OtCustomizerController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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('website', $this->currentWebsite);
  32. $this->view->assign('templates', TemplateRepository::templates);
  33. $templateRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(TemplateRepository::class);
  34. $this->view->assign('currentTemplate', $templateRepository->getTemplate($this->currentWebsite));
  35. $this->view->assign('preferences', $templateRepository->getTemplatePreferences($this->currentWebsite));
  36. }
  37. /**
  38. * A template has been selected, apply the change
  39. */
  40. public function selectTemplateAction() {
  41. $templateKey = $this->request->getArgument('template_key');
  42. // applies the change in the database
  43. $queryBuilder = $this->connectionPool->getQueryBuilderForTable('ot_websites');
  44. $queryBuilder->update('ot_websites')
  45. ->where($queryBuilder->expr()->eq('uid', $this->currentWebsite['uid']))
  46. ->set('template', $templateKey)
  47. ->execute();
  48. // Clear the site's cache
  49. OtCacheManager::clearSiteCache($this->currentRootUid);
  50. $this->addFlashMessage($this->getLanguageService()->sL(
  51. 'LLL:EXT:ot_templating/Resources/Private/Language/locallang.xlf:theme_updated'
  52. ));
  53. $this->forward('index');
  54. }
  55. /**
  56. * Update the site's preferences
  57. */
  58. public function updatePreferencesAction() {
  59. $args = $this->request->getArguments();
  60. $prefs = TemplateRepository::defaultPreferences;
  61. if (isset($args['themeColor'])) {
  62. $prefs['themeColor'] = $args['themeColor'];
  63. }
  64. if (isset($args['displayCarousel'])) {
  65. $prefs['displayCarousel'] = $args['displayCarousel'] ? 1 : 0;
  66. }
  67. if (isset($args['displayBreadcrumb'])) {
  68. $prefs['displayBreadcrumb'] = $args['displayBreadcrumb'] ? 1 : 0;
  69. }
  70. if (isset($args['staticDonors'])) {
  71. $prefs['staticDonors'] = $args['staticDonors'] ? 1 : 0;
  72. }
  73. // applies the change in the database
  74. $queryBuilder = $this->connectionPool->getQueryBuilderForTable('ot_websites');
  75. $queryBuilder->update('ot_websites')
  76. ->where($queryBuilder->expr()->eq('uid', $this->currentWebsite['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. }