<?phpnamespace App\AtechNet\CoreBundle\Entity;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping\Column;use Doctrine\ORM\Mapping\Entity;use Doctrine\ORM\Mapping\JoinColumn;use Doctrine\ORM\Mapping\JoinTable;use Doctrine\ORM\Mapping\ManyToMany;use Doctrine\ORM\Mapping\Table as Table;/** * UserDepartment * * @Table(name="user_department") * @Entity */class UserDepartment extends AbstractSignedEntity{ public const int DEPARTMENT_SERVICE_ID = 18; public const int DEPARTMENT_STOCK_MANAGEMENT_ID = 22; /** * @var string * * @Column(name="title", type="string", length=255) */ private $title; /** * @var ArrayCollection * * @ManyToMany(targetEntity="User", inversedBy="managedDepartments") * @JoinTable( * name="users_department_leader", * joinColumns={ * @JoinColumn(name="department_id", referencedColumnName="id") * }, * inverseJoinColumns={ * @JoinColumn(name="user_id", referencedColumnName="id") * }) */ private $teamLeaders; /** * @var ArrayCollection * * @ManyToMany(targetEntity="User", mappedBy="departments") **/ private $users; public function __construct() { parent::__construct(); $this->users = new ArrayCollection(); $this->teamLeaders = new ArrayCollection(); } /** * @param string $title * @return $this */ public function setTitle(string $title): UserDepartment { $this->title = $title; return $this; } /** * @return string */ public function getTitle(): string { return $this->title; } /** * @param User $user * @return $this */ public function addUser(User $user): UserDepartment { $this->users[] = $user; return $this; } /** * @param User $user * @return bool */ public function removeUser(User $user): bool { return $this->users->removeElement($user); } /** * @return ArrayCollection */ public function getUsers(): ArrayCollection { return $this->users; } /** * Get Team Leaders of Department * * @return ArrayCollection */ public function getTeamLeaders(): Collection { return $this->teamLeaders; } /** * Add a Team Leader * * @param User $teamLeader */ public function addTeamLeader(User $teamLeader): void { if (!$this->teamLeaders->contains($teamLeader)) { $this->teamLeaders->add($teamLeader); } } /** * Remove a Team Leader * * @param User $teamLeader */ public function removeTeamLeader(User $teamLeader): void { if ($this->teamLeaders->contains($teamLeader)) { $this->teamLeaders->removeElement($teamLeader); } } /** * Clear Team Leaders */ public function clearTeamLeaders(): void { $this->teamLeaders->clear(); }}