Exemple #1
0
 public function getMenusWithChilds($menu_id)
 {
     $menu_model = new Default_Model_Menu();
     $res = $menu_model->getTotalMenuArray();
     $tmpArr = array();
     $tmpMenuArr = array();
     $tmpMenuDataArr = array();
     for ($i = 0; $i < sizeof($res); $i++) {
         $tmpMenuArr[$res[$i]['id']] = $res[$i]['parent'];
         $tmp = array();
         $tmp['id'] = $res[$i]['id'];
         $tmp["parent"] = $res[$i]['parent'];
         $tmp["menuName"] = $res[$i]['menuName'];
         $tmpMenuDataArr[$res[$i]['id']] = $tmp;
     }
     $emptyArr = array();
     foreach ($tmpMenuArr as $key => $value) {
         if ($value == 0 && !array_key_exists($value, $tmpArr)) {
             $tmpArr[$key] = $emptyArr;
             $tmpArr[$key] = $tmpMenuDataArr[$key];
         } else {
             if (array_key_exists($value, $tmpArr) && !array_key_exists($key, $tmpArr[$value])) {
                 $tmpArr[$value]['childs'][$key] = $tmpMenuDataArr[$key];
             }
         }
     }
     foreach ($tmpArr as $key => $value_arr) {
         if (is_array($value_arr)) {
             if (isset($value_arr['childs']) && is_array($value_arr['childs'])) {
                 foreach ($value_arr['childs'] as $c_key => $ch_value) {
                     foreach ($tmpMenuArr as $tkey => $tvalue) {
                         if ($tvalue == $c_key && !array_key_exists($tkey, $tmpArr)) {
                             $tmpArr[$key]['childs'][$c_key]['childs'][$tkey] = $tmpMenuDataArr[$tkey];
                         }
                     }
                 }
             }
         }
     }
     $childs_array = array();
     if (array_key_exists($menu_id, $tmpArr)) {
         $childs_array[] = $menu_id;
         if (isset($tmpArr[$menu_id]['childs'])) {
             foreach ($tmpArr[$menu_id]['childs'] as $chkey1 => $chvalue1) {
                 $childs_array[] = $chkey1;
                 if (isset($chvalue1['childs'])) {
                     foreach ($chvalue1['childs'] as $chkey2 => $chvalue2) {
                         $childs_array[] = $chkey2;
                     }
                 }
             }
         }
     } else {
         foreach ($tmpArr as $menuid => $menu_data) {
             if (isset($tmpArr[$menuid]['childs'])) {
                 foreach ($tmpArr[$menuid]['childs'] as $chkey1 => $chvalue1) {
                     if ($chkey1 == $menu_id) {
                         $childs_array[] = $chkey1;
                         if (isset($chvalue1['childs'])) {
                             foreach ($chvalue1['childs'] as $chkey2 => $chvalue2) {
                                 $childs_array[] = $chkey2;
                             }
                         }
                     }
                 }
             }
         }
     }
     return $childs_array;
 }