コード例 #1
0
 public function updateUserRole($userId, $roleId, $addOrRemove, $updateSubUsers = false)
 {
     $confStorage = ConfService::getConfStorageImpl();
     $user = $confStorage->createUserObject($userId);
     if (!AuthService::canAdministrate($user)) {
         throw new Exception("Cannot update user data for " . $userId);
     }
     if ($addOrRemove == "add") {
         $roleObject = AuthService::getRole($roleId);
         $user->addRole($roleObject);
     } else {
         $user->removeRole($roleId);
     }
     $user->save("superuser");
     $loggedUser = AuthService::getLoggedUser();
     if ($loggedUser->getId() == $user->getId()) {
         AuthService::updateUser($user);
     }
     return $user;
 }