Support oft parent groups
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Admin\Repositories;
|
||||
|
||||
use App\Models\ParentGroup;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class AdminParentGroupRepository
|
||||
{
|
||||
/** Alle Parent Groups, alphabetisch mit „Ohne Zuordnung" am Ende, mit der Zahl zugeordneter Mandanten. */
|
||||
public function all(): Collection
|
||||
{
|
||||
return ParentGroup::withCount('tenants')
|
||||
->ordered()
|
||||
->get();
|
||||
}
|
||||
|
||||
public function findById(int $id): ?ParentGroup
|
||||
{
|
||||
return ParentGroup::find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ob die Parent Group noch verwendet wird -- von einem Mandanten oder von einer Anmeldung. Anmeldungen sind
|
||||
* mandantengebunden; gezählt wird hier bewusst über alle Mandanten hinweg.
|
||||
*/
|
||||
public function isInUse(ParentGroup $parentGroup): bool
|
||||
{
|
||||
return $parentGroup->tenants()->exists()
|
||||
|| $parentGroup->eventParticipants()->withoutGlobalScopes()->exists();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user