OtCustomizerController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. public function __construct(
  20. private readonly ConnectionPool $connectionPool,
  21. private readonly TemplateRepository $templateRepository,
  22. private readonly OtCacheManager $otCacheManager,
  23. ) {}
  24. /**
  25. * Index action (default action)
  26. * Displays the customizer page on the backend
  27. */
  28. public function indexAction(): ResponseInterface {
  29. $this->view->assign('rootPage', $this->currentRootUid);
  30. $this->view->assign('website', $this->currentWebsite);
  31. $this->view->assign('templates', TemplateRepository::templates);
  32. $this->view->assign('currentTemplate', $this->templateRepository->getTemplate($this->currentWebsite));
  33. $this->view->assign('preferences', $this->templateRepository->getTemplatePreferences($this->currentWebsite));
  34. return $this->htmlResponse();
  35. }
  36. /**
  37. * A template has been selected, apply the change
  38. */
  39. public function selectTemplateAction() {
  40. $templateKey = $this->request->getArgument('template_key');
  41. // applies the change in the database
  42. $queryBuilder = $this->connectionPool->getQueryBuilderForTable('ot_websites');
  43. $queryBuilder->update('ot_websites')
  44. ->where($queryBuilder->expr()->eq('uid', $this->currentWebsite['uid']))
  45. ->set('template', $templateKey)
  46. ->execute();
  47. // Clear the site's cache
  48. $this->otCacheManager->clearSiteCache($this->currentRootUid);
  49. $this->addFlashMessage($this->getLanguageService()->sL(
  50. 'LLL:EXT:ot_templating/Resources/Private/Language/locallang.xlf:theme_updated'
  51. ));
  52. return new ForwardResponse('index');
  53. }
  54. /**
  55. * Update the site's preferences
  56. */
  57. public function updatePreferencesAction() {
  58. $args = $this->request->getArguments();
  59. $prefs = TemplateRepository::defaultPreferences;
  60. if (isset($args['themeColor'])) {
  61. $prefs['themeColor'] = $args['themeColor'];
  62. }
  63. if (isset($args['displayCarousel'])) {
  64. $prefs['displayCarousel'] = $args['displayCarousel'] ? 1 : 0;
  65. }
  66. if (isset($args['displayBreadcrumb'])) {
  67. $prefs['displayBreadcrumb'] = $args['displayBreadcrumb'] ? 1 : 0;
  68. }
  69. if (isset($args['staticDonors'])) {
  70. $prefs['staticDonors'] = $args['staticDonors'] ? 1 : 0;
  71. }
  72. // applies the change in the database
  73. $queryBuilder = $this->connectionPool->getQueryBuilderForTable('ot_websites');
  74. $queryBuilder->update('ot_websites')
  75. ->where($queryBuilder->expr()->eq('uid', $this->currentWebsite['uid']))
  76. ->set('template_preferences', json_encode($prefs))
  77. ->execute();
  78. // Clear the site's cache
  79. $this->otCacheManager->clearSiteCache($this->currentRootUid);
  80. $this->addFlashMessage($this->getLanguageService()->sL(
  81. 'LLL:EXT:ot_templating/Resources/Private/Language/locallang.xlf:settings_updated'
  82. ));
  83. return (new ForwardResponse('index'))->withControllerName('OtCustomizer')->withExtensionName('OtTemplating');
  84. }
  85. }