Ejemplo n.º 1
0
 /**
  * Returns an array representing a tree of ShopCategories,
  * not including the root chosen.
  *
  * The resulting array looks like:
  * array(
  *   parent ID => array(
  *     child ID => array(
  *       'ord' => val,
  *       'active' => val,
  *       'level' => val,
  *     ),
  *     ... more children
  *   ),
  *   ... more parents
  * )
  * @static
  * @param   integer $parent_id          The optional root ShopCategory ID.
  *                                      Defaults to 0 (zero).
  * @param   boolean $active             Only return ShopCategories
  *                                      with active==1 if true.
  *                                      Defaults to false.
  * @param   integer $level              Optional nesting level, initially 0.
  *                                      Defaults to 0 (zero).
  * @return  array                       The array of ShopCategories,
  *                                      or false on failure.
  */
 static function getCategoryTree($parent_id = 0, $active = false, $level = 0)
 {
     // Get the ShopCategory's children
     $arrChildShopCategories = ShopCategory::getChildCategoriesById($parent_id, $active);
     // has there been an error?
     if ($arrChildShopCategories === false) {
         return false;
     }
     // initialize root tree
     $arrCategoryTree = array();
     // local parent subtree
     $arrCategoryTree[$parent_id] = array();
     // the local parent's children
     foreach ($arrChildShopCategories as $objChildShopCategory) {
         $childCategoryId = $objChildShopCategory->id();
         $arrCategoryTree[$parent_id][$childCategoryId] = array('ord' => $objChildShopCategory->ord(), 'active' => $objChildShopCategory->active(), 'level' => $level);
         // get the grandchildren
         foreach (ShopCategory::getCategoryTree($childCategoryId, $active, $level + 1) as $subCategoryId => $objSubCategory) {
             $arrCategoryTree[$subCategoryId] = $objSubCategory;
         }
     }
     return $arrCategoryTree;
 }