Examen.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <?php
  2. namespace AppBundle\Entity\Booking;
  3. use AppBundle\Entity\Education\EducationCurriculum;
  4. use AppBundle\Entity\Organization\Jury;
  5. use AppBundle\Enum\Education\PratiqueEnum;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Dunglas\ApiBundle\Annotation\Iri;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use AppBundle\Validator\Constraints\Booking as OpentalentEventAssert;
  12. /**
  13. * Examen
  14. *
  15. * @Iri("http://schema.org/Examen")
  16. * @OpentalentEventAssert\Examen()
  17. */
  18. #[ORM\Entity]
  19. class Examen extends AbstractBooking
  20. {
  21. /**
  22. * @var ArrayCollection<ExamenRecur>
  23. */
  24. #[Assert\Valid]
  25. #[ORM\OneToMany(targetEntity: 'ExamenRecur', mappedBy: 'event', cascade: ['persist'], orphanRemoval: true)]
  26. #[Groups(['examen_bookingrecur', 'planning_detail', 'examen_informations_edit'])]
  27. protected $eventRecur;
  28. /**
  29. * @var ArrayCollection<Examen>
  30. */
  31. #[ORM\OneToMany(targetEntity: 'Examen', mappedBy: 'parent', orphanRemoval: true)]
  32. #[Groups(['examen_timeline'])]
  33. private $timeline;
  34. /**
  35. * @var \AppBundle\Entity\Booking\Examen
  36. */
  37. #[ORM\ManyToOne(targetEntity: 'Examen', inversedBy: 'timeline')]
  38. #[Groups(['examen'])]
  39. private $parent;
  40. /**
  41. * @var string
  42. */
  43. #[Assert\Type(type: 'string')]
  44. #[Assert\Choice(callback: ['\AppBundle\Enum\Booking\ExamenTimelineTypeEnum', 'toArray'], multiple: false, min: 1)]
  45. #[ORM\Column(type: 'string', length: 255, nullable: true)]
  46. #[Groups(['examen'])]
  47. private $type;
  48. /**
  49. * @var Jury
  50. */
  51. #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Organization\Jury', inversedBy: 'examens', cascade: ['persist'])]
  52. #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
  53. #[Groups(['examen', 'examenconvocation_list_examen', 'examen_details', 'planning_detail', 'presence_attendance', 'examen_informations_edit'])]
  54. private $jury;
  55. /**
  56. * @var string
  57. */
  58. #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Education\Education', inversedBy: 'examens')]
  59. #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
  60. #[Groups(['examen', 'examenconvocation_list_examen', 'planning_list', 'presence_attendance', 'examen_details', 'planning_detail', 'report_card_examenconvocations', 'examen_informations_edit'])]
  61. private $education;
  62. /**
  63. * @var EducationCurriculum
  64. */
  65. #[ORM\ManyToMany(targetEntity: 'AppBundle\Entity\Education\EducationCurriculum')]
  66. #[Groups(['examen_educationcurriculum', 'planning_detail', 'examenconvocation_list_examen', 'planning_list', 'presence_attendance', 'examen_details', 'examen_informations_edit'])]
  67. private $educationCurriculum;
  68. /**
  69. * @var ArrayCollection<ExamenConvocation>
  70. */
  71. #[Assert\Valid]
  72. #[ORM\OneToMany(targetEntity: 'ExamenConvocation', mappedBy: 'examen', cascade: ['persist'], orphanRemoval: true)]
  73. #[Groups(['examen_examenconvocation', 'presence_attendance', 'examen_details', 'planning_detail', 'examen_informations_edit'])]
  74. private $convocation;
  75. /**
  76. * var ArrayCollection<AttendanceBooking>
  77. */
  78. #[Assert\Valid]
  79. #[ORM\OneToMany(targetEntity: 'AppBundle\Entity\Booking\AttendanceBooking', cascade: ['persist'], mappedBy: 'examen', orphanRemoval: true)]
  80. #[ORM\JoinColumn(nullable: false)]
  81. #[Groups(['examen_attendancebooking', 'presence_attendance', 'planning_detail', 'examen_details'])]
  82. private $attendanceBooking;
  83. /**
  84. * @var string
  85. */
  86. private $fullLabelTemplate;
  87. public function __construct()
  88. {
  89. parent::__construct();
  90. $this->educationCurriculum = new ArrayCollection();
  91. $this->convocation = new ArrayCollection();
  92. $this->attendanceBooking = new ArrayCollection();
  93. }
  94. /**
  95. * Sets jury.
  96. *
  97. * @param Jury $jury
  98. *
  99. * @return $this
  100. */
  101. public function setJury(\AppBundle\Entity\Organization\Jury $jury = null)
  102. {
  103. $this->jury = $jury;
  104. return $this;
  105. }
  106. /**
  107. * Gets jury.
  108. *
  109. * @return Jury
  110. */
  111. public function getJury()
  112. {
  113. return $this->jury;
  114. }
  115. /**
  116. * Add educationCurriculum
  117. *
  118. * @param EducationCurriculum $educationCurriculum
  119. * @return EducationCurriculum
  120. */
  121. public function addEducationCurriculum(\AppBundle\Entity\Education\EducationCurriculum $educationCurriculum)
  122. {
  123. $this->educationCurriculum[] = $educationCurriculum;
  124. return $this;
  125. }
  126. /**
  127. * Remove educationCurriculum
  128. *
  129. * @param EducationCurriculum $educationCurriculum
  130. */
  131. public function removeEducationCurriculum(\AppBundle\Entity\Education\EducationCurriculum $educationCurriculum)
  132. {
  133. $this->educationCurriculum->removeElement($educationCurriculum);
  134. }
  135. /**
  136. * Get educationCurriculum
  137. *
  138. * @return \Doctrine\Common\Collections\Collection
  139. */
  140. public function getEducationCurriculum()
  141. {
  142. return $this->educationCurriculum;
  143. }
  144. /**
  145. * Add convocation
  146. *
  147. * @param ExamenConvocation $convocation
  148. * @return $this
  149. */
  150. public function addConvocation(ExamenConvocation $convocation)
  151. {
  152. $convocation->setExamen($this);
  153. $this->convocation[] = $convocation;
  154. return $this;
  155. }
  156. /**
  157. * Remove convocation
  158. *
  159. * @param ExamenConvocation $convocation
  160. * @return $this
  161. */
  162. public function removeConvocation(ExamenConvocation $convocation)
  163. {
  164. $this->convocation->removeElement($convocation);
  165. return $this;
  166. }
  167. /**
  168. * Get convocation
  169. *
  170. * @return ArrayCollection<ExamenConvocation>
  171. */
  172. public function getConvocation()
  173. {
  174. return $this->convocation;
  175. }
  176. /**
  177. * {@inheritdoc}
  178. */
  179. public function getParticipants() {
  180. $participants = new ArrayCollection();
  181. array_map(function (ExamenConvocation $c) use ($participants) { $participants->add($c->getStudent()->getPerson());}, $this->getConvocation()->toArray());
  182. return $participants;
  183. }
  184. /**
  185. * Set type
  186. *
  187. * @param string $type
  188. *
  189. * @return Examen
  190. */
  191. public function setType($type)
  192. {
  193. $this->type = $type;
  194. return $this;
  195. }
  196. /**
  197. * Get type
  198. *
  199. * @return string
  200. */
  201. public function getType()
  202. {
  203. return $this->type;
  204. }
  205. /**
  206. * Add timeline
  207. *
  208. * @param \AppBundle\Entity\Booking\Examen $timeline
  209. *
  210. * @return Examen
  211. */
  212. public function addTimeline(\AppBundle\Entity\Booking\Examen $timeline)
  213. {
  214. $this->timeline[] = $timeline;
  215. return $this;
  216. }
  217. /**
  218. * Remove timeline
  219. *
  220. * @param \AppBundle\Entity\Booking\Examen $timeline
  221. */
  222. public function removeTimeline(\AppBundle\Entity\Booking\Examen $timeline)
  223. {
  224. $this->timeline->removeElement($timeline);
  225. }
  226. /**
  227. * Get timeline
  228. *
  229. * @return \Doctrine\Common\Collections\Collection
  230. */
  231. public function getTimeline()
  232. {
  233. return $this->timeline;
  234. }
  235. /**
  236. * Set parent
  237. *
  238. * @param \AppBundle\Entity\Booking\Examen $parent
  239. *
  240. * @return Examen
  241. */
  242. public function setParent(\AppBundle\Entity\Booking\Examen $parent = null)
  243. {
  244. $this->parent = $parent;
  245. return $this;
  246. }
  247. /**
  248. * Get parent
  249. *
  250. * @return \AppBundle\Entity\Booking\Examen
  251. */
  252. public function getParent()
  253. {
  254. return $this->parent;
  255. }
  256. /**
  257. * Set education
  258. *
  259. * @param \AppBundle\Entity\Education\Education $education
  260. *
  261. * @return Examen
  262. */
  263. public function setEducation(\AppBundle\Entity\Education\Education $education = null)
  264. {
  265. $this->education = $education;
  266. return $this;
  267. }
  268. /**
  269. * Get education
  270. *
  271. * @return \AppBundle\Entity\Education\Education
  272. */
  273. public function getEducation()
  274. {
  275. return $this->education;
  276. }
  277. /**
  278. * Add attendanceBooking
  279. *
  280. * @param \AppBundle\Entity\Booking\AttendanceBooking $attendanceBooking
  281. *
  282. * @return AbstractBooking
  283. */
  284. public function addAttendanceBooking(\AppBundle\Entity\Booking\AttendanceBooking $attendanceBooking)
  285. {
  286. $attendanceBooking->setExamen($this);
  287. $this->attendanceBooking[] = $attendanceBooking;
  288. return $this;
  289. }
  290. /**
  291. * Remove attendanceBooking
  292. *
  293. * @param \AppBundle\Entity\Booking\AttendanceBooking $attendanceBooking
  294. */
  295. public function removeAttendanceBooking(\AppBundle\Entity\Booking\AttendanceBooking $attendanceBooking)
  296. {
  297. $this->attendanceBooking->removeElement($attendanceBooking);
  298. }
  299. /**
  300. * Get attendanceBooking
  301. *
  302. * @return \Doctrine\Common\Collections\Collection
  303. */
  304. public function getAttendanceBooking()
  305. {
  306. return $this->attendanceBooking;
  307. }
  308. /**
  309. * Gets full label.
  310. *
  311. * @return array
  312. */
  313. public function getFullLabelTemplate()
  314. {
  315. $dateTimeStart = $this->getDatetimeStart();
  316. $timezone = 'Europe/Paris';
  317. $dateTimeStart->setTimezone(new \DateTimeZone($timezone));
  318. $dateTimeStartFormatted = [];
  319. $dateTimeStartFormatted[] = ['value' => $dateTimeStart->format('l') , 'translate' => true];
  320. $dateTimeStartFormatted[] = $dateTimeStart->format('à H:i');
  321. if(is_null($this->getEducation())){
  322. return [];
  323. }
  324. $educationCurricullums = [];
  325. foreach ($this->getEducationCurriculum() as $edc){
  326. $educationCurricullums[] = ( $edc->getCycle() ? $edc->getCycle()->getLabel() : '' );
  327. $educationCurricullums[] = ['value' => $edc->getYear(), 'translate' => true];
  328. $educationCurricullums[] = $edc->getLevel();
  329. $educationCurricullums[] = ', ';
  330. }
  331. $fullLabelTemplate = [
  332. $this->getName(),
  333. $this->getEducation()->getEducationCategory()->getLabel(),
  334. ($this->getEducation()->getEducationComplement() && $this->getEducation()->getEducationComplement()->getName() !== PratiqueEnum::NONE)?$this->getEducation()->getEducationComplement()->getName():''
  335. ];
  336. return array_merge($fullLabelTemplate, $educationCurricullums, $dateTimeStartFormatted);
  337. }
  338. }