OtCustomizerController.php 3.8 KB

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