function UserAclRoles($user_id = '') { $show_box['title'] = '获取用户全部角色'; $return_value = ''; $roles_idname = array(); $roles_id = array(); $sp_roles = Q::ini('appini/sp_role'); // 第一步:直接从中间表获得用户的全部角色ID $user_roles = UsersHaveRoles::find('user_id = ?', intval($user_id))->asArray()->getAll(); //dump($user_roles); // 取出有用的ID,去除deny的ID foreach ($user_roles as $value) { if ($value['is_include']) { $roles_id[] = $value['role_id']; } } //dump ( $roles_id); $roles_arr = Roles::find('role_id in (?)', Q::normalize($roles_id, ","))->asArray()->getAll(); foreach ($roles_arr as $value) { $roles_idname[$value['role_id']] = $value['rolename']; } //dump($roles_idname); if (in_array($sp_roles['REPEAL'], $roles_idname)) { $return_value = array($value['role_id'] => $sp_roles['REPEAL']); return $return_value; } elseif (in_array($sp_roles['FREEZE'], $roles_idname)) { $return_value = array($value['role_id'] => $sp_roles['FREEZE']); return $return_value; } elseif (in_array($sp_roles['UNCHECKED'], $roles_idname)) { $return_value = array($value['role_id'] => $sp_roles['UNCHECKED']); return $return_value; } else { return $roles_idname; } }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(RolesRequest $roles, $id) { //this is method to saving $roles = Roles::find($id); $roles->name = Input::get('name'); $roles->access = json_encode(Input::get('access')); $roles->save(); Session::flash('message', 'You have successfully added Roles'); return Redirect::to('roles'); }
/** * Find indexed roles by role IDs * * @param void * @return array */ function findIndexedByIds($ids) { $result = array(); if (is_foreachable($ids)) { $roles = Roles::find(array('conditions' => array('id IN (?)', $ids))); if (is_foreachable($roles)) { foreach ($roles as $role) { $result[$role->getId()] = $role; } // foreach } // if } // if return $result; }
public function editedRoleAction($id) { Input::flash(); $data = Input::all(); $rules = array('rolename' => array('min:3', 'required')); // Build the custom messages array. $messages = array('rolename.min' => 'ชื่อบทบาทจะต้องยาวมากกว่า :min ตัวอักษร', 'rolename.required' => 'กรุณาระบุชื่อบทบาท'); // Create a new validator instance. $validator = Validator::make($data, $rules, $messages); if ($validator->passes()) { $role = Roles::find($id); $ck_role = $role->checkRole($data['rolename']); if ($ck_role) { $role->role_name = $data['rolename']; $role->save(); return Redirect::to('role')->with('success', 'บันทึกชื่อบทบาทรหัส: ' . $id . ' สำเร็จ.'); } else { return Redirect::to('role-add')->with('warning', 'มีชื่อบทบาทนี้ในระบบแล้ว'); } } else { // $errors = $validator->messages(); return Redirect::to('role-edit/' . $id)->withErrors($validator); } }
public function eliminarRol() { $rol = Input::get("rol"); $roles = Permisos::where("role_id", "=", $rol)->get(); if (count($roles) > 0) { return Response::json(array("estado" => "1")); } else { $role = Role::find($rol); $role->delete(); $permisos = Roles::find($rol); $permisos->delete(); $html = (string) View::make("dashboard.roles.rolesTablaRoles")->with(array("roles" => Role::all())); return Response::json(array("estado" => "2", "html" => $html)); } }
/** * Remove the specified user from storage. * * @param $role * @internal param $id * @return Response */ public function deleteIndex($role) { $id = $role->id; if (!$role->delete()) { return Api::json(array('result' => 'error', 'error' => Lang::get('core.delete_error'))); } $roles = Roles::find($id); return empty($roles) ? Api::json(array('result' => 'success')) : Api::json(array('result' => 'error', 'error' => Lang::get('core.delete_error'))); }
/** * 角色绑定权限 */ function actionRoleBind() { $this->_pathway->addStep('角色绑定权限'); $id = $this->_context->id; $role = Roles::find()->getById($id); if ($this->_context->isPOST()) { try { $permission_ids = $this->_context->permission_ids; $permission_ids = $permission_ids != '' ? Q::normalize($permission_ids) : '0'; $role->permissions = Permissions::find("id in (?)", $permission_ids)->getAll(); $role->save(); } catch (QValidator_ValidateFailedException $ex) { } } $permission = Helper_Permissions::getAllPermissions(); $permission_ids = array(); foreach ($role->permissions as $v) { $permission_ids[] = $v->id; } $this->_view['role'] = $role; $this->_view['permissions'] = $permission; $this->_view['permission_ids'] = $permission_ids; }