Copied!

UserService

UserService.php : 37
Interface

This service provides methods for managing users and user groups.

Methods

publicassignUserToUserGroup()

UserService.php : 351

Assigns a new user group to the user.

public assignUserToUserGroup(User $user, UserGroup $userGroup) : void

If the user is already in the given user group this method does nothing.

Parameters

Name Type Default value Description
$user User - -
$userGroup UserGroup - -
Tags
Throws
UnauthorizedException

if the authenticated user is not allowed to assign the user group to the user

publiccheckUserCredentials()

UserService.php : 220

Checks if credentials are valid for provided User.

public checkUserCredentials(User $user, string $credentials) : bool

Parameters

Name Type Default value Description
$user User - -
$credentials string - -

Return values

bool

publiccreateUser()

UserService.php : 173

Create a new user. The created user is published by this method.

public createUser(UserCreateStruct $userCreateStruct, array<string|int, mixed> $parentGroups) : User

Parameters

Name Type Default value Description
$userCreateStruct UserCreateStruct -

the data used for creating the user

$parentGroups array<string|int, mixed> -

the groups of type UserGroup which are assigned to the user after creation

Return values

User

Tags
Throws
UnauthorizedException

if the authenticated user is not allowed to move the user group

Throws
ContentFieldValidationException

if a field in the $userCreateStruct is not valid

Throws
ContentValidationException

if a required field is missing or set to an empty value

Throws
InvalidArgumentException

if a field value is not accepted by the field type if a user with provided login already exists

publiccreateUserGroup()

UserService.php : 56

Creates a new user group using the data provided in the ContentCreateStruct parameter.

public createUserGroup(UserGroupCreateStruct $userGroupCreateStruct, UserGroup $parentGroup) : UserGroup

In 4.x in the content type parameter in the profile is ignored

  • the content type is determined via configuration and can be set to null. The returned version is published.

Parameters

Name Type Default value Description
$userGroupCreateStruct UserGroupCreateStruct -

a structure for setting all necessary data to create this user group

$parentGroup UserGroup - -

Return values

UserGroup

Tags
Throws
UnauthorizedException

if the authenticated user is not allowed to create a user group

Throws
InvalidArgumentException

if the input structure has invalid data

Throws
ContentFieldValidationException

if a field in the $userGroupCreateStruct is not valid

Throws
ContentValidationException

if a required field is missing or set to an empty value

publicdeleteUser()

UserService.php : 283

This method deletes a user.

public deleteUser(User $user) : array<string|int, int>

Parameters

Name Type Default value Description
$user User - -

Return values

array<string|int, int>

Affected Location Id's (List of Locations of the Content that was deleted)

Tags
Throws
UnauthorizedException

if the authenticated user is not allowed to delete the user

publicdeleteUserGroup()

UserService.php : 123

Removes a user group.

public deleteUserGroup(UserGroup $userGroup) : array<string|int, int>

the users which are not assigned to other groups will be deleted.

Parameters

Name Type Default value Description
$userGroup UserGroup - -

Return values

array<string|int, int>

Affected Location Id's (List of Locations of the Content that was deleted)

Tags
Throws
UnauthorizedException

if the authenticated user is not allowed to create a user group

publicexpireUserToken()

UserService.php : 339

Expires user token with user hash.

public expireUserToken(string $hash) : void

Parameters

Name Type Default value Description
$hash string - -

publicfindUserGroups()

UserService.php : 457

Finds user groups matching the given filter, using content filtering ({@see ContentService::find()}).

public findUserGroups(Filter $filter[, User|null $user = null ][, array<string|int, string> $prioritizedLanguages = [] ]) : UserGroupList

Location criteria of the filter are evaluated on the main Location of a user group, so e.g. ParentLocationId with the main Location of a user group matches its subgroups, consistently with UserGroup::$parentId.

The filter is limited to the user group content type, and the content ID is added as the last sort clause. Only user groups the current user is allowed to read are returned and counted. User groups without a main Location (e.g. trashed ones) are neither returned nor counted. As in ContentService::find(), a filter limit of 0 means no limit.

With a user, only the user groups it is directly assigned to are matched: the content items holding the parent Locations of its Locations the current user is allowed to read, as in loadUserGroupsOfUser().

Parameters

