diff --git a/src/Administration.php b/src/Administration.php index ff962c4..d6c9349 100644 --- a/src/Administration.php +++ b/src/Administration.php @@ -186,6 +186,79 @@ final class Administration extends UserManager { ); } + /** + * Takes away the specified role from the user with the given ID + * + * A user may have any number of roles (i.e. no role at all, a single role, or any combination of roles) + * + * @param int $userId the ID of the user to take the role away from + * @param int $role the role as one of the constants from the {@see Role} class + * @throws UnknownIdException if no user with the specified ID has been found + * + * @see Role + */ + public function removeRoleForUserById($userId, $role) { + $userFound = $this->removeRoleForUserByColumnValue( + 'id', + (int) $userId, + $role + ); + + if ($userFound === false) { + throw new UnknownIdException(); + } + } + + /** + * Takes away the specified role from the user with the given email address + * + * A user may have any number of roles (i.e. no role at all, a single role, or any combination of roles) + * + * @param string $userEmail the email address of the user to take the role away from + * @param int $role the role as one of the constants from the {@see Role} class + * @throws InvalidEmailException if no user with the specified email address has been found + * + * @see Role + */ + public function removeRoleForUserByEmail($userEmail, $role) { + $userEmail = self::validateEmailAddress($userEmail); + + $userFound = $this->removeRoleForUserByColumnValue( + 'email', + $userEmail, + $role + ); + + if ($userFound === false) { + throw new InvalidEmailException(); + } + } + + /** + * Takes away the specified role from the user with the given username + * + * A user may have any number of roles (i.e. no role at all, a single role, or any combination of roles) + * + * @param string $username the username of the user to take the role away from + * @param int $role the role as one of the constants from the {@see Role} class + * @throws UnknownUsernameException if no user with the specified username has been found + * @throws AmbiguousUsernameException if multiple users with the specified username have been found + * + * @see Role + */ + public function removeRoleForUserByUsername($username, $role) { + $userData = $this->getUserDataByUsername( + \trim($username), + [ 'id' ] + ); + + $this->removeRoleForUserByColumnValue( + 'id', + (int) $userData['id'], + $role + ); + } + protected function throttle($actionType, $customSelector = null) { // do nothing }