src/AtechNet/CoreBundle/Entity/UserDepartment.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\AtechNet\CoreBundle\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping\Column;
  6. use Doctrine\ORM\Mapping\Entity;
  7. use Doctrine\ORM\Mapping\JoinColumn;
  8. use Doctrine\ORM\Mapping\JoinTable;
  9. use Doctrine\ORM\Mapping\ManyToMany;
  10. use Doctrine\ORM\Mapping\Table as Table;
  11. /**
  12.  * UserDepartment
  13.  *
  14.  * @Table(name="user_department")
  15.  * @Entity
  16.  */
  17. class UserDepartment extends AbstractSignedEntity
  18. {
  19.     public const int DEPARTMENT_SERVICE_ID = 18;
  20.     public const int DEPARTMENT_STOCK_MANAGEMENT_ID = 22;
  21.     /**
  22.      * @var string
  23.      *
  24.      * @Column(name="title", type="string", length=255)
  25.      */
  26.     private $title;
  27.     /**
  28.      * @var ArrayCollection
  29.      *
  30.      * @ManyToMany(targetEntity="User", inversedBy="managedDepartments")
  31.      * @JoinTable(
  32.      *  name="users_department_leader",
  33.      *  joinColumns={
  34.      *      @JoinColumn(name="department_id", referencedColumnName="id")
  35.      *  },
  36.      *  inverseJoinColumns={
  37.      *      @JoinColumn(name="user_id", referencedColumnName="id")
  38.      *  })
  39.      */
  40.     private $teamLeaders;
  41.     /**
  42.      * @var ArrayCollection
  43.      *
  44.      * @ManyToMany(targetEntity="User", mappedBy="departments")
  45.      **/
  46.     private $users;
  47.     public function __construct()
  48.     {
  49.         parent::__construct();
  50.         $this->users = new ArrayCollection();
  51.         $this->teamLeaders = new ArrayCollection();
  52.     }
  53.     /**
  54.      * @param string $title
  55.      * @return $this
  56.      */
  57.     public function setTitle(string $title): UserDepartment
  58.     {
  59.         $this->title = $title;
  60.         return $this;
  61.     }
  62.     /**
  63.      * @return string
  64.      */
  65.     public function getTitle(): string
  66.     {
  67.         return $this->title;
  68.     }
  69.     /**
  70.      * @param User $user
  71.      * @return $this
  72.      */
  73.     public function addUser(User $user): UserDepartment
  74.     {
  75.         $this->users[] = $user;
  76.         return $this;
  77.     }
  78.     /**
  79.      * @param User $user
  80.      * @return bool
  81.      */
  82.     public function removeUser(User $user): bool
  83.     {
  84.         return $this->users->removeElement($user);
  85.     }
  86.     /**
  87.      * @return ArrayCollection
  88.      */
  89.     public function getUsers(): ArrayCollection
  90.     {
  91.         return $this->users;
  92.     }
  93.     /**
  94.      * Get Team Leaders of Department
  95.      *
  96.      * @return ArrayCollection
  97.      */
  98.     public function getTeamLeaders(): Collection
  99.     {
  100.         return $this->teamLeaders;
  101.     }
  102.     /**
  103.      * Add a Team Leader
  104.      *
  105.      * @param User $teamLeader
  106.      */
  107.     public function addTeamLeader(User $teamLeader): void
  108.     {
  109.         if (!$this->teamLeaders->contains($teamLeader)) {
  110.             $this->teamLeaders->add($teamLeader);
  111.         }
  112.     }
  113.     /**
  114.      * Remove a Team Leader
  115.      *
  116.      * @param User $teamLeader
  117.      */
  118.     public function removeTeamLeader(User $teamLeader): void
  119.     {
  120.         if ($this->teamLeaders->contains($teamLeader)) {
  121.             $this->teamLeaders->removeElement($teamLeader);
  122.         }
  123.     }
  124.     /**
  125.      * Clear Team Leaders
  126.      */
  127.     public function clearTeamLeaders(): void
  128.     {
  129.         $this->teamLeaders->clear();
  130.     }
  131. }