Name Type Default value Description
$filter Filter - -
$user User|null null -
$prioritizedLanguages array<string|int, string> []

Used as prioritized language code on translated properties of returned objects. User groups not available in any of them (and not always available) are neither returned nor counted.

Return values

UserGroupList

Tags
Throws
NotFoundException

if the given user does not exist

Throws
UnauthorizedException

if the current user is not allowed to read the given user

Throws
BadStateException

if user groups matched by the filter were deleted or changed before they could be loaded

publicfindUsers()

UserService.php : 429

Finds users matching the given filter, using Location filtering ({@see LocationService::find()}).

public findUsers(Filter $filter[, UserGroup|null $userGroup = null ][, array<string|int, string> $prioritizedLanguages = [] ]) : UserList

Each user is matched through exactly one of its Locations: the Location directly under the main Location of the given user group (its direct members, also those assigned through a secondary Location), or the main Location without a user group. Location criteria of the filter and the content/read permission are evaluated on that Location, so each user is returned and counted once.

The filter is limited to the user content types, and the content ID is added as the last sort clause. Only users the current user is allowed to read are returned and counted. A user group without a main Location has no members. As in LocationService::find(), a filter limit of 0 means no limit.

Parameters

Name Type Default value Description
$filter Filter - -
$userGroup UserGroup|null null -
$prioritizedLanguages array<string|int, string> []

Used as prioritized language code on translated properties of returned objects. Users not available in any of them (and not always available) are neither returned nor counted.

Return values

UserList

Tags
Throws
NotFoundException

if the given user group does not exist

Throws
UnauthorizedException

if the current user is not allowed to read the given user group

Throws
BadStateException

if users matched by the filter were deleted or changed before they could be loaded

publicgetPasswordInfo()

UserService.php : 553

Returns information about password for a given user.

public getPasswordInfo(User $user) : PasswordInfo

Parameters

Name Type Default value Description
$user User - -

Return values

PasswordInfo

publicisUser()

UserService.php : 472

Checks if Content is a user.

public isUser(Content $content) : bool

@since 7.4

Parameters

Name Type Default value Description
$content Content - -

Return values

bool

publicisUserGroup()

UserService.php : 483

Checks if Content is a user group.

public isUserGroup(Content $content) : bool

Parameters

Name Type Default value Description
$content Content - -

Return values

bool

publicloadSubUserGroups()

UserService.php : 105

Loads the sub groups of a user group.

public loadSubUserGroups(UserGroup $userGroup[, int $offset = 0 ][, int $limit = 25 ][, array<string|int, string> $prioritizedLanguages = [] ]) : array<string|int, UserGroup>

Parameters

Name Type Default value Description
$userGroup UserGroup - -
$offset int 0

the start offset for paging

$limit int 25

the number of user groups returned

$prioritizedLanguages array<string|int, string> []

Used as prioritized language code on translated properties of returned object.

Return values

array<string|int, UserGroup>

Tags
Throws
UnauthorizedException

if the authenticated user is not allowed to read the user group

publicloadUser()

UserService.php : 188

Loads a user.

public loadUser(mixed $userId[, array<string|int, string> $prioritizedLanguages = [] ]) : User

Parameters

Name Type Default value Description
$userId mixed - -
$prioritizedLanguages array<string|int, string> []

Used as prioritized language code on translated properties of returned object.

Return values

User

Tags
Throws
NotFoundException

if a user with the given id was not found

publicloadUserByEmail()

UserService.php : 236

Loads a user for the given email.

public loadUserByEmail(string $email[, array<string|int, string> $prioritizedLanguages = [] ]) : User

Parameters

Name Type Default value Description
$email string - -
$prioritizedLanguages array<string|int, string> []

Used as prioritized language code on translated properties of returned object.

Return values

User

Tags
Throws
InvalidArgumentException
Throws
NotFoundException

publicloadUserByLogin()

UserService.php : 207

Loads a user for the given login.

public loadUserByLogin(string $login[, array<string|int, string> $prioritizedLanguages = [] ]) : User

Since 6.1 login is case-insensitive across all storage engines and database backends, like was the case with mysql before in Ibexa 3.x/4.x/5.x.

Parameters

Name Type Default value Description
$login string - -
$prioritizedLanguages array<string|int, string> []

Used as prioritized language code on translated properties of returned object.

