Class

eZ\Publish\Core\Repository\UserService

class UserService implements UserService

This service provides methods for managing users and user groups.

Methods

setLogger(LoggerInterface $logger = null)

__construct(Repository $repository, Handler $userHandler, array $settings = array())

Setups service with reference to repository object that created it & corresponding handler.

UserGroup createUserGroup(UserGroupCreateStruct $userGroupCreateStruct, UserGroup $parentGroup)

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

UserGroup loadUserGroup(mixed $id, array $prioritizedLanguages = array())

Loads a user group for the given id.

UserGroup[] loadSubUserGroups(UserGroup $userGroup, int $offset, int $limit = 25, array $prioritizedLanguages = array())

Loads the sub groups of a user group.

mixed[] deleteUserGroup(UserGroup $userGroup)

Removes a user group.

moveUserGroup(UserGroup $userGroup, UserGroup $newParent)

Moves the user group to another parent.

UserGroup updateUserGroup(UserGroup $userGroup, UserGroupUpdateStruct $userGroupUpdateStruct)

Updates the group profile with fields and meta data.

User createUser(UserCreateStruct $userCreateStruct, array $parentGroups)

Create a new user.

User loadUser(mixed $userId, array $prioritizedLanguages = array())

Loads a user.

User loadAnonymousUser()

Loads anonymous user.

User loadUserByCredentials(string $login, string $password, array $prioritizedLanguages = array())

Loads a user for the given login and password.

User loadUserByLogin(string $login, array $prioritizedLanguages = array())

Loads a user for the given login.

User[] loadUsersByEmail(string $email, array $prioritizedLanguages = array())

Loads a user for the given email.

mixed[] deleteUser(User $user)

This method deletes a user.

User updateUser(User $user, UserUpdateStruct $userUpdateStruct)

Updates a user.

assignUserToUserGroup(User $user, UserGroup $userGroup)

Assigns a new user group to the user.

unAssignUserFromUserGroup(User $user, UserGroup $userGroup)

Removes a user group from the user.

UserGroup[] loadUserGroupsOfUser(User $user, int $offset, int $limit = 25, array $prioritizedLanguages = array())

Loads the user groups the user belongs to.

User[] loadUsersOfUserGroup(UserGroup $userGroup, int $offset, int $limit = 25, array $prioritizedLanguages = array())

Loads the users of a user group.

UserCreateStruct newUserCreateStruct(string $login, string $email, string $password, string $mainLanguageCode, ContentType $contentType = null)

Instantiate a user create class.

UserGroupCreateStruct newUserGroupCreateStruct(string $mainLanguageCode, null|ContentType $contentType = null)

Instantiate a user group create class.

UserUpdateStruct newUserUpdateStruct()

Instantiate a new user update struct.

UserGroupUpdateStruct newUserGroupUpdateStruct()

Instantiate a new user group update struct.

Details

at line 67
public setLogger(LoggerInterface $logger = null)

Parameters

LoggerInterface $logger

at line 79
public __construct(Repository $repository, Handler $userHandler, array $settings = array())

Setups service with reference to repository object that created it & corresponding handler.

Parameters

Repository $repository
Handler $userHandler
array $settings

at line 110
public UserGroup createUserGroup(UserGroupCreateStruct $userGroupCreateStruct, UserGroup $parentGroup)

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

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

UserGroupCreateStruct $userGroupCreateStruct a structure for setting all necessary data to create this user group
UserGroup $parentGroup

Return Value

UserGroup

Exceptions

UnauthorizedException if the authenticated user is not allowed to create a user group
InvalidArgumentException if the input structure has invalid data
ContentFieldValidationException if a field in the $userGroupCreateStruct is not valid
ContentValidationException if a required field is missing or set to an empty value

at line 155
public UserGroup loadUserGroup(mixed $id, array $prioritizedLanguages = array())

Loads a user group for the given id.

Parameters

mixed $id
array $prioritizedLanguages Used as prioritized language code on translated properties of returned object.

Return Value

UserGroup

Exceptions

UnauthorizedException if the authenticated user is not allowed to create a user group
NotFoundException if the user group with the given id was not found

at line 174
public UserGroup[] loadSubUserGroups(UserGroup $userGroup, int $offset, int $limit = 25, array $prioritizedLanguages = array())

Loads the sub groups of a user group.

Parameters

UserGroup $userGroup
int $offset the start offset for paging
int $limit the number of user groups returned
array $prioritizedLanguages Used as prioritized language code on translated properties of returned object.

Return Value

UserGroup[]

Exceptions

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

at line 244
public mixed[] deleteUserGroup(UserGroup $userGroup)

Removes a user group.

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

Parameters

UserGroup $userGroup

Return Value

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

Exceptions

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

at line 269
public moveUserGroup(UserGroup $userGroup, UserGroup $newParent)

Moves the user group to another parent.

Parameters

UserGroup $userGroup
UserGroup $newParent

Exceptions

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

at line 316
public UserGroup updateUserGroup(UserGroup $userGroup, UserGroupUpdateStruct $userGroupUpdateStruct)

Updates the group profile with fields and meta data.

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

UserGroup $userGroup
UserGroupUpdateStruct $userGroupUpdateStruct

Return Value

UserGroup

Exceptions

