class GroupMembershipService (View source)

Service for managing group memberships

Handles adding/removing users to/from groups

Methods

__construct(UserGroupMemberRepositoryInterface $memberRepository, UserGroupRepositoryInterface $groupRepository)

No description

addUserToGroup(int $groupId, int $userId)

Add a user to a group

bool
removeUserFromGroup(int $groupId, int $userId)

Remove a user from a group

array
listGroupMembers(int $groupId)

List all members of a group

array
listUserGroups(int $userId)

List all groups a user belongs to

array
bulkAddUsers(int $groupId, array $userIds)

Add multiple users to a group

array
bulkRemoveUsers(int $groupId, array $userIds)

Remove multiple users from a group

bool
isUserMember(int $groupId, int $userId)

Check if a user is a member of a group

Details

__construct(UserGroupMemberRepositoryInterface $memberRepository, UserGroupRepositoryInterface $groupRepository)

No description

Parameters

UserGroupMemberRepositoryInterface $memberRepository
UserGroupRepositoryInterface $groupRepository

UserGroupMember addUserToGroup(int $groupId, int $userId)

Add a user to a group

Parameters

int $groupId

Group ID

int $userId

User ID

Return Value

UserGroupMember

Exceptions

InvalidArgumentException

bool removeUserFromGroup(int $groupId, int $userId)

Remove a user from a group

Permission effect: User immediately loses permissions granted by this group

Parameters

int $groupId

Group ID

int $userId

User ID

Return Value

bool

Exceptions

InvalidArgumentException

array listGroupMembers(int $groupId)

List all members of a group

Parameters

int $groupId

Group ID

Return Value

array

Exceptions

InvalidArgumentException

array listUserGroups(int $userId)

List all groups a user belongs to

Parameters

int $userId

User ID

Return Value

array

array bulkAddUsers(int $groupId, array $userIds)

Add multiple users to a group

Parameters

int $groupId

Group ID

array $userIds

Array of user IDs

Return Value

array

Results of bulk operation

array bulkRemoveUsers(int $groupId, array $userIds)

Remove multiple users from a group

Parameters

int $groupId

Group ID

array $userIds

Array of user IDs

Return Value

array

Results of bulk operation

bool isUserMember(int $groupId, int $userId)

Check if a user is a member of a group

Parameters

int $groupId

Group ID

int $userId

User ID

Return Value

bool