/** * @test */ public function getMenuPageOverlay() { $this->pageRepo->sys_language_uid = 1; $rows = $this->pageRepo->getMenu(array(2, 3), 'uid, title'); $this->assertEquals('Attrappe 1-2-5', $rows[5]['title']); $this->assertEquals('Attrappe 1-2-6', $rows[6]['title']); $this->assertEquals('Dummy 1-2-7', $rows[7]['title']); $this->assertEquals('Dummy 1-3-8', $rows[8]['title']); $this->assertEquals('Attrappe 1-3-9', $rows[9]['title']); $this->assertCount(5, $rows); }
/** * recursive function for building a page array * * @param array $page the current page * @param int $depth the current depth * @param array $pages contains all pages so far * @param int $level the tree level required for the UI grid * @return array */ protected function getPageTree($page, $depth, $pages = [], $level = 0) { // default query settings $fields = '*'; $sortField = 'sorting'; // decrease the depth $depth--; // add the current language value if ($this->modParams['lang'] > 0) { $page['sys_language_uid'] = $this->languages[$page['_PAGES_OVERLAY_LANGUAGE'] ?: 0]; } if ($this->showResults) { $results = $this->getResults($page); $page['results'] = $results['Percentage']['count']; } $page['level'] = $level; // add the page to the pages array $pages[] =& $page; // fetch subpages and set the treelevel if ($depth > 0) { $subPages = $this->pageRepository->getMenu($page['uid'], $fields, $sortField); if (count($subPages) > 0) { $page['$$treeLevel'] = $level; $level++; foreach ($subPages as &$subPage) { $pages = $this->getPageTree($subPage, $depth, $pages, $level); } } } return $pages; }
/** * Wrapper for \TYPO3\CMS\Frontend\Page\PageRepository::getMenu() * Caution: different signature * * @param integer $pageUid * @param array $excludePages * @param string $where * @param boolean $showHiddenInMenu * @param boolean $checkShortcuts * @param array $allowedDoktypeList * @return array */ public function getMenu($pageUid = NULL, $excludePages = array(), $where = '', $showHiddenInMenu = FALSE, $checkShortcuts = FALSE, $allowedDoktypeList = array()) { if (NULL === $pageUid) { $pageUid = $GLOBALS['TSFE']->id; } $addWhere = self::$pageSelect->enableFields('pages', 0); if (0 < count($allowedDoktypeList)) { $addWhere .= ' AND doktype IN (' . implode(',', $allowedDoktypeList) . ')'; } else { $addWhere .= ' AND doktype != ' . PageRepository::DOKTYPE_SYSFOLDER; } if (0 < count($excludePages)) { $addWhere .= ' AND uid NOT IN (' . implode(',', $excludePages) . ')'; } if (FALSE === (bool) $showHiddenInMenu) { $addWhere .= ' AND nav_hide=0'; } if ('' !== $where) { $addWhere = $where . ' ' . $addWhere; } $key = md5(intval($showHiddenInMenu) . $pageUid . $addWhere . intval($checkShortcuts)); if (FALSE === isset(self::$cachedMenus[$key])) { self::$cachedMenus[$key] = self::$pageSelect->getMenu($pageUid, '*', 'sorting', $addWhere, $checkShortcuts); } return self::$cachedMenus[$key]; }
/** * Resolves shortcuts for the shortcur of type PageRepository::SHORTCUT_MODE_FIRST_SUBPAGE. * * @param array $page * @param array $processedPages * @return array */ private function resolveShortcutFirstSubpage(array $page, array &$processedPages) { $rows = $this->pageRepository->getMenu($page['uid']); if (count($rows) > 0) { reset($rows); $page = current($rows); if ($page['doktype'] == PageRepository::DOKTYPE_SHORTCUT) { $page = $this->resolveShortcutProcess($page, $processedPages); } } return $page; }
/** * @return array * @throws Exception */ protected function getArticlePagesList() { $pageList = array(); if ($this->settings['pidOrganizationFolder'] > 0) { $organizations = $this->organizationRepository->findAll(); $usedLeisureFolderPids = array(); /** @var $organization \MUM\BjrFreizeit\Domain\Model\Organization $organization */ foreach ($organizations as $organization) { $usedLeisureFolderPids[] = $organization->getLeisureFolderPid(); } $ret = $this->pageRepository->getMenu($this->settings['pidOrganizationFolder'], '*', 'sorting', 'AND deleted =0 AND hidden = 0'); foreach ($ret as $pageUid => $row) { if (!in_array($pageUid, $usedLeisureFolderPids)) { $pageList[$pageUid] = $row['title']; } } } else { throw new Exception('PID für Seite mit Anbieter ist nicht gesetzt.'); } return $pageList; }
/** * Returns TRUE if there is a submenu with items for the page id, $uid * Used by the item states "IFSUB", "ACTIFSUB" and "CURIFSUB" to check if there is a submenu * * @param integer $uid Page uid for which to search for a submenu * @return boolean Returns TRUE if there was a submenu with items found * @access private * @todo Define visibility */ public function isSubMenu($uid) { // Looking for a mount-pid for this UID since if that // exists we should look for a subpages THERE and not in the input $uid; $mount_info = $this->sys_page->getMountPointInfo($uid); if (is_array($mount_info)) { $uid = $mount_info['mount_pid']; } $recs = $this->sys_page->getMenu($uid, 'uid,pid,doktype,mount_pid,mount_pid_ol,nav_hide,shortcut,shortcut_mode,l18n_cfg'); $hasSubPages = FALSE; $bannedUids = $this->getBannedUids(); foreach ($recs as $theRec) { // no valid subpage if the document type is excluded from the menu if (GeneralUtility::inList($this->doktypeExcludeList, $theRec['doktype'])) { continue; } // No valid subpage if the page is hidden inside menus and // it wasn't forced to show such entries if ($theRec['nav_hide'] && !$this->conf['includeNotInMenu']) { continue; } // No valid subpage if the default language should be shown and the page settings // are excluding the visibility of the default language if (!$GLOBALS['TSFE']->sys_language_uid && GeneralUtility::hideIfDefaultLanguage($theRec['l18n_cfg'])) { continue; } // No valid subpage if the alternative language should be shown and the page settings // are requiring a valid overlay but it doesn't exists $hideIfNotTranslated = GeneralUtility::hideIfNotTranslated($theRec['l18n_cfg']); if ($GLOBALS['TSFE']->sys_language_uid && $hideIfNotTranslated && !$theRec['_PAGES_OVERLAY']) { continue; } // No valid subpage if the subpage is banned by excludeUidList if (in_array($theRec['uid'], $bannedUids)) { continue; } $hasSubPages = TRUE; break; } return $hasSubPages; }
/** * Get page shortcut; Finds the records pointed to by input value $SC (the shortcut value) * * @param integer $SC The value of the "shortcut" field from the pages record * @param integer $mode The shortcut mode: 1 will select first subpage, 2 a random subpage, 3 the parent page; default is the page pointed to by $SC * @param integer $thisUid The current page UID of the page which is a shortcut * @param integer $itera Safety feature which makes sure that the function is calling itself recursively max 20 times (since this function can find shortcuts to other shortcuts to other shortcuts...) * @param array $pageLog An array filled with previous page uids tested by the function - new page uids are evaluated against this to avoid going in circles. * @return mixed Returns the page record of the page that the shortcut pointed to. * @access private * @see getPageAndRootline() * @todo Define visibility */ public function getPageShortcut($SC, $mode, $thisUid, $itera = 20, $pageLog = array()) { $idArray = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $SC); // Find $page record depending on shortcut mode: switch ($mode) { case \TYPO3\CMS\Frontend\Page\PageRepository::SHORTCUT_MODE_FIRST_SUBPAGE: case \TYPO3\CMS\Frontend\Page\PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE: $pageArray = $this->sys_page->getMenu($idArray[0] ? $idArray[0] : $thisUid, '*', 'sorting', 'AND pages.doktype<199 AND pages.doktype!=' . \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_BE_USER_SECTION); $pO = 0; if ($mode == \TYPO3\CMS\Frontend\Page\PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE && count($pageArray)) { $randval = intval(rand(0, count($pageArray) - 1)); $pO = $randval; } $c = 0; foreach ($pageArray as $pV) { if ($c == $pO) { $page = $pV; break; } $c++; } if (count($page) == 0) { $message = 'This page (ID ' . $thisUid . ') is of type "Shortcut" and configured to redirect to a subpage. ' . 'However, this page has no accessible subpages.'; throw new \TYPO3\CMS\Core\Error\Http\PageNotFoundException($message, 1301648328); } break; case \TYPO3\CMS\Frontend\Page\PageRepository::SHORTCUT_MODE_PARENT_PAGE: $parent = $this->sys_page->getPage($thisUid); $page = $this->sys_page->getPage($parent['pid']); if (count($page) == 0) { $message = 'This page (ID ' . $thisUid . ') is of type "Shortcut" and configured to redirect to its parent page. ' . 'However, the parent page is not accessible.'; throw new \TYPO3\CMS\Core\Error\Http\PageNotFoundException($message, 1301648358); } break; default: $page = $this->sys_page->getPage($idArray[0]); if (count($page) == 0) { $message = 'This page (ID ' . $thisUid . ') is of type "Shortcut" and configured to redirect to a page, which is not accessible (ID ' . $idArray[0] . ').'; throw new \TYPO3\CMS\Core\Error\Http\PageNotFoundException($message, 1301648404); } break; } // Check if short cut page was a shortcut itself, if so look up recursively: if ($page['doktype'] == \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_SHORTCUT) { if (!in_array($page['uid'], $pageLog) && $itera > 0) { $pageLog[] = $page['uid']; $page = $this->getPageShortcut($page['shortcut'], $page['shortcut_mode'], $page['uid'], $itera - 1, $pageLog); } else { $pageLog[] = $page['uid']; $message = 'Page shortcuts were looping in uids ' . implode(',', $pageLog) . '...!'; \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($message, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR); throw new \RuntimeException($message, 1294587212); } } // Return resulting page: return $page; }
/** * @param int $startPageId * @return array */ private function getSubPages($startPageId) { return $this->pageRepo->getMenu($startPageId, '*', 'sorting', $this->pageRepo->enableFields('pages') . 'AND ' . UrlEntry::EXCLUDE_FROM_SITEMAP . '!=1'); }
/** * @param int $id * @return array */ protected function getPageMenu($id) { return $this->pageRepository->getMenu($id, '*', 'sorting'); }