/** * Recursive scan of subcategories * * @param integer $maxDepth Maximum depth of the tree (i.e. 2 => 3 levels depth) * @param integer $currentDepth specify the current depth in the tree (don't use it, only for rucursivity!) * @param array $excludedIdsArray specify a list of ids to exclude of results * @param integer $idLang Specify the id of the language used * * @return array Subcategories lite tree */ function recurseLiteCategTree($maxDepth = 3, $currentDepth = 0, $idLang = NULL, $excludedIdsArray = NULL) { global $link; //get idLang $idLang = is_null($idLang) ? _USER_ID_LANG_ : (int) $idLang; //recursivity for subcategories $children = array(); if (($maxDepth == 0 or $currentDepth < $maxDepth) and $subcats = $this->getSubCategories($idLang, true) and sizeof($subcats)) { foreach ($subcats as &$subcat) { if (!$subcat['id_cms_category']) { break; } elseif (!is_array($excludedIdsArray) || !in_array($subcat['id_cms_category'], $excludedIdsArray)) { $categ = new CMSCategory($subcat['id_cms_category'], $idLang); $categ->name = CMSCategory::hideCMSCategoryPosition($categ->name); $children[] = $categ->recurseLiteCategTree($maxDepth, $currentDepth + 1, $idLang, $excludedIdsArray); } } } return array('id' => $this->id_cms_category, 'link' => $link->getCMSCategoryLink($this->id, $this->link_rewrite), 'name' => $this->name, 'desc' => $this->description, 'children' => $children); }
/** * Recursive scan of subcategories * * @param integer $max_depth Maximum depth of the tree (i.e. 2 => 3 levels depth) * @param integer $currentDepth specify the current depth in the tree (don't use it, only for rucursivity!) * @param array $excluded_ids_array specify a list of ids to exclude of results * @param integer $idLang Specify the id of the language used * * @return array Subcategories lite tree */ public function recurseLiteCategTree($max_depth = 3, $currentDepth = 0, $id_lang = null, $excluded_ids_array = null, Link $link = null) { if (!$link) { $link = Context::getContext()->link; } if (is_null($id_lang)) { $id_lang = Context::getContext()->language->id; } // recursivity for subcategories $children = array(); $subcats = $this->getSubCategories($id_lang, true); if (($max_depth == 0 || $currentDepth < $max_depth) && $subcats && count($subcats)) { foreach ($subcats as &$subcat) { if (!$subcat['id_cms_category']) { break; } elseif (!is_array($excluded_ids_array) || !in_array($subcat['id_cms_category'], $excluded_ids_array)) { $categ = new CMSCategory($subcat['id_cms_category'], $id_lang); $categ->name = CMSCategory::hideCMSCategoryPosition($categ->name); $children[] = $categ->recurseLiteCategTree($max_depth, $currentDepth + 1, $id_lang, $excluded_ids_array); } } } return array('id' => $this->id_cms_category, 'link' => $link->getCMSCategoryLink($this->id, $this->link_rewrite), 'name' => $this->name, 'desc' => $this->description, 'children' => $children); }
/** * Recursive scan of subcategories * * @param integer $max_depth Maximum depth of the tree (i.e. 2 => 3 levels depth) * @param integer $current_depth specify the current depth in the tree (don't use it, only for rucursivity!) * @param array $excluded_ids_array specify a list of ids to exclude of results * @param integer $id_lang Specify the id of the language used * * @return array Subcategories lite tree */ public function recurseLiteCategTree($max_depth = 3, $current_depth = 0, $id_lang = null, $excluded_ids_array = null) { global $link; $id_lang = !(int) $id_lang ? _USER_ID_LANG_ : (int) $id_lang; $children = array(); if (($max_depth == 0 || $current_depth < $max_depth) && ($subcats = $this->getSubCategories((int) $id_lang, true))) { if (count($subcats)) { /* Keep this line out of the first if statement to avoid side effect due to the assignation */ foreach ($subcats as &$subcat) { if (!$subcat['id_cms_category']) { break; } elseif (!is_array($excluded_ids_array) || !in_array($subcat['id_cms_category'], $excluded_ids_array)) { $categ = new CMSCategory((int) $subcat['id_cms_category'], (int) $id_lang); $categ->name = CMSCategory::hideCMSCategoryPosition($categ->name); $children[] = $categ->recurseLiteCategTree($max_depth, $current_depth + 1, (int) $id_lang, $excluded_ids_array); } } } } return array('id' => (int) $this->id_cms_category, 'link' => $link->getCMSCategoryLink($this->id, $this->link_rewrite), 'name' => $this->name, 'desc' => $this->description, 'children' => $children); }