| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace Opentalent\OtTemplating\Controller;
- use Opentalent\OtCore\Controller\SelectedSiteController;
- use Opentalent\OtCore\Cache\OtCacheManager;
- use Opentalent\OtTemplating\Templating\TemplateRepository;
- use PDO;
- use TYPO3\CMS\Core\Database\ConnectionPool;
- use TYPO3\CMS\Core\Utility\GeneralUtility;
- /**
- * Controller for the OtCustomizer backend submodule
- *
- * @author olivier.massot
- */
- class OtCustomizerController extends SelectedSiteController {
- /**
- * Index action (default action)
- * Displays the customizer page on the backend
- */
- public function indexAction() {
- $this->view->assign('rootPage', $this->currentRootUid);
- $this->view->assign('templates', TemplateRepository::templates);
- $templateRepository = GeneralUtility::makeInstance(TemplateRepository::class);
- $this->view->assign('currentTemplate', $templateRepository->getTemplate($this->currentRootUid));
- $this->view->assign('preferences', $templateRepository->getTemplatePreferences($this->currentRootUid));
- $args = $this->request->getArguments();
- $this->view->assign('preferencesUpdated', $args['preferencesUpdated']);
- }
- /**
- * A template has been selected, apply the change
- *
- */
- public function selectTemplateAction() {
- $templateKey = $this->request->getArgument('template_key');
- // applies the change in the database
- $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
- $queryBuilder->update('pages')
- ->where(
- $queryBuilder->expr()->eq(
- 'uid',
- $queryBuilder->createNamedParameter($this->currentRootUid, PDO::PARAM_INT)
- )
- )
- ->set('tx_opentalent_template', $templateKey)
- ->execute()
- ;
- // Clear the site's cache
- OtCacheManager::clearSiteCache($this->currentRootUid);
- $this->forward('index');
- }
- /**
- * Update the site's preferences
- */
- public function updatePreferencesAction() {
- $args = $this->request->getArguments();
- $prefs = TemplateRepository::defaultPreferences;
- if (isset($args['themeColor'])) {
- $prefs['themeColor'] = $args['themeColor'];
- }
- if (isset($args['displayCarousel'])) {
- $prefs['displayCarousel'] = $args['displayCarousel'];
- }
- // applies the change in the database
- $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
- $queryBuilder->update('pages')
- ->where(
- $queryBuilder->expr()->eq(
- 'uid',
- $queryBuilder->createNamedParameter($this->currentRootUid, PDO::PARAM_INT)
- )
- )
- ->set('tx_opentalent_template_preferences', json_encode($prefs))
- ->execute()
- ;
- // Clear the site's cache
- OtCacheManager::clearSiteCache($this->currentRootUid);
- $this->forward(
- 'index',
- 'OtCustomizer',
- 'OtTemplating',
- ['preferencesUpdated'=>'1']
- );
- }
- }
|