Return values

User

Tags
Throws
NotFoundException

if a user with the given credentials was not found

Throws
InvalidArgumentException

publicloadUserByToken()

UserService.php : 269

Loads a user with user hash key.

public loadUserByToken(string $hash[, array<string|int, string> $prioritizedLanguages = [] ]) : User

Parameters

Name Type Default value Description
$hash string - -
$prioritizedLanguages array<string|int, string> [] -

Return values

User

publicloadUserGroup()

UserService.php : 72

Loads a user group for the given id.

public loadUserGroup(int $id[, array<string|int, string> $prioritizedLanguages = [] ]) : UserGroup

Parameters

Name Type Default value Description
$id int - -
$prioritizedLanguages array<string|int, string> []

Used as prioritized language code on translated properties of returned object.

Return values

UserGroup

Tags
Throws
UnauthorizedException

if the authenticated user is not allowed to load a user group

Throws
NotFoundException

if the user group with the given id was not found

publicloadUserGroupByRemoteId()

UserService.php : 88

Loads a user group for the given remote id.

public loadUserGroupByRemoteId(string $remoteId[, array<string|int, string> $prioritizedLanguages = [] ]) : UserGroup

Parameters

Name Type Default value Description
$remoteId string - -
$prioritizedLanguages array<string|int, string> []

Used as prioritized language code on translated properties of returned object.

Return values

UserGroup

Tags
Throws
UnauthorizedException

if the authenticated user is not allowed to load a user group

Throws
NotFoundException

if the user group with the given id was not found

publicloadUserGroupsOfUser()

UserService.php : 383

Loads the user groups the user belongs to.

public loadUserGroupsOfUser(User $user[, int $offset = 0 ][, int $limit = 25 ][, array<string|int, string> $prioritizedLanguages = [] ]) : array<string|int, UserGroup>

Parameters

Name Type Default value Description
$user User - -
$offset int 0

the start offset for paging

$limit int 25

the number of user groups returned

$prioritizedLanguages array<string|int, string> []

Used as prioritized language code on translated properties of returned object.

Return values

array<string|int, UserGroup>

Tags
Throws
UnauthorizedException

if the authenticated user is not allowed read the user or user group

publicloadUsersByEmail()

UserService.php : 256

Loads a users for the given email.

public loadUsersByEmail(string $email[, array<string|int, string> $prioritizedLanguages = [] ]) : array<string|int, User>

Note: This method loads user by $email where $email might be case-insensitive on certain storage engines!

Returns an array of Users since Ibexa has under certain circumstances allowed several users having same email in the past (by means of a configuration option).

Parameters

Name Type Default value Description
$email string - -
$prioritizedLanguages array<string|int, string> []

Used as prioritized language code on translated properties of returned object.

Return values

array<string|int, User>

Tags
Throws
InvalidArgumentException

publicloadUsersOfUserGroup()

UserService.php : 402

Loads the users of a user group.

public loadUsersOfUserGroup(UserGroup $userGroup[, int $offset = 0 ][, int $limit = 25 ][, array<string|int, string> $prioritizedLanguages = [] ]) : array<string|int, User>

Parameters

Name Type Default value Description
$userGroup UserGroup - -
$offset int 0

the start offset for paging

$limit int 25

the number of users returned

$prioritizedLanguages array<string|int, string> []

Used as prioritized language code on translated properties of returned object.

Return values

array<string|int, User>

Tags
Throws
UnauthorizedException

if the authenticated user is not allowed to read the users or user group

publicmoveUserGroup()

UserService.php : 133

Moves the user group to another parent.

public moveUserGroup(UserGroup $userGroup, UserGroup $newParent) : void

Parameters

Name Type Default value Description
$userGroup UserGroup - -
$newParent UserGroup - -
Tags
Throws
UnauthorizedException

if the authenticated user is not allowed to move the user group

publicnewUserCreateStruct()

UserService.php : 496

Instantiate a user create class.

public newUserCreateStruct(string $login, string $email, string $password, string $mainLanguageCode[, ContentType|null $contentType = null ]) : UserCreateStruct

Parameters

Name Type Default value Description
$login string -

the login of the new user

$email string -

the email of the new user

$password string -

the plain password of the new user

$mainLanguageCode string -

the main language for the underlying content object

$contentType ContentType|null null

