src/Entity/UserPositions.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserPositionsRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. /**
  9.  * @ORM\Entity(repositoryClass=UserPositionsRepository::class)
  10.  */
  11. class UserPositions
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      * @Groups({"user.position.core"})
  18.      */
  19.     private $id;
  20.     /**
  21.      * @ORM\Column(type="string", length=64)
  22.      * @Groups({"user.position.core"})
  23.      */
  24.     private $name;
  25.     /**
  26.      * @ORM\OneToMany(targetEntity=UserPositionsGroup::class, mappedBy="user_position")
  27.      */
  28.     private $groups;
  29.     /**
  30.      * @ORM\OneToMany(targetEntity=User::class, mappedBy="user_position")
  31.      */
  32.     private $users;
  33.     public function __construct()
  34.     {
  35.         $this->groups = new ArrayCollection();
  36.         $this->users = new ArrayCollection();
  37.     }
  38.     public function getId(): ?int
  39.     {
  40.         return $this->id;
  41.     }
  42.     public function getName(): ?string
  43.     {
  44.         return $this->name;
  45.     }
  46.     public function setName(string $name): self
  47.     {
  48.         $this->name $name;
  49.         return $this;
  50.     }
  51.     /**
  52.      * @return Collection<int, UserPositionsGroup>
  53.      */
  54.     public function getGroups(): Collection
  55.     {
  56.         return $this->groups;
  57.     }
  58.     public function addUserPositionsGroup(UserPositionsGroup $userPositionsGroup): self
  59.     {
  60.         if (!$this->groups->contains($userPositionsGroup)) {
  61.             $this->groups[] = $userPositionsGroup;
  62.             $userPositionsGroup->setUserPosition($this);
  63.         }
  64.         return $this;
  65.     }
  66.     public function removeUserPositionsGroup(UserPositionsGroup $userPositionsGroup): self
  67.     {
  68.         if ($this->groups->removeElement($userPositionsGroup)) {
  69.             // set the owning side to null (unless already changed)
  70.             if ($userPositionsGroup->getUserPosition() === $this) {
  71.                 $userPositionsGroup->setUserPosition(null);
  72.             }
  73.         }
  74.         return $this;
  75.     }
  76.     /**
  77.      * @return Collection<int, User>
  78.      */
  79.     public function getUsers(): Collection
  80.     {
  81.         return $this->users;
  82.     }
  83.     public function addUser(User $user): self
  84.     {
  85.         if (!$this->users->contains($user)) {
  86.             $this->users[] = $user;
  87.             $user->setUserPosition($this);
  88.         }
  89.         return $this;
  90.     }
  91.     public function removeUser(User $user): self
  92.     {
  93.         if ($this->users->removeElement($user)) {
  94.             // set the owning side to null (unless already changed)
  95.             if ($user->getUserPosition() === $this) {
  96.                 $user->setUserPosition(null);
  97.             }
  98.         }
  99.         return $this;
  100.     }
  101. }