src/Entity/UserGroup.php line 23

  1. <?php
  2. namespace App\Entity;
  3. use App\Annotations\HideFromView;
  4. use App\Trait\EntityTrait;
  5. use App\Repository\UserGroupRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\DBAL\Types\Types;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use ApiPlatform\Action\NotFoundAction;
  11. use ApiPlatform\Metadata\Get;
  12. use ApiPlatform\Metadata\GetCollection;
  13. use ApiPlatform\Metadata\ApiResource;
  14. use Symfony\Component\Serializer\Annotation\Ignore;
  15. use Symfony\Component\Serializer\Annotation\MaxDepth;
  16. #[ApiResource(
  17.     normalizationContext: ['enable_max_depth'=>true],
  18. )]
  19. #[ORM\Entity(repositoryClassUserGroupRepository::class)]
  20. class UserGroup
  21. {
  22.     use EntityTrait;
  23.     #[ORM\Id]
  24.     #[ORM\GeneratedValue]
  25.     #[ORM\Column]
  26.     private ?int $id null;
  27.     #[ORM\Column(length128)]
  28.     private ?string $name null;
  29.     #[ORM\Column]
  30.     private array $roles = [];
  31.     #[HideFromView]
  32.     #[MaxDepth(1)]
  33.     #[ORM\ManyToMany(targetEntityUser::class, inversedBy'userGroups')]
  34.     private Collection $users;
  35.     public function __construct()
  36.     {
  37.         $this->users = new ArrayCollection();
  38.     }
  39.     public function getId(): ?int
  40.     {
  41.         return $this->id;
  42.     }
  43.     public function getName(): ?string
  44.     {
  45.         return $this->name;
  46.     }
  47.     public function setName(string $name): self
  48.     {
  49.         $this->name $name;
  50.         return $this;
  51.     }
  52.     public function getRoles(): array
  53.     {
  54.         return $this->roles;
  55.     }
  56.     public function setRoles(array $roles): self
  57.     {
  58.         $this->roles $roles;
  59.         return $this;
  60.     }
  61.     /**
  62.      * @return Collection<int, User>
  63.      */
  64.     public function getUsers(): Collection
  65.     {
  66.         return $this->users;
  67.     }
  68.     public function addUser(User $user): self
  69.     {
  70.         if (!$this->users->contains($user)) {
  71.             $this->users->add($user);
  72.         }
  73.         return $this;
  74.     }
  75.     public function removeUser(User $user): self
  76.     {
  77.         $this->users->removeElement($user);
  78.         return $this;
  79.     }
  80.     public function __toString()
  81.     {
  82.         return $this->name;
  83.     }
  84. }