OtCustomizerController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace Opentalent\OtTemplating\Controller;
  3. use Opentalent\OtCore\Controller\SelectedSiteController;
  4. use Opentalent\OtCore\Cache\OtCacheManager;
  5. use Opentalent\OtCore\Website\OtWebsiteRepository;
  6. use Opentalent\OtTemplating\Templating\TemplateRepository;
  7. use PDO;
  8. use TYPO3\CMS\Core\Database\ConnectionPool;
  9. use TYPO3\CMS\Core\Utility\GeneralUtility;
  10. use TYPO3\CMS\Extbase\Object\ObjectManager;
  11. /**
  12. * Controller for the OtCustomizer backend submodule
  13. *
  14. * @author olivier.massot
  15. */
  16. class OtCustomizerController extends SelectedSiteController {
  17. /**
  18. * @var \TYPO3\CMS\Core\Database\ConnectionPool
  19. */
  20. private $connectionPool;
  21. public function injectConnectionPool(\TYPO3\CMS\Core\Database\ConnectionPool $connectionPool)
  22. {
  23. $this->connectionPool = $connectionPool;
  24. }
  25. /**
  26. * Index action (default action)
  27. * Displays the customizer page on the backend
  28. */
  29. public function indexAction() {
  30. $this->view->assign('rootPage', $this->currentRootUid);
  31. $this->view->assign('templates', TemplateRepository::templates);
  32. $templateRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(TemplateRepository::class);
  33. $this->view->assign('currentTemplate', $templateRepository->getTemplate($this->currentRootUid));
  34. $this->view->assign('preferences', $templateRepository->getTemplatePreferences($this->currentRootUid));
  35. }
  36. /**
  37. * A template has been selected, apply the change
  38. */
  39. public function selectTemplateAction() {
  40. $templateKey = $this->request->getArgument('template_key');
  41. $otWebsiteRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(OtWebsiteRepository::class);
  42. $website = $otWebsiteRepository->getWebsiteByPageUid($this->currentRootUid);
  43. // applies the change in the database
  44. $queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages');
  45. $queryBuilder->update('ot_websites')
  46. ->where($queryBuilder->expr()->eq('uid', $website['uid']))
  47. ->set('template', $templateKey)
  48. ->execute();
  49. // Clear the site's cache
  50. OtCacheManager::clearSiteCache($this->currentRootUid);
  51. $this->addFlashMessage($this->getLanguageService()->sL(
  52. 'LLL:EXT:ot_templating/Resources/Private/Language/locallang.xlf:theme_updated'
  53. ));
  54. $this->forward('index');
  55. }
  56. /**
  57. * Update the site's preferences
  58. */
  59. public function updatePreferencesAction() {
  60. $args = $this->request->getArguments();
  61. $prefs = TemplateRepository::defaultPreferences;
  62. if (isset($args['themeColor'])) {
  63. $prefs['themeColor'] = $args['themeColor'];
  64. }
  65. if (isset($args['displayCarousel'])) {
  66. $prefs['displayCarousel'] = $args['displayCarousel'] ? 1 : 0;
  67. }
  68. if (isset($args['displayBreadcrumb'])) {
  69. $prefs['displayBreadcrumb'] = $args['displayBreadcrumb'] ? 1 : 0;
  70. }
  71. // applies the change in the database
  72. $otWebsiteRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(OtWebsiteRepository::class);
  73. $website = $otWebsiteRepository->getWebsiteByPageUid($this->currentRootUid);
  74. $queryBuilder = $this->connectionPool->getQueryBuilderForTable('ot_websites');
  75. $queryBuilder->update('ot_websites')
  76. ->where($queryBuilder->expr()->eq('uid', $website['uid']))
  77. ->set('template_preferences', json_encode($prefs))
  78. ->execute();
  79. // Clear the site's cache
  80. OtCacheManager::clearSiteCache($this->currentRootUid);
  81. $this->addFlashMessage($this->getLanguageService()->sL(
  82. 'LLL:EXT:ot_templating/Resources/Private/Language/locallang.xlf:settings_updated'
  83. ));
  84. $this->forward(
  85. 'index',
  86. 'OtCustomizer',
  87. 'OtTemplating'
  88. );
  89. }
  90. }