Example #1
0
 /**
  * Recursive scan of subcategories
  *
  * @param int $max_depth Maximum depth of the tree (i.e. 2 => 3 levels depth)
  * @param int $current_depth specify the current depth in the tree (don't use it, only for rucursivity!)
  * @param int $id_lang Specify the id of the language used
  * @param array $excluded_ids_array specify a list of ids to exclude of results
  *
  * @return array Subcategories lite tree
  */
 public function recurseLiteCategTree($max_depth = 3, $current_depth = 0, $id_lang = null, $excluded_ids_array = null)
 {
     $id_lang = is_null($id_lang) ? Context::getContext()->language->id : (int) $id_lang;
     $children = array();
     $subcats = $this->getSubCategories($id_lang, true);
     if (($max_depth == 0 || $current_depth < $max_depth) && $subcats && count($subcats)) {
         foreach ($subcats as &$subcat) {
             if (!$subcat['id_category']) {
                 break;
             } elseif (!is_array($excluded_ids_array) || !in_array($subcat['id_category'], $excluded_ids_array)) {
                 $categ = new Category($subcat['id_category'], $id_lang);
                 $children[] = $categ->recurseLiteCategTree($max_depth, $current_depth + 1, $id_lang, $excluded_ids_array);
             }
         }
     }
     if (is_array($this->description)) {
         foreach ($this->description as $lang => $description) {
             $this->description[$lang] = Category::getDescriptionClean($description);
         }
     } else {
         $this->description = Category::getDescriptionClean($this->description);
     }
     return array('id' => (int) $this->id, 'link' => Context::getContext()->link->getCategoryLink($this->id, $this->link_rewrite), 'name' => $this->name, 'desc' => $this->description, 'children' => $children);
 }