| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <?php
- namespace Opentalent\OtTemplating\Page;
- use FluidTYPO3\Vhs\Service\PageService;
- use TYPO3\CMS\Core\Exception\SiteNotFoundException;
- use TYPO3\CMS\Core\Site\SiteFinder;
- 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. C'est le thème par défaut.",
- 'picture' => 'EXT:ot_templating/Resources/Public/media/theme_classic.png'
- ],
- 'Modern' => [
- 'name' => 'Moderne',
- 'description' => '[Nouveauté 2020] 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
- * @return string
- */
- public function getCurrentTemplate() {
- $rootPageUid = $this->getCurrentSiteRootPageId();
- if (!($rootPageUid >= 0)) {
- // throw new \RuntimeException('Can not find any root page');
- return self::defaultTemplate;
- }
- $rootPage = $this->getPage($rootPageUid);
- $templateName = $rootPage['tx_opentalent_template'];
- if ($templateName==='') {
- return self::defaultTemplate;
- }
- return $templateName;
- }
- /**
- * Returns the current site template's name
- * @return array
- */
- public function getTemplatePreferences() {
- $rootPageUid = $this->getCurrentSiteRootPageId();
- if (!($rootPageUid >= 0)) {
- return [];
- }
- $rootPage = $this->getPage($rootPageUid);
- $templatePreferences = $rootPage['tx_opentalent_template_preferences'];
- if ($templatePreferences==='') {
- return self::defaultPreferences;
- }
- return json_decode($templatePreferences, true);
- }
- /**
- * Returns the typo3 site matching the current request
- *
- */
- public function getCurrentSite() {
- $request = $GLOBALS['TYPO3_REQUEST'];
- $site = $request->getAttribute('site');
- return GeneralUtility::makeInstance(SiteFinder::class)
- ->getSiteByIdentifier($site->getIdentifier());
- }
- /**
- *
- */
- public function getCurrentSiteRootPageId() {
- $site = $this->getCurrentSite();
- return $site->getRootPageId();
- }
- /**
- *
- */
- public function getCurrentSiteRootPageUri() {
- $site = $this->getCurrentSite();
- return $site->getBase();
- }
- /**
- *
- */
- public function getCurrentSiteRootPage() {
- $uid = $this->getCurrentSiteRootPageUri();
- return $this->getPage($uid);
- }
- }
|