| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace Opentalent\OtTemplating\Utilities;
- use FluidTYPO3\Vhs\Service\PageService;
- use TYPO3\CMS\Core\Utility\GeneralUtility;
- use TYPO3\CMS\Extbase\Object\ObjectManager;
- use TYPO3\CMS\Frontend\Page\PageRepository;
- /**
- * Class OtPageRepository
- *
- * Provides some useful methods to query typo3 pages
- *
- * @package Opentalent\OtTemplating\Page
- */
- class OtPageRepository extends PageRepository
- {
- CONST templates = [
- 'Classic' => [
- 'name' => 'Classique',
- 'description' => 'Le thème classique, simple et complet.',
- 'picture' => 'EXT:ot_templating/Resources/Public/media/theme_classic.png'
- ],
- 'Modern' => [
- 'name' => 'Moderne',
- 'description' => '[Nouveau] Un thème moderne et intuitif.',
- 'picture' => 'EXT:ot_templating/Resources/Public/media/theme_modern.png'
- ]
- ];
- CONST defaultTemplate = 'Classic';
- CONST defaultPreferences = [
- 'themeColor' => 'lightblue',
- 'displayCarousel' => '1'
- ];
- /**
- * Returns the root page of the given page,
- * or the page itself if the given page is
- * already the rootpage of the site
- *
- * @param $pageUid
- *
- * @return array
- */
- public function getRootPageFor($pageUid) {
- $pageService = GeneralUtility::makeInstance(ObjectManager::class)->get(PageService::class);
- $rootLine = $pageService->getRootLine($pageUid);
- for (end($rootLine); key($rootLine)!==null; prev($rootLine)){
- $page = current($rootLine);
- if ($page['is_siteroot'] == 1) {
- return $page;
- }
- }
- return [];
- }
- /**
- * Recursively returns all the subpages of the given page
- *
- * @param $pageUid
- * @return array
- */
- public function getAllSubpagesForPage($pageUid) {
- $subpages = [];
- $stack = $this->getSubpagesForPages(
- [$pageUid],
- '*',
- 'sorting',
- '',
- false
- );
- foreach ($stack as $page) {
- $subpages[] = $page;
- $children = $this->getAllSubpagesForPage($page['uid']);
- if (!empty($children)) {
- $subpages = array_merge($subpages, $children);
- }
- }
- return $subpages;
- }
- /**
- * Returns the current site template's name
- * @param $pageUid
- * @return string
- */
- public function getCurrentTemplate($pageUid) {
- $rootPageUid = $this->getRootPageFor($pageUid)['uid'];
- if (!($rootPageUid >= 0)) {
- return '';
- }
- $rootPage = $this->getPage($rootPageUid);
- $templateName = $rootPage['tx_opentalent_template'];
- if ($templateName==='') {
- return self::defaultTemplate;
- }
- return $templateName;
- }
- /**
- * Returns the current site template's name
- * @param $pageUid
- * @return array
- */
- public function getTemplatePreferences($pageUid) {
- $rootPageUid = $this->getRootPageFor($pageUid)['uid'];
- if (!($rootPageUid >= 0)) {
- return [];
- }
- $rootPage = $this->getPage($rootPageUid);
- $templatePreferences = $rootPage['tx_opentalent_template_preferences'];
- if ($templatePreferences==='') {
- return self::defaultPreferences;
- }
- return json_decode($templatePreferences, true);
- }
- }
|