mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-04 07:56:12 +00:00
79 lines
1.9 KiB
PHP
79 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/*
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Chill\MainBundle\Entity;
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Serializer\Annotation as Serializer;
|
|
|
|
#[ORM\Entity]
|
|
#[ORM\Table(name: 'chill_main_user_group')]
|
|
#[Serializer\DiscriminatorMap(typeProperty: 'type', mapping: ['user_group' => UserGroup::class])]
|
|
class UserGroup
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::INTEGER, nullable: false)]
|
|
#[Serializer\Groups(['read'])]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::JSON, nullable: false, options: ['default' => '[]'])]
|
|
#[Serializer\Groups(['read'])]
|
|
private array $label = [];
|
|
|
|
/**
|
|
* @var \Doctrine\Common\Collections\Collection<int, \Chill\MainBundle\Entity\User>
|
|
*/
|
|
#[ORM\ManyToMany(targetEntity: User::class)]
|
|
#[ORM\JoinTable(name: 'chill_main_user_group_user')]
|
|
private Collection $users;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->users = new ArrayCollection();
|
|
}
|
|
|
|
public function addUser(User $user): self
|
|
{
|
|
if (!$this->users->contains($user)) {
|
|
$this->users[] = $user;
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeUser(User $user): self
|
|
{
|
|
if ($this->users->contains($user)) {
|
|
$this->users->removeElement($user);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getLabel(): array
|
|
{
|
|
return $this->label;
|
|
}
|
|
|
|
public function getUsers(): Collection
|
|
{
|
|
return $this->users;
|
|
}
|
|
}
|