Course.php 11 KB

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