Course.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Booking;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use App\Entity\Access\Access;
  6. use App\Entity\Billing\ResidenceArea;
  7. use App\Entity\Core\Tagg;
  8. use App\Entity\Education\Education;
  9. use App\Entity\Education\EducationCurriculum;
  10. use App\Entity\Organization\Organization;
  11. use App\Entity\Place\Place;
  12. use App\Entity\Place\Room;
  13. use App\Entity\Product\Equipment;
  14. use App\Repository\Booking\CourseRepository;
  15. // use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
  16. use Doctrine\Common\Collections\ArrayCollection;
  17. use Doctrine\Common\Collections\Collection;
  18. use Doctrine\ORM\Mapping as ORM;
  19. /**
  20. * @todo : A la suite de la migration, il faut supprimer le nom de la table pour avoir une table Course, et supprimer l'attribut discr.
  21. * @todo : migration table tag_booking
  22. *
  23. * Classe Course qui permet de gérer les cours de la structure.
  24. *
  25. * Security :
  26. *
  27. * * @see App\Doctrine\Booking\CurrentCoursesExtension
  28. */
  29. #[ApiResource(operations: [])]
  30. // #[Auditable]
  31. #[ORM\Entity(repositoryClass: CourseRepository::class)]
  32. #[ORM\Table(name: 'Booking')]
  33. class Course extends AbstractBooking
  34. {
  35. /** @var Collection<int, CourseRecur> */
  36. #[ORM\OneToMany(targetEntity: CourseRecur::class, mappedBy: 'event', cascade: ['persist'], orphanRemoval: true)]
  37. private Collection $eventRecur;
  38. /** @var Collection<int, Course> */
  39. #[ORM\OneToMany(targetEntity: Course::class, mappedBy: 'parent', orphanRemoval: true)]
  40. private Collection $timeline;
  41. #[ORM\ManyToOne(inversedBy: 'timeline')]
  42. private ?Course $parent = null;
  43. #[ORM\ManyToOne(inversedBy: 'courses')]
  44. #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
  45. protected ?Place $place = null;
  46. #[ORM\ManyToOne(inversedBy: 'courses')]
  47. #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
  48. protected ?Room $room = null;
  49. /** @var Collection<int, Access> */
  50. #[ORM\ManyToMany(targetEntity: Access::class, inversedBy: 'practicalCourses')]
  51. #[ORM\JoinTable(name: 'booking_organizer')]
  52. #[ORM\JoinColumn(name: 'booking_id', referencedColumnName: 'id')]
  53. #[ORM\InverseJoinColumn(name: 'organizer_id', referencedColumnName: 'id')]
  54. private Collection $organizer;
  55. #[ORM\ManyToOne(inversedBy: 'courses')]
  56. #[ORM\JoinColumn(nullable: false)]
  57. protected Organization $organization;
  58. #[ORM\ManyToOne(inversedBy: 'courses')]
  59. #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
  60. private ?Education $education = null;
  61. /** @var Collection<int, EducationCurriculum> */
  62. #[ORM\ManyToMany(targetEntity: EducationCurriculum::class)]
  63. private Collection $educationCurriculum;
  64. /** @var Collection<int, Access> */
  65. #[ORM\ManyToMany(targetEntity: Access::class, inversedBy: 'courses')]
  66. #[ORM\JoinTable(name: 'course_student')]
  67. #[ORM\JoinColumn(name: 'course_id', referencedColumnName: 'id')]
  68. #[ORM\InverseJoinColumn(name: 'student_id', referencedColumnName: 'id')]
  69. private Collection $students;
  70. /** @var Collection<int, Work> */
  71. #[ORM\OneToMany(targetEntity: Work::class, mappedBy: 'course', cascade: ['persist'], orphanRemoval: true)]
  72. private Collection $work;
  73. /** @var Collection<int, Equipment> */
  74. #[ORM\ManyToMany(targetEntity: Equipment::class)]
  75. #[ORM\JoinTable(name: 'booking_equipment')]
  76. #[ORM\JoinColumn(name: 'booking_id', referencedColumnName: 'id')]
  77. #[ORM\InverseJoinColumn(name: 'equipment_id', referencedColumnName: 'id')]
  78. private Collection $equipments;
  79. /** @var Collection<int, AttendanceBooking> */
  80. #[ORM\OneToMany(targetEntity: AttendanceBooking::class, mappedBy: 'course', cascade: ['persist'], orphanRemoval: true)]
  81. #[ORM\JoinColumn(nullable: false)]
  82. private Collection $attendanceBooking;
  83. /** @var Collection<int, Tagg> */
  84. #[ORM\ManyToMany(targetEntity: Tagg::class, inversedBy: 'courses', cascade: ['persist'])]
  85. #[ORM\JoinTable(name: 'tag_booking')]
  86. #[ORM\JoinColumn(name: 'booking_id', referencedColumnName: 'id')]
  87. #[ORM\InverseJoinColumn(name: 'tag_id', referencedColumnName: 'id')]
  88. private Collection $tags;
  89. public function __construct()
  90. {
  91. $this->eventRecur = new ArrayCollection();
  92. $this->timeline = new ArrayCollection();
  93. $this->organizer = new ArrayCollection();
  94. $this->educationCurriculum = new ArrayCollection();
  95. $this->students = new ArrayCollection();
  96. $this->work = new ArrayCollection();
  97. $this->equipments = new ArrayCollection();
  98. $this->attendanceBooking = new ArrayCollection();
  99. $this->tags = new ArrayCollection();
  100. }
  101. /**
  102. * @return Collection<int, CourseRecur>
  103. */
  104. public function getEventRecur(): Collection
  105. {
  106. return $this->eventRecur;
  107. }
  108. public function addEventRecur(CourseRecur $eventRecur): self
  109. {
  110. if (!$this->eventRecur->contains($eventRecur)) {
  111. $this->eventRecur[] = $eventRecur;
  112. $eventRecur->setEvent($this);
  113. }
  114. return $this;
  115. }
  116. public function removeEventRecur(CourseRecur $eventRecur): self
  117. {
  118. if ($this->eventRecur->removeElement($eventRecur)) {
  119. // set the owning side to null (unless already changed)
  120. if ($eventRecur->getEvent() === $this) {
  121. $eventRecur->setEvent(null);
  122. }
  123. }
  124. return $this;
  125. }
  126. /**
  127. * @return Collection<int, Course>
  128. */
  129. public function getTimeline(): Collection
  130. {
  131. return $this->timeline;
  132. }
  133. public function addTimeline(Course $timeline): self
  134. {
  135. if (!$this->timeline->contains($timeline)) {
  136. $this->timeline[] = $timeline;
  137. $timeline->setParent($this);
  138. }
  139. return $this;
  140. }
  141. public function removeTimeline(Course $timeline): self
  142. {
  143. if ($this->timeline->removeElement($timeline)) {
  144. // set the owning side to null (unless already changed)
  145. if ($timeline->getParent() === $this) {
  146. $timeline->setParent(null);
  147. }
  148. }
  149. return $this;
  150. }
  151. public function getParent(): ?self
  152. {
  153. return $this->parent;
  154. }
  155. public function setParent(?self $parent): self
  156. {
  157. $this->parent = $parent;
  158. return $this;
  159. }
  160. public function getPlace(): ?Place
  161. {
  162. return $this->place;
  163. }
  164. public function setPlace(?Place $place): self
  165. {
  166. $this->place = $place;
  167. return $this;
  168. }
  169. public function getRoom(): ?Room
  170. {
  171. return $this->room;
  172. }
  173. public function setRoom(?Room $room): self
  174. {
  175. $this->room = $room;
  176. return $this;
  177. }
  178. /**
  179. * @return Collection<int, Access>
  180. */
  181. public function getOrganizer(): Collection
  182. {
  183. return $this->organizer;
  184. }
  185. public function addOrganizer(Access $organizer): self
  186. {
  187. if (!$this->organizer->contains($organizer)) {
  188. $this->organizer[] = $organizer;
  189. }
  190. return $this;
  191. }
  192. public function removeOrganizer(Access $organizer): self
  193. {
  194. $this->organizer->removeElement($organizer);
  195. return $this;
  196. }
  197. public function getOrganization(): ?Organization
  198. {
  199. return $this->organization;
  200. }
  201. public function setOrganization(?Organization $organization): self
  202. {
  203. $this->organization = $organization;
  204. return $this;
  205. }
  206. public function getEducation(): ?Education
  207. {
  208. return $this->education;
  209. }
  210. public function setEducation(?Education $education): self
  211. {
  212. $this->education = $education;
  213. return $this;
  214. }
  215. /**
  216. * @return Collection<int, EducationCurriculum>
  217. */
  218. public function getEducationCurriculum(): Collection
  219. {
  220. return $this->educationCurriculum;
  221. }
  222. public function addEducationCurriculum(EducationCurriculum $educationCurriculum): self
  223. {
  224. if (!$this->educationCurriculum->contains($educationCurriculum)) {
  225. $this->educationCurriculum[] = $educationCurriculum;
  226. }
  227. return $this;
  228. }
  229. public function removeEducationCurriculum(EducationCurriculum $educationCurriculum): self
  230. {
  231. $this->educationCurriculum->removeElement($educationCurriculum);
  232. return $this;
  233. }
  234. /**
  235. * @return Collection<int, Access>
  236. */
  237. public function getStudents(): Collection
  238. {
  239. return $this->students;
  240. }
  241. public function addStudent(Access $student): self
  242. {
  243. if (!$this->students->contains($student)) {
  244. $this->students[] = $student;
  245. }
  246. return $this;
  247. }
  248. public function removeStudent(Access $student): self
  249. {
  250. $this->students->removeElement($student);
  251. return $this;
  252. }
  253. /**
  254. * @return Collection<int, Work>
  255. */
  256. public function getWork(): Collection
  257. {
  258. return $this->work;
  259. }
  260. public function addWork(Work $work): self
  261. {
  262. if (!$this->work->contains($work)) {
  263. $this->work[] = $work;
  264. $work->setCourse($this);
  265. }
  266. return $this;
  267. }
  268. public function removeWork(Work $work): self
  269. {
  270. if ($this->work->removeElement($work)) {
  271. // set the owning side to null (unless already changed)
  272. if ($work->getCourse() === $this) {
  273. $work->setCourse(null);
  274. }
  275. }
  276. return $this;
  277. }
  278. /**
  279. * @return Collection<int, Equipment>
  280. */
  281. public function getEquipments(): Collection
  282. {
  283. return $this->equipments;
  284. }
  285. public function addEquipment(Equipment $equipment): self
  286. {
  287. if (!$this->equipments->contains($equipment)) {
  288. $this->equipments[] = $equipment;
  289. }
  290. return $this;
  291. }
  292. public function removeEquipment(Equipment $equipment): self
  293. {
  294. $this->equipments->removeElement($equipment);
  295. return $this;
  296. }
  297. /**
  298. * @return Collection<int, AttendanceBooking>
  299. */
  300. public function getAttendanceBooking(): Collection
  301. {
  302. return $this->attendanceBooking;
  303. }
  304. public function addAttendanceBooking(AttendanceBooking $attendanceBooking): self
  305. {
  306. if (!$this->attendanceBooking->contains($attendanceBooking)) {
  307. $this->attendanceBooking[] = $attendanceBooking;
  308. $attendanceBooking->setCourse($this);
  309. }
  310. return $this;
  311. }
  312. public function removeAttendanceBooking(AttendanceBooking $attendanceBooking): self
  313. {
  314. if ($this->attendanceBooking->removeElement($attendanceBooking)) {
  315. // set the owning side to null (unless already changed)
  316. if ($attendanceBooking->getCourse() === $this) {
  317. $attendanceBooking->setCourse(null);
  318. }
  319. }
  320. return $this;
  321. }
  322. /**
  323. * @return Collection<int, Tagg>
  324. */
  325. public function getTags(): Collection
  326. {
  327. return $this->tags;
  328. }
  329. public function addTag(Tagg $tag): self
  330. {
  331. if (!$this->tags->contains($tag)) {
  332. $this->tags[] = $tag;
  333. }
  334. return $this;
  335. }
  336. public function removeTag(Tagg $tag): self
  337. {
  338. $this->tags->removeElement($tag);
  339. return $this;
  340. }
  341. }