Пример #1
0
 /**
  * Get page url
  *
  * @param string $slug
  * @param string $language
  * @param array $privacyOptions     
  * @param boolean $trustedPrivacyData
  * @param string $objectId
  * @return string|boolean
  */
 protected function getPageUrl($slug, $language, array $privacyOptions = [], $trustedPrivacyData = false, $objectId = null)
 {
     if (!isset($this->pagesMap[$language]) || !array_key_exists($slug, $this->pagesMap[$language])) {
         return false;
     }
     // get a page info
     $page = $this->pagesMap[$language][$slug];
     // check the page's status
     if ($page['active'] != PageNestedSet::PAGE_STATUS_ACTIVE || $page['module_status'] != ApplicationAbstractBaseModel::MODULE_STATUS_ACTIVE) {
         return false;
     }
     // check the page's privacy
     if (false == ($result = PagePrivacyUtility::checkPagePrivacy($page['privacy'], $privacyOptions, $trustedPrivacyData, $objectId))) {
         return false;
     }
     // check the page's visibility
     if (!empty($page['hidden']) && in_array(UserIdentityService::getCurrentUserIdentity()['role'], $page['hidden'])) {
         return false;
     }
     // check for a parent and
     if (!empty($page['parent'])) {
         if (false === ($parentUrl = $this->getPageUrl($page['parent'], $language, [], false))) {
             return false;
         }
         // build a link (skip the home page)
         if ($this->pagesMap[$language][$page['parent']]['level'] > 1) {
             $slug = $parentUrl . '/' . $slug;
         }
     }
     return $slug;
 }
Пример #2
0
 /**
  * Get page breadcrumb
  *
  * @param array $pages
  * @param boolean $homeIncluded
  * @return array|boolean
  */
 protected function getPageBreadcrumb(array $pages, $homeIncluded = false)
 {
     // compare the count of paths
     if (count($this->getReceivedPath()) != ($homeIncluded ? count($pages) - 1 : count($pages))) {
         return false;
     }
     $index = 0;
     $breadcrumb = [];
     foreach ($pages as $page) {
         // check the page's privacy
         if (false == ($result = PagePrivacyUtility::checkPagePrivacy($page['privacy']))) {
             return false;
         }
         // skip the home page
         if ($page['level'] > 1) {
             // compare received slugs
             if ($this->getReceivedPath()[$index] != $page['slug']) {
                 return false;
             }
             $index++;
             $breadcrumb[] = $page;
         }
     }
     return $breadcrumb;
 }