src/Entity/Office.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\OfficeRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use JMS\Serializer\Annotation as Serializer;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. /**
  10. * @ORM\Table(indexes={ @ORM\Index(name="idx_office_module_id", columns={"module_id"}), @ORM\Index(name="idx_office_program_id", columns={"program_id"}) })
  11. * @ORM\Entity(repositoryClass=OfficeRepository::class)
  12. * @Serializer\ExclusionPolicy("ALL")
  13. * @UniqueEntity(
  14. * fields={"name"},
  15. * errorPath="name",
  16. * message="Une fonction existe avec le même nom"
  17. * )
  18. */
  19. class Office extends BaseEntity
  20. {
  21. /**
  22. * @ORM\Id
  23. * @ORM\GeneratedValue
  24. * @ORM\Column(type="integer")
  25. * @Serializer\Expose
  26. * @Serializer\Groups({"office", "user_profile"})
  27. */
  28. private $id;
  29. /**
  30. * @ORM\Column(type="string", length=255)
  31. * @Serializer\Expose
  32. * @Serializer\Groups({"office", "user_profile"})
  33. */
  34. private $name;
  35. /**
  36. * @ORM\OneToMany(targetEntity=UserOffice::class, mappedBy="office", fetch="EXTRA_LAZY")
  37. */
  38. private $userOffices;
  39. /**
  40. * @ORM\ManyToMany(targetEntity=Job::class, mappedBy="offices")
  41. */
  42. private $jobs;
  43. /**
  44. * @ORM\ManyToOne(targetEntity=Module::class, inversedBy="offices")
  45. * @ORM\JoinColumn(name="module_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
  46. */
  47. private $module;
  48. /**
  49. * @ORM\ManyToOne(targetEntity=Program::class, inversedBy="offices")
  50. * @ORM\JoinColumn(name="program_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
  51. */
  52. private $program;
  53. /**
  54. * @ORM\ManyToOne(targetEntity=Live::class, inversedBy="offices")
  55. */
  56. private $live;
  57. /**
  58. * @ORM\OneToMany(targetEntity=User::class, mappedBy="office", fetch="EXTRA_LAZY")
  59. */
  60. private $users;
  61. /**
  62. * @ORM\ManyToMany(targetEntity=SubsidiaryCompany::class, mappedBy="offices")
  63. */
  64. private $subsidiaryCompanies;
  65. /**
  66. * @ORM\OneToMany(targetEntity=Target::class, mappedBy="office", fetch="EXTRA_LAZY")
  67. */
  68. private $targets;
  69. public function __construct()
  70. {
  71. $this->userOffices = new ArrayCollection();
  72. $this->jobs = new ArrayCollection();
  73. $this->users = new ArrayCollection();
  74. $this->targets = new ArrayCollection();
  75. }
  76. public function getId(): ?int
  77. {
  78. return $this->id;
  79. }
  80. public function getName(): ?string
  81. {
  82. return $this->name;
  83. }
  84. public function setName(string $name): self
  85. {
  86. $this->name = $name;
  87. return $this;
  88. }
  89. /**
  90. * @return Collection<int, UserOffice>
  91. */
  92. public function getUserOffices(): Collection
  93. {
  94. return $this->userOffices;
  95. }
  96. public function addUserOffice(UserOffice $userOffice): self
  97. {
  98. if (!$this->userOffices->contains($userOffice)) {
  99. $this->userOffices[] = $userOffice;
  100. $userOffice->setOffice($this);
  101. }
  102. return $this;
  103. }
  104. public function removeUserOffice(UserOffice $userOffice): self
  105. {
  106. if ($this->userOffices->removeElement($userOffice)) {
  107. // set the owning side to null (unless already changed)
  108. if ($userOffice->getOffice() === $this) {
  109. $userOffice->setOffice(null);
  110. }
  111. }
  112. return $this;
  113. }
  114. /**
  115. * @return Collection<int, Job>
  116. */
  117. public function getJobs(): Collection
  118. {
  119. return $this->jobs;
  120. }
  121. public function addJob(Job $job): self
  122. {
  123. if (!$this->jobs->contains($job)) {
  124. $this->jobs[] = $job;
  125. $job->addOffice($this);
  126. }
  127. return $this;
  128. }
  129. public function removeJob(Job $job): self
  130. {
  131. if ($this->jobs->removeElement($job)) {
  132. $job->removeOffice($this);
  133. }
  134. return $this;
  135. }
  136. public function getModule(): ?Module
  137. {
  138. return $this->module;
  139. }
  140. public function setModule(?Module $module): self
  141. {
  142. $this->module = $module;
  143. return $this;
  144. }
  145. public function getProgram(): ?Program
  146. {
  147. return $this->program;
  148. }
  149. public function setProgram(?Program $program): self
  150. {
  151. $this->program = $program;
  152. return $this;
  153. }
  154. public function getLive(): ?Live
  155. {
  156. return $this->live;
  157. }
  158. public function setLive(?Live $live): self
  159. {
  160. $this->live = $live;
  161. return $this;
  162. }
  163. /**
  164. * @return Collection<int, User>
  165. */
  166. public function getUsers(): Collection
  167. {
  168. return $this->users;
  169. }
  170. public function addUser(User $user): self
  171. {
  172. if (!$this->users->contains($user)) {
  173. $this->users[] = $user;
  174. $user->setOffice($this);
  175. }
  176. return $this;
  177. }
  178. public function removeUser(User $user): self
  179. {
  180. if ($this->users->removeElement($user)) {
  181. // set the owning side to null (unless already changed)
  182. if ($user->getOffice() === $this) {
  183. $user->setOffice(null);
  184. }
  185. }
  186. return $this;
  187. }
  188. /**
  189. * @return Collection<int, SubsidiaryCompany>
  190. */
  191. public function getSubsidiaryCompanies(): Collection
  192. {
  193. return $this->subsidiaryCompanies;
  194. }
  195. public function addSubsidiaryCompany(SubsidiaryCompany $subsidiaryCompany): self
  196. {
  197. if (!$this->subsidiaryCompanies->contains($subsidiaryCompany)) {
  198. $this->subsidiaryCompanies[] = $subsidiaryCompany;
  199. $subsidiaryCompany->addOffice($this);
  200. }
  201. return $this;
  202. }
  203. public function removeSubsidiaryCompany(SubsidiaryCompany $subsidiaryCompany): self
  204. {
  205. if ($this->subsidiaryCompanies->removeElement($subsidiaryCompany)) {
  206. $subsidiaryCompany->removeOffice($this);
  207. }
  208. return $this;
  209. }
  210. /**
  211. * @return Collection<int, Target>
  212. */
  213. public function getTarges(): Collection
  214. {
  215. return $this->targets;
  216. }
  217. public function addTarget(Target $target): self
  218. {
  219. if (!$this->targets->contains($target)) {
  220. $this->targets[] = $target;
  221. $target->setOffice($this);
  222. }
  223. return $this;
  224. }
  225. public function removeTarget(Target $target): self
  226. {
  227. if ($this->targets->removeElement($target)) {
  228. // set the owning side to null (unless already changed)
  229. if ($target->getOffice() === $this) {
  230. $target->setOffice(null);
  231. }
  232. }
  233. return $this;
  234. }
  235. }