public function change_role($user_id, $new_role) { $dao = Model_Role::data_access(); $role = $dao->filter(Model_Role::NAME, $new_role)->find(); $role_id = $role[0]->id; $dao = Model_UserRole::data_access(); $user_role_array = $dao->filter(Model_UserRole::UserId, $user_id)->find(); $user_role = $user_role_array[0]; $user_role->role_id = $role_id; $success = $user_role->save(); return $success; }
public function get_user_role($user_id) { if ($user_id == 0) { return ""; } $user_role_array = Model_UserRole::data_access()->filter(Model_UserRole::UserId, $user_id)->find(); $user_role = $user_role_array[0]; $role_id = $user_role->role_id; $role = Model_Role::data_access()->find_by_pk($role_id); $role_name = $role->name; return $role_name; }
public function get_admins() { $dao = Model_Role::data_access(); $admin = $dao->filter(Model_Role::NAME, 'admin')->find(); $admin_id = $admin[0]->id; $dao = Model_UserRole::data_access(); $user_role = $dao->filter(Model_UserRole::RoleId, $admin_id)->find(); $user = array(); foreach ($user_role as $key => $value) { $dao = Model_User::data_access(); $tmp = $dao->filter(Model_User::UserId, $value->user_id)->find(); $user[$key] = $tmp[0]; } return $user; }