Exemplo n.º 1
0
 public static function getCategorySegment($categoryId, &$query, $fullPath = 0)
 {
     if (isset($query['Itemid'])) {
         unset($query['Itemid']);
     }
     $segments = array();
     $params = JUDirectoryHelper::getParams();
     $rootCategory = JUDirectoryFrontHelperCategory::getRootCategory();
     $categoryObject = JUDirectoryHelper::getCategoryById($categoryId);
     if (!is_object($categoryObject)) {
         return false;
     }
     if ($categoryObject->level == 0) {
         $itemIdTreeRoot = JUDirectoryHelperRoute::getMenuItemIdOfViewCategoryTreeRoot();
         if ($itemIdTreeRoot > 0) {
             $query['Itemid'] = $itemIdTreeRoot;
             return $segments;
         }
         $query['Itemid'] = JUDirectoryHelperRoute::getHomeMenuItemId();
         $sefRootCategory = $rootCategory->id . ':' . $params->get('sef_root_cat', 'root');
         $segments[] = JApplication::stringURLSafe($sefRootCategory);
         return $segments;
     } elseif ($categoryObject->level == 1) {
         $menuItemIdsOfViewCategoryTreeLevel1 = JUDirectoryHelperRoute::getMenuItemIdArrayOfViewCategoryTreeLevel1();
         if (isset($menuItemIdsOfViewCategoryTreeLevel1[$categoryObject->id])) {
             $query['Itemid'] = $menuItemIdsOfViewCategoryTreeLevel1[$categoryObject->id];
             return $segments;
         }
         $itemIdTreeRoot = JUDirectoryHelperRoute::getMenuItemIdOfViewCategoryTreeRoot();
         if ($itemIdTreeRoot > 0) {
             $query['Itemid'] = $itemIdTreeRoot;
             $segments[] = $categoryObject->id . ":" . $categoryObject->alias;
             return $segments;
         }
         $query['Itemid'] = JUDirectoryHelperRoute::getHomeMenuItemId();
         $sefRootCategory = $params->get('sef_root_cat', 'root');
         $segments[] = JApplication::stringURLSafe($sefRootCategory);
         $segments[] = $categoryObject->id . ":" . $categoryObject->alias;
         return $segments;
     } else {
         $levelCats = JUDirectoryHelper::getCatsByLevel(1, $categoryObject->id);
         if (is_array($levelCats) && count($levelCats)) {
             $categoryIdAncestorLevel1 = $levelCats[0]->id;
         }
         $menuItemIdsOfViewCategoryTreeLevel1 = JUDirectoryHelperRoute::getMenuItemIdArrayOfViewCategoryTreeLevel1();
         if (isset($menuItemIdsOfViewCategoryTreeLevel1[$categoryIdAncestorLevel1])) {
             $query['Itemid'] = $menuItemIdsOfViewCategoryTreeLevel1[$categoryIdAncestorLevel1];
             if ($fullPath) {
                 $categoryPath = JUDirectoryHelper::getCategoryPath($categoryId);
                 if (is_array($categoryPath) && count($categoryPath)) {
                     foreach ($categoryPath as $categoryPathValue) {
                         if ($categoryPathValue->level > 1 && $categoryPathValue->id != $categoryObject->id) {
                             $segments[] = $categoryPathValue->alias;
                         }
                     }
                 }
             }
             $segments[] = $categoryObject->id . ":" . $categoryObject->alias;
             return $segments;
         }
         $itemIdTreeRoot = JUDirectoryHelperRoute::getMenuItemIdOfViewCategoryTreeRoot();
         if ($itemIdTreeRoot > 0) {
             $query['Itemid'] = $itemIdTreeRoot;
             if ($fullPath) {
                 $categoryPath = JUDirectoryHelper::getCategoryPath($categoryId);
                 if (is_array($categoryPath) && count($categoryPath)) {
                     foreach ($categoryPath as $categoryPathValue) {
                         if ($categoryPathValue->level > 0 && $categoryPathValue->id != $categoryObject->id) {
                             $segments[] = $categoryPathValue->alias;
                         }
                     }
                 }
             }
             $segments[] = $categoryObject->id . ":" . $categoryObject->alias;
             return $segments;
         }
         $query['Itemid'] = JUDirectoryHelperRoute::getHomeMenuItemId();
         if ($fullPath) {
             $sefRootCategory = $params->get('sef_root_cat', 'root');
             $segments[] = JApplication::stringURLSafe($sefRootCategory);
             $categoryPath = JUDirectoryHelper::getCategoryPath($categoryId);
             if (is_array($categoryPath) && count($categoryPath)) {
                 foreach ($categoryPath as $categoryPathValue) {
                     if ($categoryPathValue->level > 0 && $categoryPathValue->id != $categoryObject->id) {
                         $segments[] = $categoryPathValue->alias;
                     }
                 }
             }
         }
         $segments[] = $categoryObject->id . ":" . $categoryObject->alias;
         return $segments;
     }
     return $segments;
 }