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({
  18.      *     "user.position.core",
  19.      *     "user_position@core"
  20.      * })
  21.      */
  22.     private $id;
  23.     /**
  24.      * @ORM\Column(type="string", length=64)
  25.      * @Groups({
  26.      *      "user.position.core",
  27.      *      "user_position@core"
  28.      *  })
  29.      */
  30.     private $name;
  31.     /**
  32.      * @ORM\OneToMany(targetEntity=UserPositionsGroup::class, mappedBy="user_position")
  33.      */
  34.     private $groups;
  35.     /**
  36.      * @ORM\OneToMany(targetEntity=User::class, mappedBy="user_position")
  37.      */
  38.     private $users;
  39.     public function __construct()
  40.     {
  41.         $this->groups = new ArrayCollection();
  42.         $this->users = new ArrayCollection();
  43.     }
  44.     public function getId(): ?int
  45.     {
  46.         return $this->id;
  47.     }
  48.     public function getName(): ?string
  49.     {
  50.         return $this->name;
  51.     }
  52.     public function setName(string $name): self
  53.     {
  54.         $this->name $name;
  55.         return $this;
  56.     }
  57.     /**
  58.      * @return Collection<int, UserPositionsGroup>
  59.      */
  60.     public function getGroups(): Collection
  61.     {
  62.         return $this->groups;
  63.     }
  64.     public function addUserPositionsGroup(UserPositionsGroup $userPositionsGroup): self
  65.     {
  66.         if (!$this->groups->contains($userPositionsGroup)) {
  67.             $this->groups[] = $userPositionsGroup;
  68.             $userPositionsGroup->setUserPosition($this);
  69.         }
  70.         return $this;
  71.     }
  72.     public function removeUserPositionsGroup(UserPositionsGroup $userPositionsGroup): self
  73.     {
  74.         if ($this->groups->removeElement($userPositionsGroup)) {
  75.             // set the owning side to null (unless already changed)
  76.             if ($userPositionsGroup->getUserPosition() === $this) {
  77.                 $userPositionsGroup->setUserPosition(null);
  78.             }
  79.         }
  80.         return $this;
  81.     }
  82.     /**
  83.      * @return Collection<int, User>
  84.      */
  85.     public function getUsers(): Collection
  86.     {
  87.         return $this->users;
  88.     }
  89.     public function addUser(User $user): self
  90.     {
  91.         if (!$this->users->contains($user)) {
  92.             $this->users[] = $user;
  93.             $user->setUserPosition($this);
  94.         }
  95.         return $this;
  96.     }
  97.     public function removeUser(User $user): self
  98.     {
  99.         if ($this->users->removeElement($user)) {
  100.             // set the owning side to null (unless already changed)
  101.             if ($user->getUserPosition() === $this) {
  102.                 $user->setUserPosition(null);
  103.             }
  104.         }
  105.         return $this;
  106.     }
  107. }