Event.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Booking;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Entity\Access\Access;
  6. use App\Entity\Core\Categories;
  7. use App\Entity\Core\File;
  8. use App\Entity\Core\Tagg;
  9. use App\Entity\Organization\Organization;
  10. use App\Entity\Place\Place;
  11. use App\Entity\Place\PlaceSystem;
  12. use App\Entity\Place\Room;
  13. use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
  14. use Doctrine\Common\Collections\ArrayCollection;
  15. use Doctrine\Common\Collections\Collection;
  16. use Doctrine\ORM\Mapping as ORM;
  17. use Symfony\Component\Validator\Constraints as Assert;
  18. /**
  19. * @todo : A la suite de la migration, il faut supprimer le nom de la table pour avoir une table Event, et supprimer l'attribut discr.
  20. * @todo : migration table tag_booking
  21. */
  22. #[Auditable]
  23. #[ORM\Entity]
  24. #[ORM\Table(name: 'Booking')]
  25. #[ApiResource(
  26. collectionOperations:[],
  27. itemOperations: [
  28. "get" => ["security" => "is_granted('ROLE_ADMIN') and object.getOrganization().getId() == user.getOrganization().getId()"]
  29. ]
  30. )]
  31. class Event extends AbstractBooking
  32. {
  33. #[ORM\Column(length: 255, nullable: false)]
  34. private string $discr = 'event';
  35. #[ORM\ManyToOne(inversedBy: 'events')]
  36. #[ORM\JoinColumn(nullable: false)]
  37. protected Organization $organization;
  38. #[ORM\ManyToOne(inversedBy: 'events')]
  39. #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
  40. protected Place $place;
  41. #[ORM\ManyToOne(inversedBy: 'events')]
  42. #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
  43. protected Room $room;
  44. #[ORM\OneToMany(mappedBy: 'event', targetEntity: EventRecur::class, cascade: ['persist'], orphanRemoval: true)]
  45. private Collection $eventRecur;
  46. #[ORM\OneToMany(mappedBy: 'parent', targetEntity: Event::class, orphanRemoval: true)]
  47. private Collection $timeline;
  48. #[ORM\ManyToOne(inversedBy: 'timeline')]
  49. private Event $parent;
  50. #[Assert\Valid]
  51. #[ORM\ManyToOne(cascade: ['persist'],inversedBy: 'events')]
  52. #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
  53. private File $image;
  54. #[ORM\ManyToOne]
  55. private EventGender $gender;
  56. #[Assert\Valid]
  57. #[ORM\OneToMany(mappedBy: 'event', targetEntity: EventUser::class, cascade: ['persist'], orphanRemoval: true)]
  58. private Collection $eventUser;
  59. #[ORM\ManyToMany(targetEntity: Categories::class, cascade: ['persist'])]
  60. private Collection $categories;
  61. #[ORM\OneToMany(mappedBy: 'event', targetEntity: EventReport::class, orphanRemoval: true)]
  62. private Collection $eventReports;
  63. #[ORM\ManyToMany(targetEntity: File::class, cascade: ['persist'], orphanRemoval: true)]
  64. #[ORM\JoinTable(name: 'event_files')]
  65. #[ORM\JoinColumn(name: 'event_id', referencedColumnName: 'id', onDelete: 'cascade')]
  66. #[ORM\InverseJoinColumn(name: 'file_id', referencedColumnName: 'id', onDelete: 'cascade')]
  67. private Collection $files;
  68. #[ORM\ManyToOne]
  69. #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
  70. private PlaceSystem $placeSystem;
  71. #[ORM\OneToMany(mappedBy: 'event', targetEntity: AttendanceBooking::class, cascade: ['persist'], orphanRemoval: true)]
  72. #[ORM\JoinColumn(nullable: false)]
  73. private Collection $attendanceBooking;
  74. #[ORM\ManyToMany(targetEntity: Access::class, inversedBy: 'eventOrganizers')]
  75. #[ORM\JoinTable(name: 'booking_organizer')]
  76. #[ORM\JoinColumn(name: 'booking_id', referencedColumnName: 'id')]
  77. #[ORM\InverseJoinColumn(name: 'organizer_id', referencedColumnName: 'id')]
  78. private Collection $organizer;
  79. #[ORM\ManyToMany(targetEntity: Tagg::class, inversedBy: 'events', cascade: ['persist'],)]
  80. #[ORM\JoinTable(name: 'tag_booking')]
  81. #[ORM\JoinColumn(name: 'booking_id', referencedColumnName: 'id')]
  82. #[ORM\InverseJoinColumn(name: 'tag_id', referencedColumnName: 'id')]
  83. private Collection $tags;
  84. public function __construct()
  85. {
  86. $this->eventRecur = new ArrayCollection();
  87. $this->timeline = new ArrayCollection();
  88. $this->eventUser = new ArrayCollection();
  89. $this->categories = new ArrayCollection();
  90. $this->eventReports = new ArrayCollection();
  91. $this->files = new ArrayCollection();
  92. $this->attendanceBooking = new ArrayCollection();
  93. $this->organizer = new ArrayCollection();
  94. $this->tags = new ArrayCollection();
  95. }
  96. public function getDiscr(): ?string
  97. {
  98. return $this->discr;
  99. }
  100. public function setDiscr(string $discr): self
  101. {
  102. $this->discr = $discr;
  103. return $this;
  104. }
  105. public function getOrganization(): ?Organization
  106. {
  107. return $this->organization;
  108. }
  109. public function setOrganization(?Organization $organization): self
  110. {
  111. $this->organization = $organization;
  112. return $this;
  113. }
  114. public function getPlace(): ?Place
  115. {
  116. return $this->place;
  117. }
  118. public function setPlace(?Place $place): self
  119. {
  120. $this->place = $place;
  121. return $this;
  122. }
  123. public function getRoom(): ?Room
  124. {
  125. return $this->room;
  126. }
  127. public function setRoom(?Room $room): self
  128. {
  129. $this->room = $room;
  130. return $this;
  131. }
  132. /**
  133. * @return Collection<int, EventRecur>
  134. */
  135. public function getEventRecur(): Collection
  136. {
  137. return $this->eventRecur;
  138. }
  139. public function addEventRecur(EventRecur $eventRecur): self
  140. {
  141. if (!$this->eventRecur->contains($eventRecur)) {
  142. $this->eventRecur[] = $eventRecur;
  143. $eventRecur->setEvent($this);
  144. }
  145. return $this;
  146. }
  147. public function removeEventRecur(EventRecur $eventRecur): self
  148. {
  149. if ($this->eventRecur->removeElement($eventRecur)) {
  150. // set the owning side to null (unless already changed)
  151. if ($eventRecur->getEvent() === $this) {
  152. $eventRecur->setEvent(null);
  153. }
  154. }
  155. return $this;
  156. }
  157. /**
  158. * @return Collection<int, Event>
  159. */
  160. public function getTimeline(): Collection
  161. {
  162. return $this->timeline;
  163. }
  164. public function addTimeline(Event $timeline): self
  165. {
  166. if (!$this->timeline->contains($timeline)) {
  167. $this->timeline[] = $timeline;
  168. $timeline->setParent($this);
  169. }
  170. return $this;
  171. }
  172. public function removeTimeline(Event $timeline): self
  173. {
  174. if ($this->timeline->removeElement($timeline)) {
  175. // set the owning side to null (unless already changed)
  176. if ($timeline->getParent() === $this) {
  177. $timeline->setParent(null);
  178. }
  179. }
  180. return $this;
  181. }
  182. public function getParent(): ?self
  183. {
  184. return $this->parent;
  185. }
  186. public function setParent(?self $parent): self
  187. {
  188. $this->parent = $parent;
  189. return $this;
  190. }
  191. public function getImage(): ?File
  192. {
  193. return $this->image;
  194. }
  195. public function setImage(?File $image): self
  196. {
  197. $this->image = $image;
  198. return $this;
  199. }
  200. public function getGender(): ?EventGender
  201. {
  202. return $this->gender;
  203. }
  204. public function setGender(?EventGender $gender): self
  205. {
  206. $this->gender = $gender;
  207. return $this;
  208. }
  209. /**
  210. * @return Collection<int, EventUser>
  211. */
  212. public function getEventUser(): Collection
  213. {
  214. return $this->eventUser;
  215. }
  216. public function addEventUser(EventUser $eventUser): self
  217. {
  218. if (!$this->eventUser->contains($eventUser)) {
  219. $this->eventUser[] = $eventUser;
  220. $eventUser->setEvent($this);
  221. }
  222. return $this;
  223. }
  224. public function removeEventUser(EventUser $eventUser): self
  225. {
  226. if ($this->eventUser->removeElement($eventUser)) {
  227. // set the owning side to null (unless already changed)
  228. if ($eventUser->getEvent() === $this) {
  229. $eventUser->setEvent(null);
  230. }
  231. }
  232. return $this;
  233. }
  234. /**
  235. * @return Collection<int, Categories>
  236. */
  237. public function getCategories(): Collection
  238. {
  239. return $this->categories;
  240. }
  241. public function addCategory(Categories $category): self
  242. {
  243. if (!$this->categories->contains($category)) {
  244. $this->categories[] = $category;
  245. }
  246. return $this;
  247. }
  248. public function removeCategory(Categories $category): self
  249. {
  250. $this->categories->removeElement($category);
  251. return $this;
  252. }
  253. /**
  254. * @return Collection<int, EventReport>
  255. */
  256. public function getEventReports(): Collection
  257. {
  258. return $this->eventReports;
  259. }
  260. public function addEventReport(EventReport $eventReport): self
  261. {
  262. if (!$this->eventReports->contains($eventReport)) {
  263. $this->eventReports[] = $eventReport;
  264. $eventReport->setEvent($this);
  265. }
  266. return $this;
  267. }
  268. public function removeEventReport(EventReport $eventReport): self
  269. {
  270. if ($this->eventReports->removeElement($eventReport)) {
  271. // set the owning side to null (unless already changed)
  272. if ($eventReport->getEvent() === $this) {
  273. $eventReport->setEvent(null);
  274. }
  275. }
  276. return $this;
  277. }
  278. /**
  279. * @return Collection<int, File>
  280. */
  281. public function getFiles(): Collection
  282. {
  283. return $this->files;
  284. }
  285. public function addFile(File $file): self
  286. {
  287. if (!$this->files->contains($file)) {
  288. $this->files[] = $file;
  289. }
  290. return $this;
  291. }
  292. public function removeFile(File $file): self
  293. {
  294. $this->files->removeElement($file);
  295. return $this;
  296. }
  297. public function getPlaceSystem(): ?PlaceSystem
  298. {
  299. return $this->placeSystem;
  300. }
  301. public function setPlaceSystem(?PlaceSystem $placeSystem): self
  302. {
  303. $this->placeSystem = $placeSystem;
  304. return $this;
  305. }
  306. /**
  307. * @return Collection<int, AttendanceBooking>
  308. */
  309. public function getAttendanceBooking(): Collection
  310. {
  311. return $this->attendanceBooking;
  312. }
  313. public function addAttendanceBooking(AttendanceBooking $attendanceBooking): self
  314. {
  315. if (!$this->attendanceBooking->contains($attendanceBooking)) {
  316. $this->attendanceBooking[] = $attendanceBooking;
  317. $attendanceBooking->setEvent($this);
  318. }
  319. return $this;
  320. }
  321. public function removeAttendanceBooking(AttendanceBooking $attendanceBooking): self
  322. {
  323. if ($this->attendanceBooking->removeElement($attendanceBooking)) {
  324. // set the owning side to null (unless already changed)
  325. if ($attendanceBooking->getEvent() === $this) {
  326. $attendanceBooking->setEvent(null);
  327. }
  328. }
  329. return $this;
  330. }
  331. /**
  332. * @return Collection<int, Access>
  333. */
  334. public function getOrganizer(): Collection
  335. {
  336. return $this->organizer;
  337. }
  338. public function addOrganizer(Access $organizer): self
  339. {
  340. if (!$this->organizer->contains($organizer)) {
  341. $this->organizer[] = $organizer;
  342. }
  343. return $this;
  344. }
  345. public function removeOrganizer(Access $organizer): self
  346. {
  347. $this->organizer->removeElement($organizer);
  348. return $this;
  349. }
  350. /**
  351. * @return Collection<int, Tagg>
  352. */
  353. public function getTags(): Collection
  354. {
  355. return $this->tags;
  356. }
  357. public function addTag(Tagg $tag): self
  358. {
  359. if (!$this->tags->contains($tag)) {
  360. $this->tags[] = $tag;
  361. }
  362. return $this;
  363. }
  364. public function removeTag(Tagg $tag): self
  365. {
  366. $this->tags->removeElement($tag);
  367. return $this;
  368. }
  369. }