| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- namespace Opentalent\OtTemplating\Controller;
- use Opentalent\OtTemplating\Page\OtPageRepository;
- use PDO;
- use TYPO3\CMS\Core\Database\ConnectionPool;
- use TYPO3\CMS\Core\DataHandling\DataHandler;
- use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
- use TYPO3\CMS\Core\Utility\GeneralUtility;
- /**
- * Controller for the OtCustomizer backend submodule
- *
- * @author olivier.massot
- */
- class OtCustomizerController extends ActionController {
- /**
- * Index action (default action)
- * Displays the customize page on the backend
- */
- public function indexAction() {
- // Get the current root page's uid
- $rootPageUid = $this->getCurrentRootPageUid();
- // If the current page is not a root page or a subpage of one, abort
- $pageSelected = ($rootPageUid !== null);
- $this->view->assign('pageSelected', (int)$pageSelected);
- if (!$pageSelected) {
- return;
- }
- $this->view->assign('rootPage', $rootPageUid);
- $this->view->assign('templates', OtPageRepository::templates);
- $pageRepository = new OtPageRepository();
- $this->view->assign('currentTemplate', $pageRepository->getCurrentTemplate($rootPageUid));
- $this->view->assign('preferences', $pageRepository->getTemplatePreferences($rootPageUid));
- $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');
- // Get the current root page's uid
- $rootPageUid = $this->getCurrentRootPageUid();
- // applies the change in the database
- $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
- $queryBuilder->update('pages')
- ->where(
- $queryBuilder->expr()->eq(
- 'uid',
- $queryBuilder->createNamedParameter($rootPageUid, PDO::PARAM_INT)
- )
- )
- ->set('tx_opentalent_template', $templateKey)
- ->execute()
- ;
- // Clear the page cache
- $this->cleanCache();
- $this->forward('index');
- }
- /**
- * Update the site's preferences
- */
- public function updatePreferencesAction() {
- $args = $this->request->getArguments();
- $prefs = OtPageRepository::defaultPreferences;
- if (isset($args['themeColor'])) {
- $prefs['themeColor'] = $args['themeColor'];
- }
- if (isset($args['displayCarousel'])) {
- $prefs['displayCarousel'] = $args['displayCarousel'];
- }
- // Get the current root page's uid
- $rootPageUid = $this->getCurrentRootPageUid();
- // applies the change in the database
- $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
- $queryBuilder->update('pages')
- ->where(
- $queryBuilder->expr()->eq(
- 'uid',
- $queryBuilder->createNamedParameter($rootPageUid, PDO::PARAM_INT)
- )
- )
- ->set('tx_opentalent_template_preferences', json_encode($prefs))
- ->execute()
- ;
- // Clear the page cache
- $this->cleanCache();
- $this->forward(
- 'index',
- 'OtCustomizer',
- 'OtTemplating',
- ['preferencesUpdated'=>'1']
- );
- }
- /**
- * Return the uid of the root page of the currently selected
- * site, or null if no site's page is selected
- *
- * @return int | null
- */
- public function getCurrentRootPageUid() {
- // Get the current page uid
- $pageId = (int) GeneralUtility::_GP('id');
- // Get the root page of the site
- $otPageRepository = new OtPageRepository();
- $rootPage = $otPageRepository->getRootPageFor($pageId);
- if (!$rootPage['uid'] > 0) {
- return null;
- }
- return (int)$rootPage['uid'];
- }
- /**
- * Cleans the pages cache
- */
- public function cleanCache() {
- $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
- $dataHandler->start([], []);
- $dataHandler->clear_cacheCmd('all');
- }
- /**
- * Gets the backend user
- *
- * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
- */
- protected function getBackendUser() {
- return $GLOBALS['BE_USER'];
- }
- }
|