content type for the underlying content object.

Return values

UserCreateStruct

publicnewUserGroupCreateStruct()

UserService.php : 512

Instantiate a user group create class.

public newUserGroupCreateStruct(string $mainLanguageCode[, ContentType|null $contentType = null ]) : UserGroupCreateStruct

Parameters

Name Type Default value Description
$mainLanguageCode string -

The main language for the underlying content object

$contentType ContentType|null null

5.x the content type for the underlying content object. In 4.x it is ignored and taken from the configuration

Return values

UserGroupCreateStruct

publicnewUserGroupUpdateStruct()

UserService.php : 529

Instantiate a new user group update struct.

public newUserGroupUpdateStruct() : UserGroupUpdateStruct

Return values

UserGroupUpdateStruct

publicnewUserUpdateStruct()

UserService.php : 522

Instantiate a new user update struct.

public newUserUpdateStruct() : UserUpdateStruct

Return values

UserUpdateStruct

publicunAssignUserFromUserGroup()

UserService.php : 366

Removes a user group from the user.

public unAssignUserFromUserGroup(User $user, UserGroup $userGroup) : void

Parameters

Name Type Default value Description
$user User - -
$userGroup UserGroup - -
Tags
Throws
UnauthorizedException

if the authenticated user is not allowed to remove the user group from the user

Throws
InvalidArgumentException

if the user is not in the given user group

Throws
BadStateException

If $userGroup is the last assigned user group

publicupdateUser()

UserService.php : 301

Updates a user.

public updateUser(User $user, UserUpdateStruct $userUpdateStruct) : User

4.x: If the versionUpdateStruct is set in the user update structure, this method internally creates a content draft, updates ts with the provided data and publishes the draft. If a draft is explicitly required, the user group can be updated via the content service methods.

Parameters

Name Type Default value Description
$user User - -
$userUpdateStruct UserUpdateStruct - -

Return values

User

Tags
Throws
ContentFieldValidationException

if a field in the $userUpdateStruct is not valid

Throws
ContentValidationException

if a required field is set empty

Throws
InvalidArgumentException

if a field value is not accepted by the field type

Throws
UnauthorizedException

if the authenticated user is not allowed to update the user

publicupdateUserGroup()

UserService.php : 154

Updates the group profile with fields and meta data.

public updateUserGroup(UserGroup $userGroup, UserGroupUpdateStruct $userGroupUpdateStruct) : UserGroup

4.x: If the versionUpdateStruct is set in $userGroupUpdateStruct, this method internally creates a content draft, updates ts with the provided data and publishes the draft. If a draft is explicitly required, the user group can be updated via the content service methods.

Parameters

Name Type Default value Description
$userGroup UserGroup - -
$userGroupUpdateStruct UserGroupUpdateStruct - -

Return values

UserGroup

Tags
Throws
UnauthorizedException

if the authenticated user is not allowed to move the user group

Throws
ContentFieldValidationException

if a field in the $userGroupUpdateStruct is not valid

Throws
ContentValidationException

if a required field is set empty

Throws
InvalidArgumentException

if a field value is not accepted by the field type

publicupdateUserPassword()

UserService.php : 316

Validates and updates just the user's password.

public updateUserPassword(User $user, string $newPassword) : User

Parameters

Name Type Default value Description
$user User - -
$newPassword string - -

Return values

User

Tags
Throws
ContentValidationException
Throws
ContentFieldValidationException

if new password does not pass validation

Throws
UnauthorizedException

if the authenticated user is not allowed to update the user

Throws
InvalidArgumentException
Throws
NotFoundException
Throws
Exception

publicupdateUserToken()

UserService.php : 329

Update the user token information specified by the user token struct.

public updateUserToken(User $user, UserTokenUpdateStruct $userTokenUpdateStruct) : User

Parameters

Name Type Default value Description
$user User - -
$userTokenUpdateStruct UserTokenUpdateStruct - -

Return values

User

publicvalidatePassword()

UserService.php : 541

Validates given password.

public validatePassword(string $password[, PasswordValidationContext|null $context = null ]) : array<string|int, ValidationError>

Parameters

Name Type Default value Description
$password string - -
$context PasswordValidationContext|null null -

Return values

array<string|int, ValidationError>

Tags
Throws
ContentValidationException