Expand models, user groups need more properties.

This commit is contained in:
James Cole
2024-04-01 14:04:22 +02:00
parent b537a3145d
commit 80f410835b
9 changed files with 57 additions and 24 deletions

View File

@@ -392,4 +392,28 @@ class UserRepository implements UserRepositoryInterface
return null !== $invitee;
}
#[\Override]
public function getUserGroups(User $user): Collection
{
$memberships = $user->groupMemberships()->get();
$set = [];
$collection = new Collection();
/** @var GroupMembership $membership */
foreach ($memberships as $membership) {
/** @var null|UserGroup $group */
$group = $membership->userGroup()->first();
if (null !== $group) {
$groupId = (int)$group->id;
if (in_array($groupId, $set, true)) {
continue;
}
$set[$groupId] = $group;
}
}
$collection->push(...$set);
return $collection;
}
}