|
|
@@ -3,8 +3,9 @@
|
|
|
namespace Opentalent\OtTemplating\Controller;
|
|
|
|
|
|
use Opentalent\OtTemplating\Utilities\OtPageRepository;
|
|
|
-use TYPO3\CMS\Core\Page\PageRenderer;
|
|
|
-use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
|
|
|
+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;
|
|
|
|
|
|
@@ -15,53 +16,96 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
|
|
|
*/
|
|
|
class OtCustomizerController extends ActionController {
|
|
|
|
|
|
- CONST themes = [
|
|
|
- 'classic' => [
|
|
|
+ CONST templates = [
|
|
|
+ 'Classic' => [
|
|
|
'name' => 'Classique',
|
|
|
- 'description' => 'Le thème classique',
|
|
|
+ 'description' => 'Le thème classique, simple et complet.',
|
|
|
'picture' => 'EXT:ot_templating/Resources/Public/media/theme_classic.png'
|
|
|
],
|
|
|
- 'modern' => [
|
|
|
+ 'Modern' => [
|
|
|
'name' => 'Moderne',
|
|
|
- 'description' => 'Le thème 2020 pour votre site',
|
|
|
+ 'description' => '[Nouveau] Un thème moderne et intuitif.',
|
|
|
'picture' => 'EXT:ot_templating/Resources/Public/media/theme_modern.png'
|
|
|
]
|
|
|
];
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
- *
|
|
|
- * @var int
|
|
|
+ * Index action (default action)
|
|
|
+ * Displays the customize page on the backend
|
|
|
*/
|
|
|
- protected $pageRootId;
|
|
|
+ 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;
|
|
|
+ }
|
|
|
|
|
|
- public function __construct() {
|
|
|
- $this->pageRootId = (int) GeneralUtility::_GP('id');
|
|
|
+ $this->view->assign('rootPage', $rootPageUid);
|
|
|
+ $this->view->assign('templates', self::templates);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Index action
|
|
|
+ * A template has been selected, apply the change
|
|
|
*/
|
|
|
- public function indexAction() {
|
|
|
+ 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();
|
|
|
|
|
|
- // Get the current page
|
|
|
- $pageRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
|
|
|
+ $this->redirect('index');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 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');
|
|
|
- $page = $pageRepository->getPage($pageId);
|
|
|
|
|
|
// Get the root page of the site
|
|
|
- $pageRepository = new OtPageRepository();
|
|
|
- $rootPage = $pageRepository->getRootPageFor($pageId);
|
|
|
+ $otPageRepository = new OtPageRepository();
|
|
|
+ $rootPage = $otPageRepository->getRootPageFor($pageId);
|
|
|
|
|
|
- // If the current page is not a root page or a subpage of one, abort
|
|
|
- $pageSelected = ($rootPage['uid'] > 0);
|
|
|
- $this->view->assign('pageSelected', (int)$pageSelected);
|
|
|
- if (!$pageSelected) {
|
|
|
- return;
|
|
|
+ if (!$rootPage['uid'] > 0) {
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
- $this->view->assign('rootPage', $rootPage);
|
|
|
- $this->view->assign('themes', self::themes);
|
|
|
+ return (int)$rootPage['uid'];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Cleans the pages cache
|
|
|
+ */
|
|
|
+ public function cleanCache() {
|
|
|
+ $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
|
|
|
+ $dataHandler->start([], []);
|
|
|
+ $dataHandler->clear_cacheCmd('pages');
|
|
|
}
|
|
|
|
|
|
/**
|