EducationStudent.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. <?php
  2. namespace AppBundle\Entity\Education;
  3. use AppBundle\Annotation\ExportSplitFields;
  4. use AppBundle\Entity\AccessAndFunction\Access;
  5. use AppBundle\Entity\Core\Tagg;
  6. use AppBundle\Entity\Traits\ActivityYearTrait;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Dunglas\ApiBundle\Annotation\Iri;
  10. use Finite\StatefulInterface;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. use AppBundle\Entity\Traits\TimestampableEntity;
  14. use AppBundle\Entity\Traits\CreatorUpdaterEntity;
  15. use AppBundle\Validator\Constraints\Education as OpentalentAssert;
  16. /**
  17. * EducationCurriculum suivi par un Access pendant une année scolaire
  18. *
  19. * @Iri("http://schema.org/EducationStudent")
  20. * @OpentalentAssert\EducationStudentAccessStudent
  21. * @OpentalentAssert\EducationStudentTiming
  22. */
  23. #[ORM\Entity(repositoryClass: 'AppBundle\Entity\Education\Repository\EducationStudentRepository')]
  24. class EducationStudent implements StatefulInterface
  25. {
  26. use TimestampableEntity;
  27. use CreatorUpdaterEntity;
  28. use ActivityYearTrait;
  29. /**
  30. * @var int
  31. */
  32. #[ORM\Column(type: 'integer')]
  33. #[ORM\Id]
  34. #[ORM\GeneratedValue(strategy: 'AUTO')]
  35. #[Groups(['educationstudent', 'access_details', 'student_list', 'report_card', 'student_registration', 'educationnotation_list', 'examenconvocation_list_student', 'education_input_list', 'education_student_next_year', 'online_registration_access_details', 'accesses_no_reregistred_list'])]
  36. private $id;
  37. /**
  38. * @var Access
  39. */
  40. #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\AccessAndFunction\Access', inversedBy: 'educationStudent', cascade: ['persist'])]
  41. #[ORM\JoinColumn(nullable: false)]
  42. #[Assert\NotNull]
  43. #[Groups(['educationstudent', 'my_student_list', 'educationstudent_reference', 'education_student_next_year', 'educationnotation_list_educationstudent', 'education_input_list', 'education_student_next_year', 'educationstudent_notation', 'education_student_next_year_edit'])]
  44. private $access;
  45. /**
  46. * @var EducationCurriculum
  47. *
  48. *
  49. */
  50. #[ORM\ManyToOne(targetEntity: 'EducationCurriculum', inversedBy: 'educationStudent')]
  51. #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
  52. #[Groups(['educationstudent', 'access_details_educationstudent', 'my_student_list', 'report_card_educationstudent', 'student_registration_educationstudent', 'educationstudent_reference', 'educationnotation_list_educationstudent', 'examenconvocation_list_student', 'education_input_list', 'education_student_next_year', 'education_student_next_year_educationstudentlastyear', 'online_registration_access_details_educationstudent', 'educationstudent_notation', 'accesses_no_reregistred_list_educationstudent', 'student_list_educationstudent'])]
  53. private $educationCurriculum;
  54. /**
  55. * @var Access
  56. */
  57. #[ORM\ManyToMany(targetEntity: 'AppBundle\Entity\AccessAndFunction\Access', inversedBy: 'educationStudentByTeacher')]
  58. #[ORM\JoinTable(name: 'educationstudent_teacher')]
  59. #[Groups(['educationstudent_teachers', 'report_card_educationstudent', 'access_details_educationstudent', 'student_registration_educationstudent', 'educationstudent_reference', 'student_list_educationstudent', 'educationnotation_list_educationstudent', 'education_student_next_year', 'education_student_next_year_educationstudentlastyear', 'education_input_list', 'accesses_no_reregistred_list_educationstudent'])]
  60. private $teachers;
  61. /**
  62. * @var string
  63. */
  64. #[ORM\Column(type: 'string', length: 25, nullable: true)]
  65. #[Assert\Type(type: 'string')]
  66. #[Groups(['educationstudent', 'report_card_educationstudent'])]
  67. private $graduation;
  68. /**
  69. * @var bool
  70. */
  71. #[ORM\Column(type: 'boolean', options: ['default' => false])]
  72. #[Assert\Type(type: 'boolean')]
  73. #[Assert\NotNull]
  74. #[Groups(['educationstudent', 'report_card_educationstudent', 'education_student_next_year', 'student_registration_educationstudent', 'education_student_next_year_educationstudentlastyear'])]
  75. private $acquired = false;
  76. /**
  77. * @var ArrayCollection<EducationNotation>
  78. */
  79. #[Assert\Valid]
  80. #[ORM\OneToMany(targetEntity: 'AppBundle\Entity\Education\EducationNotation', mappedBy: 'educationStudent', orphanRemoval: true, cascade: ['persist'])]
  81. #[Groups(['educationstudent_educationnotation', 'report_card_educationstudent', 'education_input_list', 'educationstudent_notation'])]
  82. private $educationNotations;
  83. /**
  84. * @var string
  85. */
  86. #[ORM\Column(type: 'text', nullable: true)]
  87. #[Assert\Type(type: 'string')]
  88. #[Groups(['educationstudent', 'report_card_educationstudent'])]
  89. private $annualAppreciation;
  90. /**
  91. * @var bool
  92. */
  93. #[ORM\Column(type: 'boolean', options: ['default' => false])]
  94. #[Assert\Type(type: 'boolean')]
  95. #[Assert\NotNull]
  96. #[Groups(['educationstudent', 'education_student_next_year', 'education_student_next_year_educationstudentlastyear', 'student_registration_educationstudent'])]
  97. private $registeredFollowingYear = false;
  98. /**
  99. * Finite State Status
  100. * @var
  101. */
  102. private $state;
  103. /**
  104. * @var bool
  105. */
  106. #[Groups(['template', 'education_student_next_year'])]
  107. private $stateTemplate;
  108. /**
  109. * Last year information
  110. * @var EducationStudent
  111. */
  112. #[ORM\ManyToOne(targetEntity: 'EducationStudent', inversedBy: 'referencedEducationStudent')]
  113. #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
  114. #[Groups(['education_student_next_year'])]
  115. private $educationStudentLastYear;
  116. #[ORM\OneToMany(targetEntity: 'EducationStudent', mappedBy: 'educationStudentLastYear')]
  117. protected $referencedEducationStudent;
  118. /**
  119. * @var boolean
  120. */
  121. #[Groups(['educationstudent'])]
  122. private $allNotationsValid;
  123. /**
  124. * @var string
  125. * @ExportSplitFields({"educationCurriculum.education.educationCategory.label","educationCurriculum.education.educationComplementTemplate","educationCurriculum.cycle.label","educationCurriculum.year","educationCurriculum.level","teachersTemplate","educationTiming.timing"})
  126. */
  127. #[Groups(['intangible_list_educationcurriculums', 'educationcurriculum', 'student_list_educationstudent', 'accesses_no_reregistred_list_educationstudent'])]
  128. private $fullLabelTemplate;
  129. /**
  130. * @var string
  131. */
  132. #[Groups(['template', 'educationstudent_notation'])]
  133. private $educationCurriculumTemplate;
  134. /**
  135. * @var string
  136. */
  137. #[Groups(['template'])]
  138. private $teachersTemplate;
  139. /**
  140. * @var string
  141. */
  142. #[Groups(['educationstudent_placeroom', 'access_details_educationstudent'])]
  143. private $placeRoom;
  144. /**
  145. * @var array
  146. */
  147. #[ORM\Column(type: 'json_array', nullable: true)]
  148. #[Groups(['educationstudent', 'educationstudent_days', 'education_student_next_year', 'student_registration_educationstudent'])]
  149. private $days;
  150. private $days_export;
  151. /**
  152. * @var \DateTime
  153. */
  154. #[ORM\Column(type: 'time', nullable: true)]
  155. #[Assert\Time]
  156. #[Groups(['educationstudent', 'education_student_next_year', 'student_registration_educationstudent'])]
  157. private $time;
  158. /**
  159. * @var ArrayCollection<Tagg>
  160. */
  161. #[ORM\ManyToMany(targetEntity: 'AppBundle\Entity\Core\Tagg', cascade: ['persist'], inversedBy: 'educationStudents')]
  162. #[Assert\Valid]
  163. #[ORM\JoinTable(name: 'tag_educationStudent', joinColumns: [], inverseJoinColumns: [])]
  164. #[ORM\JoinColumn(name: 'educationStudent_id', referencedColumnName: 'id')]
  165. #[ORM\JoinColumn(name: 'tag_id', referencedColumnName: 'id')]
  166. #[Groups(['eductionstudent_tags', 'manage_tags'])]
  167. private $tags;
  168. /**
  169. * @var EducationTiming
  170. */
  171. #[ORM\ManyToOne(targetEntity: 'EducationTiming', inversedBy: 'educationStudents')]
  172. #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
  173. #[Groups(['educationstudent', 'student_registration_educationstudent', 'access_details_educationstudent', 'student_list_educationstudent', 'education_student_next_year', 'education_student_next_year_educationstudentlastyear'])]
  174. private $educationTiming;
  175. /**
  176. * Constructor
  177. */
  178. public function __construct()
  179. {
  180. $this->educationNotations = new ArrayCollection();
  181. $this->referencedEducationStudent = new ArrayCollection();
  182. $this->teachers = new ArrayCollection();
  183. $this->tags = new ArrayCollection();
  184. }
  185. /**
  186. * Gets allNotationsValid.
  187. *
  188. * @return boolean
  189. */
  190. public function getAllNotationsValid()
  191. {
  192. $allNotationsValid = true;
  193. $notations = $this->getEducationNotations();
  194. if(count($notations) == 0) $allNotationsValid = false;
  195. foreach ($notations as $notation) {
  196. if(!$notation->getIsValid()){
  197. $allNotationsValid = false;
  198. break;
  199. }
  200. }
  201. return $allNotationsValid;
  202. }
  203. /**
  204. * Sets id.
  205. *
  206. * @param int $id
  207. *
  208. * @return $this
  209. */
  210. public function setId($id)
  211. {
  212. $this->id = $id;
  213. return $this;
  214. }
  215. /**
  216. * Gets id.
  217. *
  218. * @return int
  219. */
  220. public function getId()
  221. {
  222. return $this->id;
  223. }
  224. /**
  225. * Sets access.
  226. *
  227. * @param Access $access
  228. *
  229. * @return $this
  230. */
  231. public function setAccess(\AppBundle\Entity\AccessAndFunction\Access $access)
  232. {
  233. $this->access = $access;
  234. return $this;
  235. }
  236. /**
  237. * Gets access.
  238. *
  239. * @return Access
  240. */
  241. public function getAccess()
  242. {
  243. return $this->access;
  244. }
  245. /**
  246. * Sets education Curriculum.
  247. *
  248. * @param EducationCurriculum $educationCurriculum
  249. *
  250. * @return $this
  251. */
  252. public function setEducationCurriculum(EducationCurriculum $educationCurriculum = null)
  253. {
  254. $this->educationCurriculum = $educationCurriculum;
  255. return $this;
  256. }
  257. /**
  258. * Gets education Curriculum.
  259. *
  260. * @return EducationCurriculum
  261. */
  262. public function getEducationCurriculum()
  263. {
  264. return $this->educationCurriculum;
  265. }
  266. /**
  267. * Sets graduation.
  268. *
  269. * @param string $graduation
  270. *
  271. * @return $this
  272. */
  273. public function setGraduation($graduation)
  274. {
  275. $this->graduation = $graduation;
  276. return $this;
  277. }
  278. /**
  279. * Gets graduation.
  280. *
  281. * @return string
  282. */
  283. public function getGraduation()
  284. {
  285. return $this->graduation;
  286. }
  287. /**
  288. * Sets Acquired.
  289. *
  290. * @param bool $acquired
  291. *
  292. * @return $this
  293. */
  294. public function setAcquired($acquired)
  295. {
  296. $this->acquired = $acquired;
  297. return $this;
  298. }
  299. /**
  300. * Gets Acquired.
  301. *
  302. * @return bool
  303. */
  304. public function getAcquired()
  305. {
  306. return $this->acquired;
  307. }
  308. /**
  309. * Gets the object state.
  310. *
  311. * @return string
  312. */
  313. public function getFiniteState()
  314. {
  315. return $this->state;
  316. }
  317. /**
  318. * @param string $state
  319. * @return $this
  320. */
  321. public function setFiniteState($state)
  322. {
  323. $this->state = $state;
  324. return $this;
  325. }
  326. /**
  327. * Set annualAppreciation
  328. *
  329. * @param string $annualAppreciation
  330. *
  331. * @return EducationStudent
  332. */
  333. public function setAnnualAppreciation($annualAppreciation)
  334. {
  335. $this->annualAppreciation = $annualAppreciation;
  336. return $this;
  337. }
  338. /**
  339. * Get annualAppreciation
  340. *
  341. * @return string
  342. */
  343. public function getAnnualAppreciation()
  344. {
  345. return $this->annualAppreciation;
  346. }
  347. /**
  348. * Add educationNotation
  349. *
  350. * @param \AppBundle\Entity\Education\EducationNotation $educationNotation
  351. *
  352. * @return EducationStudent
  353. */
  354. public function addEducationNotation(\AppBundle\Entity\Education\EducationNotation $educationNotation)
  355. {
  356. $educationNotation->setEducationStudent($this);
  357. $this->educationNotations[] = $educationNotation;
  358. return $this;
  359. }
  360. /**
  361. * Remove educationNotation
  362. *
  363. * @param \AppBundle\Entity\Education\EducationNotation $educationNotation
  364. */
  365. public function removeEducationNotation(\AppBundle\Entity\Education\EducationNotation $educationNotation)
  366. {
  367. $this->educationNotations->removeElement($educationNotation);
  368. }
  369. /**
  370. * Get educationNotations
  371. *
  372. * @return \Doctrine\Common\Collections\Collection
  373. */
  374. public function getEducationNotations()
  375. {
  376. return $this->educationNotations;
  377. }
  378. /**
  379. * Add teacher
  380. *
  381. * @param \AppBundle\Entity\AccessAndFunction\Access $teacher
  382. *
  383. * @return EducationStudent
  384. */
  385. public function addTeacher(\AppBundle\Entity\AccessAndFunction\Access $teacher)
  386. {
  387. $this->teachers[] = $teacher;
  388. return $this;
  389. }
  390. /**
  391. * Remove teacher
  392. *
  393. * @param \AppBundle\Entity\AccessAndFunction\Access $teacher
  394. */
  395. public function removeTeacher(\AppBundle\Entity\AccessAndFunction\Access $teacher)
  396. {
  397. $this->teachers->removeElement($teacher);
  398. }
  399. /**
  400. * Get teachers
  401. *
  402. * @return \Doctrine\Common\Collections\Collection
  403. */
  404. public function getTeachers()
  405. {
  406. return $this->teachers;
  407. }
  408. /**
  409. * Gets full label.
  410. *
  411. * @return array
  412. */
  413. public function getFullLabelTemplate()
  414. {
  415. return array_merge($this->getEducationCurriculumTemplate(), $this->getTeachersTemplate(), [$this->getEducationTiming() ? $this->getEducationTiming()->getTiming() : '']);
  416. }
  417. /**
  418. * @return array
  419. */
  420. public function getEducationCurriculumTemplate()
  421. {
  422. $educationCurriculumTemplate = [];
  423. if($this->getEducationCurriculum())
  424. $educationCurriculumTemplate = $this->getEducationCurriculum()->getFullLabelTemplate();
  425. return $educationCurriculumTemplate;
  426. }
  427. /**
  428. * @return array
  429. */
  430. public function getTeachersTemplate()
  431. {
  432. $teachers = [];
  433. foreach($this->getTeachers() as $teacher){
  434. $teachers[] = $teacher->getPerson()->getFullNameTemplate();
  435. }
  436. return [implode(", ", $teachers)];
  437. }
  438. /**
  439. * Gets full label.
  440. *
  441. * @return string
  442. */
  443. public function getPlaceRoom()
  444. {
  445. $placeRoom = '';
  446. $student = $this->getAccess();
  447. foreach ($student->getCourses() as $course){
  448. foreach ($course->getEducationCurriculum() as $educationCurri)
  449. if (!is_null($educationCurri) && !is_null($this->getEducationCurriculum()) &&
  450. $educationCurri->getId() === $this->getEducationCurriculum()->getId()
  451. && $course->getStartYear() === $this->getStartYear()){
  452. $place = $course->getPlace() ? $course->getPlace()->getName().' ' : '';
  453. $room = $course->getRoom() ? $course->getRoom()->getName() : '';
  454. $placeRoom = $place.$room;
  455. }
  456. }
  457. return $placeRoom;
  458. }
  459. /**
  460. * Set registeredFollowingYear
  461. *
  462. * @param boolean $registeredFollowingYear
  463. *
  464. * @return EducationStudent
  465. */
  466. public function setRegisteredFollowingYear($registeredFollowingYear)
  467. {
  468. $this->registeredFollowingYear = $registeredFollowingYear;
  469. return $this;
  470. }
  471. /**
  472. * Get registeredFollowingYear
  473. *
  474. * @return boolean
  475. */
  476. public function getRegisteredFollowingYear()
  477. {
  478. return $this->registeredFollowingYear;
  479. }
  480. /**
  481. * Sets Education Student Last Year information.
  482. *
  483. * @param EducationStudent $access
  484. *
  485. * @return $this
  486. */
  487. public function setEducationStudentLastYear(EducationStudent $educationStudentLastYear)
  488. {
  489. $this->educationStudentLastYear = $educationStudentLastYear;
  490. return $this;
  491. }
  492. /**
  493. * Gets Education Student Last Year information.
  494. *
  495. * @return EducationStudent
  496. */
  497. public function getEducationStudentLastYear()
  498. {
  499. return $this->educationStudentLastYear;
  500. }
  501. /**
  502. * Set days
  503. *
  504. * @param array $days
  505. *
  506. * @return EducationStudent
  507. */
  508. public function setDays($days)
  509. {
  510. $this->days = $days;
  511. return $this;
  512. }
  513. /**
  514. * Get days
  515. *
  516. * @return array
  517. */
  518. public function getDays()
  519. {
  520. return $this->days;
  521. }
  522. /**
  523. * Set time
  524. *
  525. * @param \DateTime $time
  526. *
  527. * @return EducationStudent
  528. */
  529. public function setTime($time)
  530. {
  531. $this->time = $time;
  532. return $this;
  533. }
  534. /**
  535. * Get time
  536. *
  537. */
  538. public function getTime()
  539. {
  540. if($this->time){
  541. $this->time->setTime($this->time->format("H"), $this->time->format("i"), 0);
  542. return $this->time->format('H:i');
  543. }
  544. return null;
  545. }
  546. /**
  547. * Add tag
  548. *
  549. * @param \AppBundle\Entity\Core\Tagg $tag
  550. *
  551. * @return EducationStudent
  552. */
  553. public function addTag(\AppBundle\Entity\Core\Tagg $tag)
  554. {
  555. $this->tags[] = $tag;
  556. return $this;
  557. }
  558. /**
  559. * Remove tag
  560. *
  561. * @param \AppBundle\Entity\Core\Tagg $tag
  562. */
  563. public function removeTag(\AppBundle\Entity\Core\Tagg $tag)
  564. {
  565. $this->tags->removeElement($tag);
  566. }
  567. /**
  568. * Get tags
  569. *
  570. * @return \Doctrine\Common\Collections\Collection
  571. */
  572. public function getTags()
  573. {
  574. return $this->tags;
  575. }
  576. /**
  577. * Gets full label.
  578. *
  579. * @return bool
  580. */
  581. public function getStateTemplate()
  582. {
  583. $year = date("Y");
  584. $lastYear = $year - 1;
  585. return $this->getStartYear() != $lastYear;
  586. }
  587. /**
  588. * Sets EducationTiming
  589. *
  590. * @param EducationTiming $educationTiming
  591. *
  592. * @return $this
  593. */
  594. public function setEducationTiming(EducationTiming $educationTiming = null)
  595. {
  596. $this->educationTiming = $educationTiming;
  597. return $this;
  598. }
  599. /**
  600. * Gets EducationTiming
  601. *
  602. * @return EducationTiming
  603. */
  604. public function getEducationTiming()
  605. {
  606. return $this->educationTiming;
  607. }
  608. }