class GroupService (View source)

Creates, updates, deletes and lists user groups, with the view checks the group pages need.

Handles group CRUD operations, visibility filtering, and validation

Methods

__construct(UserGroupRepositoryInterface $groupRepository, ZoneOwnershipGuard $ownershipGuard, LastSuperAdminGuard $superAdminGuard)

No description

array
listGroups(int $userId, bool $isAdmin)

List groups with visibility filtering

UserGroup|null
getGroupById(int $groupId, int $userId, bool $isAdmin)

Get a group by ID with visibility check

bool
canUserViewGroup(int $groupId, int $userId)

Check if a user can view a group

createGroup(string $name, int $permTemplId, string|null $description = null, int|null $createdBy = null)

Create a new group

UserGroup|array
updateGroup(int $groupId, string|null $name = null, string|null $description = null, int|null $permTemplId = null)

Update an existing group

bool|array
deleteGroup(int $groupId)

Delete a group

array
getGroupDetails(int $groupId)

Get group details including member and zone counts

bool
isGroupNameAvailable(string $name, int|null $excludeGroupId = null)

Check if a group name is available

Details

__construct(UserGroupRepositoryInterface $groupRepository, ZoneOwnershipGuard $ownershipGuard, LastSuperAdminGuard $superAdminGuard)

No description

Parameters

UserGroupRepositoryInterface $groupRepository
ZoneOwnershipGuard $ownershipGuard
LastSuperAdminGuard $superAdminGuard

array listGroups(int $userId, bool $isAdmin)

List groups with visibility filtering

Parameters

int $userId

Current user ID

bool $isAdmin

Whether the user is an admin (überuser)

Return Value

array

UserGroup|null getGroupById(int $groupId, int $userId, bool $isAdmin)

Get a group by ID with visibility check

Parameters

int $groupId

Group ID

int $userId

Current user ID

bool $isAdmin

Whether the user is an admin

Return Value

UserGroup|null

Exceptions

InvalidArgumentException

bool canUserViewGroup(int $groupId, int $userId)

Check if a user can view a group

Parameters

int $groupId

Group ID

int $userId

User ID

Return Value

bool

UserGroup createGroup(string $name, int $permTemplId, string|null $description = null, int|null $createdBy = null)

Create a new group

Parameters

string $name

Group name (must be unique)

int $permTemplId

Permission template ID

string|null $description

Optional description

int|null $createdBy

User ID who created the group

Return Value

UserGroup

Exceptions

InvalidArgumentException

UserGroup|array updateGroup(int $groupId, string|null $name = null, string|null $description = null, int|null $permTemplId = null)

Update an existing group

Parameters

int $groupId

Group ID

string|null $name

New name (if provided)

string|null $description

New description (if provided)

int|null $permTemplId

New permission template ID (if provided)

Return Value

UserGroup|array

The saved group, or the refusal when the new template would leave no active super admin

Exceptions

InvalidArgumentException

bool|array deleteGroup(int $groupId)

Delete a group

Cascade deletes will remove all memberships and zone associations

Parameters

int $groupId

Group ID

Return Value

bool|array

Whether the group went, or the refusal when it is all that keeps an active super admin

Exceptions

GroupNotFoundException
LastZoneOwnerException

array getGroupDetails(int $groupId)

Get group details including member and zone counts

Parameters

int $groupId

Group ID

Return Value

array

Exceptions

InvalidArgumentException

bool isGroupNameAvailable(string $name, int|null $excludeGroupId = null)

Check if a group name is available

Parameters

string $name

Group name to check

int|null $excludeGroupId

Group ID to exclude from check (for updates)

Return Value

bool