src/Entity/Job.php line 23

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