src/Entity/GroupUser.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\GroupUserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=GroupUserRepository::class)
  9.  */
  10. class GroupUser
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=255)
  20.      */
  21.     private $name;
  22.     /**
  23.      * @ORM\Column(type="string", length=255)
  24.      */
  25.     private $code;
  26.     /**
  27.      * @ORM\ManyToMany(targetEntity=Right::class, mappedBy="groups")
  28.      */
  29.     private $rights;
  30.     /**
  31.      * @ORM\OneToMany(targetEntity=User::class, mappedBy="groupUser")
  32.      */
  33.     private $users;
  34.     public function __construct()
  35.     {
  36.         $this->rights = new ArrayCollection();
  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 getCode(): ?string
  53.     {
  54.         return $this->code;
  55.     }
  56.     public function setCode(string $code): self
  57.     {
  58.         $this->code $code;
  59.         return $this;
  60.     }
  61.     /**
  62.      * @return Collection|Right[]
  63.      */
  64.     public function getRights(): Collection
  65.     {
  66.         return $this->rights;
  67.     }
  68.     public function addRight(Right $right): self
  69.     {
  70.         if (!$this->rights->contains($right)) {
  71.             $this->rights[] = $right;
  72.             $right->addGroup($this);
  73.         }
  74.         return $this;
  75.     }
  76.     public function removeRight(Right $right): self
  77.     {
  78.         if ($this->rights->removeElement($right)) {
  79.             $right->removeGroup($this);
  80.         }
  81.         return $this;
  82.     }
  83.     /**
  84.      * @return Collection|User[]
  85.      */
  86.     public function getUsers(): Collection
  87.     {
  88.         return $this->users;
  89.     }
  90.     public function addUser(User $user): self
  91.     {
  92.         if (!$this->users->contains($user)) {
  93.             $this->users[] = $user;
  94.             $user->setGroupUser($this);
  95.         }
  96.         return $this;
  97.     }
  98.     public function removeUser(User $user): self
  99.     {
  100.         if ($this->users->removeElement($user)) {
  101.             // set the owning side to null (unless already changed)
  102.             if ($user->getGroupUser() === $this) {
  103.                 $user->setGroupUser(null);
  104.             }
  105.         }
  106.         return $this;
  107.     }
  108. }