Example #1
0
	public static function getCategorySegment($categoryId, &$query, $fullPath = 0)
	{
		if (isset($query['Itemid']))
		{
			unset($query['Itemid']);
		}
		$segments = array();
		$params   = JUDownloadHelper::getParams();

		$rootCategory = JUDownloadFrontHelperCategory::getRootCategory();

		$categoryObject = JUDownloadHelper::getCategoryById($categoryId);

		if (!is_object($categoryObject))
		{
			return false;
		}

		if ($categoryObject->level == 0)
		{
			$itemIdTreeRoot = JUDownloadHelperRoute::getMenuItemIdOfViewCategoryTreeRoot();
			if ($itemIdTreeRoot > 0)
			{
				$query['Itemid'] = $itemIdTreeRoot;

				return $segments;
			}

			$query['Itemid'] = JUDownloadHelperRoute::getHomeMenuItemId();

			
			$sefRootCategory = $rootCategory->id . ':' . $params->get('sef_root_cat', 'root');
			$segments[]      = JApplication::stringURLSafe($sefRootCategory);

			return $segments;
		}
		elseif ($categoryObject->level == 1)
		{
			
			$menuItemIdsOfViewCategoryTreeLevel1 = JUDownloadHelperRoute::getMenuItemIdArrayOfViewCategoryTreeLevel1();
			if (isset($menuItemIdsOfViewCategoryTreeLevel1[$categoryObject->id]))
			{
				$query['Itemid'] = $menuItemIdsOfViewCategoryTreeLevel1[$categoryObject->id];

				return $segments;
			}

			
			$itemIdTreeRoot = JUDownloadHelperRoute::getMenuItemIdOfViewCategoryTreeRoot();
			if ($itemIdTreeRoot > 0)
			{
				$query['Itemid'] = $itemIdTreeRoot;

				$segments[] = $categoryObject->id . ":" . $categoryObject->alias;

				return $segments;
			}

			$query['Itemid'] = JUDownloadHelperRoute::getHomeMenuItemId();

			
			$sefRootCategory = $params->get('sef_root_cat', 'root');
			$segments[]      = JApplication::stringURLSafe($sefRootCategory);

			$segments[] = $categoryObject->id . ":" . $categoryObject->alias;

			return $segments;
		}
		else
		{
			
			$levelCats = JUDownloadHelper::getCatsByLevel(1, $categoryObject->id);
			if (is_array($levelCats) && count($levelCats))
			{
				$categoryIdAncestorLevel1 = $levelCats[0]->id;
			}
			$menuItemIdsOfViewCategoryTreeLevel1 = JUDownloadHelperRoute::getMenuItemIdArrayOfViewCategoryTreeLevel1();
			if (isset($menuItemIdsOfViewCategoryTreeLevel1[$categoryIdAncestorLevel1]))
			{
				$query['Itemid'] = $menuItemIdsOfViewCategoryTreeLevel1[$categoryIdAncestorLevel1];

				if ($fullPath)
				{
					$categoryPath = JUDownloadHelper::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 = JUDownloadHelperRoute::getMenuItemIdOfViewCategoryTreeRoot();
			if ($itemIdTreeRoot > 0)
			{
				$query['Itemid'] = $itemIdTreeRoot;

				if ($fullPath)
				{
					$categoryPath = JUDownloadHelper::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'] = JUDownloadHelperRoute::getHomeMenuItemId();

			if ($fullPath)
			{
				
				$sefRootCategory = $params->get('sef_root_cat', 'root');
				$segments[]      = JApplication::stringURLSafe($sefRootCategory);
				$categoryPath    = JUDownloadHelper::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;
	}