OtCustomizerController.php 3.2 KB

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