UnauthorizedException if the authenticated user is not allowed to update the user group
ContentFieldValidationException if a field in the $userGroupUpdateStruct is not valid
ContentValidationException if a required field is set empty

at line 371
public User createUser(UserCreateStruct $userCreateStruct, array $parentGroups)

Create a new user.

The created user is published by this method.

Parameters

UserCreateStruct $userCreateStruct the data used for creating the user
array $parentGroups the groups which are assigned to the user after creation

Return Value

User

Exceptions

UnauthorizedException if the authenticated user is not allowed to move the user group
ContentFieldValidationException if a field in the $userCreateStruct is not valid
ContentValidationException if a required field is missing or set to an empty value
InvalidArgumentException if a user with provided login already exists

at line 507
public User loadUser(mixed $userId, array $prioritizedLanguages = array())

Loads a user.

Parameters

mixed $userId
array $prioritizedLanguages Used as prioritized language code on translated properties of returned object.

Return Value

User

Exceptions

NotFoundException if a user with the given id was not found

at line 547
public User loadAnonymousUser()

Loads anonymous user.

Return Value

User

at line 568
public User loadUserByCredentials(string $login, string $password, array $prioritizedLanguages = array())

Loads a user for the given login and password.

If the password hash type differs from that configured for the service, it will be updated to the configured one.

{@inheritdoc}

Parameters

string $login
string $password the plain password
array $prioritizedLanguages Used as prioritized language code on translated properties of returned object.

Return Value

User

Exceptions

InvalidArgumentException if credentials are invalid
NotFoundException if a user with the given credentials was not found

at line 639
public User loadUserByLogin(string $login, array $prioritizedLanguages = array())

Loads a user for the given login.

{@inheritdoc}

Parameters

string $login
array $prioritizedLanguages Used as prioritized language code on translated properties of returned object.

Return Value

User

Exceptions

NotFoundException if a user with the given credentials was not found

at line 660
public User[] loadUsersByEmail(string $email, array $prioritizedLanguages = array())

Loads a user for the given email.

{@inheritdoc}

Parameters

string $email
array $prioritizedLanguages Used as prioritized language code on translated properties of returned object.

Return Value

User[]

at line 681
public mixed[] deleteUser(User $user)

This method deletes a user.

Parameters

User $user

Return Value

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

Exceptions

UnauthorizedException if the authenticated user is not allowed to delete the user

at line 713
public User updateUser(User $user, UserUpdateStruct $userUpdateStruct)

Updates a 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

User $user
UserUpdateStruct $userUpdateStruct

Return Value

User

Exceptions

UnauthorizedException if the authenticated user is not allowed to update the user
ContentFieldValidationException if a field in the $userUpdateStruct is not valid
ContentValidationException if a required field is set empty

at line 822
public assignUserToUserGroup(User $user, UserGroup $userGroup)

Assigns a new user group to the user.

Parameters

User $user
UserGroup $userGroup

Exceptions

UnauthorizedException if the authenticated user is not allowed to assign the user group to the user
InvalidArgumentException if the user is already in the given user group

at line 870
public unAssignUserFromUserGroup(User $user, UserGroup $userGroup)

Removes a user group from the user.

Parameters

User $user
UserGroup $userGroup

Exceptions

UnauthorizedException if the authenticated user is not allowed to remove the user group from the user
InvalidArgumentException if the user is not in the given user group
BadStateException If $userGroup is the last assigned user group

at line 920
public UserGroup[] loadUserGroupsOfUser(User $user, int $offset, int $limit = 25, array $prioritizedLanguages = array())

Loads the user groups the user belongs to.

Parameters

User $user
int $offset the start offset for paging
int $limit the number of user groups returned
array $prioritizedLanguages Used as prioritized language code on translated properties of returned object.

Return Value

UserGroup[]

Exceptions

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

at line 979
public User[] loadUsersOfUserGroup(UserGroup $userGroup, int $offset, int $limit = 25, array $prioritizedLanguages = array())

Loads the users of a user group.

Parameters

UserGroup $userGroup
int $offset the start offset for paging
int $limit the number of users returned
array $prioritizedLanguages Used as prioritized language code on translated properties of returned object.

Return Value

User[]

Exceptions

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

at line 1036
public UserCreateStruct newUserCreateStruct(string $login, string $email, string $password, string $mainLanguageCode, ContentType $contentType = null)

Instantiate a user create class.

Parameters

string $login the login of the new user
string $email the email of the new user
string $password the plain password of the new user
string $mainLanguageCode the main language for the underlying content object
ContentType $contentType 5.x the content type for the underlying content object. In 4.x it is ignored and taken from the configuration

Return Value

UserCreateStruct

at line 1065
public UserGroupCreateStruct newUserGroupCreateStruct(string $mainLanguageCode, null|ContentType $contentType = null)

Instantiate a user group create class.

Parameters

string $mainLanguageCode The main language for the underlying content object
null|ContentType $contentType 5.x the content type for the underlying content object. In 4.x it is ignored and taken from the configuration

Return Value

UserGroupCreateStruct

at line 1087
public UserUpdateStruct newUserUpdateStruct()

Instantiate a new user update struct.

Return Value

UserUpdateStruct

at line 1097
public UserGroupUpdateStruct newUserGroupUpdateStruct()

Instantiate a new user group update struct.

Return Value

UserGroupUpdateStruct