Example #1
0
 /**
  * This function is used as helper function  for services to build menu.     
  * @param Integer $role_id    = id of role
  * @param Integer $group_id   = id of group      
  * @return Array Array of menu items,privileges etc.
  */
 public function getgroupmenu_service($group_id, $role_id)
 {
     $default_parent_menu = sapp_Global::mobile_parent_menus();
     $default_child_menu = sapp_Global::mobile_child_menus();
     $res = $this->getMenuArray($role_id, $group_id);
     $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["menuName"] = $res[$i]['menuName'];
         $tmpMenuDataArr[$res[$i]['id']] = $tmp;
     }
     /**
      ** prepare an array with parent and second level menus - $tmpArr
      **/
     $emptyArr = array();
     foreach ($tmpMenuArr as $key => $value) {
         if ($value == 0 && !array_key_exists($value, $tmpArr) && in_array($key, $default_parent_menu)) {
             $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) && in_array($tkey, $default_child_menu)) {
                             $tmpArr[$key]['childs'][$tkey] = $tmpMenuDataArr[$tkey];
                         }
                     }
                 }
             }
         }
     }
     //end of foreach.
     foreach ($tmpArr as $key => $value_arr) {
         if (is_array($value_arr)) {
             if (isset($value_arr['childs']) && is_array($value_arr['childs'])) {
                 $new_childs = array();
                 foreach ($value_arr['childs'] as $c_key => $ch_value) {
                     if (in_array($c_key, $default_child_menu)) {
                         $new_childs[$c_key] = $ch_value;
                     }
                 }
                 $tmpArr[$key]['childs'] = $new_childs;
             }
         }
     }
     //end of foreach.
     return $tmpArr;
 }