Admin CRUD for user groups

This commit is contained in:
2024-09-27 11:54:23 +02:00
parent 2e71808be1
commit debca1f474
13 changed files with 309 additions and 5 deletions

View File

@@ -13,6 +13,10 @@ namespace Chill\MainBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\Order;
use Doctrine\Common\Collections\ReadableCollection;
use Doctrine\Common\Collections\Selectable;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
@@ -31,11 +35,11 @@ class UserGroup
private array $label = [];
/**
* @var \Doctrine\Common\Collections\Collection<int, \Chill\MainBundle\Entity\User>
* @var Collection<int, User>&Selectable<int, User>
*/
#[ORM\ManyToMany(targetEntity: User::class)]
#[ORM\JoinTable(name: 'chill_main_user_group_user')]
private Collection $users;
private Collection&Selectable $users;
/**
* @var Collection<int, User>&Selectable<int, User>
@@ -61,6 +65,7 @@ class UserGroup
public function __construct()
{
$this->adminUsers = new \Doctrine\Common\Collections\ArrayCollection();
$this->users = new ArrayCollection();
}
@@ -72,6 +77,7 @@ class UserGroup
public function setActive(bool $active): self
{
$this->active = $active;
return $this;
}
@@ -119,7 +125,10 @@ class UserGroup
return $this->label;
}
public function getUsers(): Collection
/**
* @return Selectable<int, User>&Collection<int, User>
*/
public function getUsers(): Collection&Selectable
{
return $this->users;
}
@@ -191,4 +200,20 @@ class UserGroup
{
return $this->users->contains($user);
}
public function getUserListByLabelAscending(): ReadableCollection
{
$criteria = Criteria::create();
$criteria->orderBy(['label' => Order::Ascending]);
return $this->getUsers()->matching($criteria);
}
public function getAdminUserListByLabelAscending(): ReadableCollection
{
$criteria = Criteria::create();
$criteria->orderBy(['label' => Order::Ascending]);
return $this->getAdminUsers()->matching($criteria);
}
}