コード例 #1
0
ファイル: Menu.php プロジェクト: lukkyrich/sentrifugo
 /**
  * This function is used as helper function for building menu.
  * @param Integer $group_id   = id of group
  * @param Integer $role_id    = id of role(useful when calling from different controller)
  * @param Integer $id         = id of role(fetch privileges of a particular role)
  * @return Array Array of menu items,privileges etc.
  */
 public function getgroup_formenu($group_id, $role_id, $id)
 {
     $priveleges_model = new Default_Model_Privileges();
     $group_model = new Default_Model_Groups();
     $group_data = $group_model->getGroupDataById($group_id);
     $res = $this->getMenuArray_formenu($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["parent"] = $res[$i]['parent'];
         $tmp["menuName"] = $this->getMenuText($res[$i]['menuName'], $role_id);
         $tmp["iconPath"] = $res[$i]['iconPath'];
         $tmp["url"] = $res[$i]['url'];
         $tmp['default_permissions']["addpermission"] = $res[$i]['addpermission'];
         $tmp['default_permissions']["editpermission"] = $res[$i]['editpermission'];
         $tmp['default_permissions']["deletepermission"] = $res[$i]['deletepermission'];
         $tmp['default_permissions']["viewpermission"] = $res[$i]['viewpermission'];
         $tmp['default_permissions']["uploadattachments"] = $res[$i]['uploadattachments'];
         $tmp['default_permissions']["viewattachments"] = $res[$i]['viewattachments'];
         $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)) {
             $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];
                         }
                     }
                 }
             }
         }
     }
     //end of foreach.
     $menu_data = array();
     $menu_data_post = array();
     $permission_data = array();
     if ($id != '') {
         $mdata = $priveleges_model->getMenuItemsByRoleId($id);
         foreach ($mdata as $val_arr) {
             $menu_data[] = $val_arr['object'];
             $menu_data_post[$val_arr['id']] = $val_arr['object'];
             if (isset($tmpMenuArr[$val_arr['object']])) {
                 if ($tmpMenuArr[$val_arr['object']] != 0) {
                     $menu_data[] = $tmpMenuArr[$val_arr['object']];
                 }
             }
             $permission_data[$val_arr['object']]['addpermission'] = $val_arr['addpermission'];
             $permission_data[$val_arr['object']]['editpermission'] = $val_arr['editpermission'];
             $permission_data[$val_arr['object']]['deletepermission'] = $val_arr['deletepermission'];
             $permission_data[$val_arr['object']]['viewpermission'] = $val_arr['viewpermission'];
             $permission_data[$val_arr['object']]['uploadattachments'] = $val_arr['uploadattachments'];
             $permission_data[$val_arr['object']]['viewattachments'] = $val_arr['viewattachments'];
         }
         $menu_data1 = array();
         foreach ($menu_data as $menu_id) {
             if (array_key_exists($menu_id, $tmpMenuArr)) {
                 $menu_data1[] = $tmpMenuArr[$menu_id];
             }
         }
         $menu_data1 = array_unique($menu_data1);
         $menu_data = array_unique($menu_data);
         $menu_data = array_merge_recursive($menu_data, $menu_data1);
     }
     $return_arr = array('tmpArr' => $tmpArr, 'menu_data_post' => $menu_data_post, 'menu_data' => $menu_data, 'permission_data' => $permission_data, 'group_data' => $group_data);
     return $return_arr;
 }