OtCustomizerController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. use TYPO3\CMS\Extbase\Object\ObjectManager;
  10. /**
  11. * Controller for the OtCustomizer backend submodule
  12. *
  13. * @author olivier.massot
  14. */
  15. class OtCustomizerController extends SelectedSiteController {
  16. /**
  17. * @var \TYPO3\CMS\Core\Database\ConnectionPool
  18. */
  19. private $connectionPool;
  20. public function injectConnectionPool(\TYPO3\CMS\Core\Database\ConnectionPool $connectionPool)
  21. {
  22. $this->connectionPool = $connectionPool;
  23. }
  24. /**
  25. * Index action (default action)
  26. * Displays the customizer page on the backend
  27. */
  28. public function indexAction() {
  29. $this->view->assign('rootPage', $this->currentRootUid);
  30. $this->view->assign('templates', TemplateRepository::templates);
  31. $templateRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(TemplateRepository::class);
  32. $this->view->assign('currentTemplate', $templateRepository->getTemplate($this->currentRootUid));
  33. $this->view->assign('preferences', $templateRepository->getTemplatePreferences($this->currentRootUid));
  34. }
  35. /**
  36. * A template has been selected, apply the change
  37. *
  38. */
  39. public function selectTemplateAction() {
  40. $templateKey = $this->request->getArgument('template_key');
  41. // applies the change in the database
  42. $queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages');
  43. $queryBuilder->update('pages')
  44. ->where(
  45. $queryBuilder->expr()->eq(
  46. 'uid',
  47. $queryBuilder->createNamedParameter($this->currentRootUid, PDO::PARAM_INT)
  48. )
  49. )
  50. ->set('tx_opentalent_template', $templateKey)
  51. ->execute()
  52. ;
  53. // Clear the site's cache
  54. OtCacheManager::clearSiteCache($this->currentRootUid);
  55. $this->addFlashMessage('Le thème a bien été modifié');
  56. $this->forward('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. // applies the change in the database
  74. $queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages');
  75. $queryBuilder->update('pages')
  76. ->where(
  77. $queryBuilder->expr()->eq(
  78. 'uid',
  79. $queryBuilder->createNamedParameter($this->currentRootUid, PDO::PARAM_INT)
  80. )
  81. )
  82. ->set('tx_opentalent_template_preferences', json_encode($prefs))
  83. ->execute();
  84. // Clear the site's cache
  85. OtCacheManager::clearSiteCache($this->currentRootUid);
  86. $this->addFlashMessage('Les préférences ont bien été enregistrées');
  87. $this->forward(
  88. 'index',
  89. 'OtCustomizer',
  90. 'OtTemplating'
  91. );
  92. }
  93. }