src/Entity/Student.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\ClassRoom;
  4. use App\Entity\Mark;
  5. use App\Entity\Payment;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use App\Entity\Traits\TimeStampable;
  9. use App\Repository\StudentRepository;
  10. use App\Entity\Traits\HasUploadableField;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  16. /**
  17. * @ORM\Entity(repositoryClass=StudentRepository::class)
  18. * @UniqueEntity(fields={"matricule"}, message="There is already an account with this matricule")
  19. * @ORM\HasLifecycleCallbacks
  20. * @Vich\Uploadable
  21. *
  22. */
  23. class Student
  24. {
  25. use TimeStampable;
  26. use HasUploadableField;
  27. /**
  28. * @ORM\Id
  29. * @ORM\GeneratedValue
  30. * @ORM\Column(type="integer")
  31. */
  32. private $id;
  33. /**
  34. * NOTE: This is not a mapped field of entity metadata, just a simple property.
  35. *
  36. * @Vich\UploadableField(mapping="student_image", fileNameProperty="imageName")
  37. * @Assert\File(
  38. * maxSize = "6024k",
  39. * mimeTypes = {"image/bmp", "image/gif", "image/x-icon", "image/jpeg", "image/png", "image/svg+xml", "image/PNG", "image/JPG"},
  40. * mimeTypesMessage = "Please upload a valid image(bmp,gif,jpg,jpeg,png,svg)"
  41. * )
  42. *
  43. * @var File|null
  44. */
  45. private $imageFile;
  46. /**
  47. * @ORM\Column(type="string", length=255)
  48. */
  49. private $matricule;
  50. /**
  51. * @var string
  52. *
  53. * @ORM\Column(name="firstname", type="string", length=255, nullable=true)
  54. */
  55. private $firstname;
  56. /**
  57. * @var string
  58. *
  59. * @ORM\Column(name="lastname", type="string", length=255)
  60. */
  61. private $lastname;
  62. /**
  63. * @var string
  64. *
  65. * @ORM\Column(name="particular_disease", type="string", length=255, nullable=true)
  66. */
  67. private $particularDisease;
  68. /**
  69. * @var string
  70. *
  71. * @ORM\Column(name="father_name", type="string", length=255)
  72. */
  73. private $fatherName;
  74. /**
  75. * @var string
  76. *
  77. * @ORM\Column(name="mother_name", type="string", length=255)
  78. */
  79. private $motherName;
  80. /**
  81. * @var string
  82. *
  83. * @ORM\Column(name="primary_contact", type="string", length=255, nullable=true)
  84. */
  85. private $primaryContact;
  86. /**
  87. * @var string
  88. *
  89. * @ORM\Column(name="residence", type="string", length=255, nullable=true)
  90. */
  91. private $residence;
  92. /**
  93. * @var string
  94. *
  95. * @ORM\Column(name="secondary_contact", type="string", length=255, nullable=true)
  96. */
  97. private $secondaryContact;
  98. /**
  99. * @var string
  100. *
  101. * @ORM\Column(name="other_informations", type="text", nullable=true)
  102. */
  103. private $otherInformations;
  104. /**
  105. * @var \DateTime
  106. *
  107. * @ORM\Column(name="birthday", type="date", nullable=false)
  108. */
  109. private $birthday;
  110. /** @ORM\Column(name="gender", nullable=false, unique=false, length=10)
  111. * @Assert\Choice(
  112. * choices = { "0", "1" },
  113. * message = "précisez le sexe")
  114. */
  115. private $gender;
  116. /**
  117. * @var string
  118. *
  119. * @ORM\Column(name="birthplace", type="string", length=255)
  120. */
  121. private $birthplace;
  122. /**
  123. * @var boolean
  124. *
  125. * @ORM\Column(name="enrolled", type="boolean", options={"default":false})
  126. */
  127. private $enrolled = false;
  128. /**
  129. * @ORM\OneToMany(targetEntity=Subscription::class, mappedBy="student")
  130. */
  131. private $subscriptions;
  132. /**
  133. * @ORM\OneToMany(targetEntity=Payment::class, mappedBy="student",cascade={"persist"})
  134. * @ORM\JoinColumn(nullable=true)
  135. *
  136. * */
  137. private $payments;
  138. /**
  139. * @ORM\ManyToOne(targetEntity=ClassRoom::class)
  140. * @ORM\JoinColumn(nullable=true)
  141. */
  142. private $entryClass;
  143. /**
  144. * Get updated
  145. *
  146. * @return \DateTime
  147. */
  148. public function getUpdated()
  149. {
  150. return $this->updated;
  151. }
  152. public function getId(): ?int
  153. {
  154. return $this->id;
  155. }
  156. /**
  157. *
  158. * @return string
  159. */
  160. public function __toString()
  161. {
  162. $lastname = (is_null($this->getLastName())) ? "" : $this->getLastName();
  163. $firstname = (is_null($this->getFirstName())) ? "" : $this->getFirstName();
  164. $matricule = (is_null($this->getMatricule())) ? "" : $this->getMatricule();
  165. return $lastname . " " . $firstname . " " . $matricule;
  166. }
  167. /**
  168. *
  169. * @return string
  170. */
  171. public function fullName()
  172. {
  173. $lastname = (is_null($this->getLastName())) ? "" : $this->getLastName();
  174. $firstname = (is_null($this->getFirstName())) ? "" : $this->getFirstName();
  175. return $lastname . " " . $firstname ;
  176. }
  177. /**
  178. * Set matricule
  179. *
  180. * @param string $matricule
  181. *
  182. * @return Student
  183. */
  184. public function setMatricule($matricule)
  185. {
  186. $this->matricule = $matricule;
  187. return $this;
  188. }
  189. /**
  190. * Get matricule
  191. *
  192. * @return string
  193. */
  194. public function getMatricule()
  195. {
  196. return $this->matricule;
  197. }
  198. /**
  199. * Set particularDisease
  200. *
  201. * @param string $particularDisease
  202. *
  203. * @return Student
  204. */
  205. public function setParticularDisease($particularDisease)
  206. {
  207. $this->particularDisease = $particularDisease;
  208. return $this;
  209. }
  210. /**
  211. * Get particularDisease
  212. *
  213. * @return string
  214. */
  215. public function getParticularDisease()
  216. {
  217. return $this->particularDisease;
  218. }
  219. /**
  220. * Set fatherName
  221. *
  222. * @param string $fatherName
  223. *
  224. * @return Student
  225. */
  226. public function setFatherName($fatherName)
  227. {
  228. $this->fatherName = $fatherName;
  229. return $this;
  230. }
  231. /**
  232. * Get fatherName
  233. *
  234. * @return string
  235. */
  236. public function getFatherName()
  237. {
  238. return $this->fatherName;
  239. }
  240. /**
  241. * Set motherName
  242. *
  243. * @param string $motherName
  244. *
  245. * @return Student
  246. */
  247. public function setMotherName($motherName)
  248. {
  249. $this->motherName = $motherName;
  250. return $this;
  251. }
  252. /**
  253. * Get motherName
  254. *
  255. * @return string
  256. */
  257. public function getMotherName()
  258. {
  259. return $this->motherName;
  260. }
  261. /**
  262. * Set primaryContact
  263. *
  264. * @param string $primaryContact
  265. *
  266. * @return Student
  267. */
  268. public function setPrimaryContact($primaryContact)
  269. {
  270. $this->primaryContact = $primaryContact;
  271. return $this;
  272. }
  273. /**
  274. * Get primaryContact
  275. *
  276. * @return string
  277. */
  278. public function getPrimaryContact()
  279. {
  280. return $this->primaryContact;
  281. }
  282. /**
  283. * Set secondaryContact
  284. *
  285. * @param string $secondaryContact
  286. *
  287. * @return Student
  288. */
  289. public function setSecondaryContact($secondaryContact)
  290. {
  291. $this->secondaryContact = $secondaryContact;
  292. return $this;
  293. }
  294. /**
  295. * Get secondaryContact
  296. *
  297. * @return string
  298. */
  299. public function getSecondaryContact()
  300. {
  301. return $this->secondaryContact;
  302. }
  303. /**
  304. * Set otherInformations
  305. *
  306. * @param string $otherInformations
  307. *
  308. * @return Student
  309. */
  310. public function setOtherInformations($otherInformations)
  311. {
  312. $this->otherInformations = $otherInformations;
  313. return $this;
  314. }
  315. /**
  316. * Get otherInformations
  317. *
  318. * @return string
  319. */
  320. public function getOtherInformations()
  321. {
  322. return $this->otherInformations;
  323. }
  324. /**
  325. * Set gender
  326. *
  327. * @param string $gender
  328. *
  329. * @return Student
  330. */
  331. public function setGender($gender)
  332. {
  333. $this->gender = $gender;
  334. return $this;
  335. }
  336. /**
  337. * Get gender
  338. *
  339. * @return string
  340. */
  341. public function getGender()
  342. {
  343. return $this->gender;
  344. }
  345. /**
  346. * Set birthplace
  347. *
  348. * @param string $birthplace
  349. *
  350. * @return Student
  351. */
  352. public function setBirthplace($birthplace)
  353. {
  354. $this->birthplace = $birthplace;
  355. return $this;
  356. }
  357. /**
  358. * Get birthplace
  359. *
  360. * @return string
  361. */
  362. public function getBirthplace()
  363. {
  364. return $this->birthplace;
  365. }
  366. /**
  367. * Set level
  368. *
  369. * @param \AppBundle\Entity\Level $level
  370. *
  371. * @return Student
  372. */
  373. public function setLevel(Level $level)
  374. {
  375. $this->level = $level;
  376. return $this;
  377. }
  378. /**
  379. * Get level
  380. *
  381. * @return \AppBundle\Entity\Level
  382. */
  383. public function getLevel()
  384. {
  385. return $this->level;
  386. }
  387. /**
  388. * Set updated
  389. *
  390. * @param \DateTime $updated
  391. *
  392. * @return Student
  393. */
  394. public function setUpdated($updated)
  395. {
  396. $this->updated = $updated;
  397. return $this;
  398. }
  399. /**
  400. * Class where the student is enrolled in a given school year
  401. *
  402. * @return ClassRoom
  403. */
  404. public function getClassRoom(SchoolYear $year)
  405. {
  406. $subscribtion = $em->getRepository('AppBundle:Subscription')->findBy(array('schoolYear' => $year, 'student' => $std));
  407. return $subscribtion->getClassRoom();
  408. }
  409. /**
  410. * Tuition fees already paid by the student in a given school year
  411. *
  412. * @return int
  413. */
  414. public function getPaymentsSum(SchoolYear $year)
  415. {
  416. $sum = 0;
  417. foreach ($this->payments as $p) {
  418. if($p->getSchoolYear() == $year){
  419. $sum += $p->getAmount();
  420. }
  421. }
  422. return $sum;
  423. }
  424. /**
  425. * Set birthday
  426. *
  427. * @param \DateTime $birthday
  428. *
  429. * @return Student
  430. */
  431. public function setBirthday($birthday)
  432. {
  433. $this->birthday = $birthday;
  434. return $this;
  435. }
  436. /**
  437. * Get birthday
  438. *
  439. * @return \DateTime
  440. */
  441. public function getBirthday()
  442. {
  443. return $this->birthday;
  444. }
  445. /**
  446. * Set firstname
  447. *
  448. * @param string $firstname
  449. *
  450. * @return Student
  451. */
  452. public function setFirstname($firstname)
  453. {
  454. $this->firstname = $firstname;
  455. return $this;
  456. }
  457. /**
  458. * Get firstname
  459. *
  460. * @return string
  461. */
  462. public function getFirstname()
  463. {
  464. return $this->firstname;
  465. }
  466. /**
  467. * Set lastname
  468. *
  469. * @param string $lastname
  470. *
  471. * @return Student
  472. */
  473. public function setLastname($lastname)
  474. {
  475. $this->lastname = $lastname;
  476. return $this;
  477. }
  478. /**
  479. * Get lastname
  480. *
  481. * @return string
  482. */
  483. public function getLastname()
  484. {
  485. return $this->lastname;
  486. }
  487. /**
  488. * Constructor
  489. */
  490. public function __construct()
  491. {
  492. $this->setEnrolled(false);
  493. $this->marks = new \Doctrine\Common\Collections\ArrayCollection();
  494. $this->subscriptions = new \Doctrine\Common\Collections\ArrayCollection();
  495. $this->payments = new ArrayCollection();
  496. }
  497. public function addMark(Mark $mark)
  498. {
  499. $this->marks[] = $mark;
  500. return $this;
  501. }
  502. public function removeMark(Mark $mark)
  503. {
  504. $this->marks->removeElement($mark);
  505. }
  506. /**
  507. * Get marks
  508. *
  509. * @return \Doctrine\Common\Collections\Collection
  510. */
  511. public function getMarks()
  512. {
  513. return $this->marks;
  514. }
  515. /**
  516. * Set profileImagePath
  517. *
  518. * @param string $profileImagePath
  519. *
  520. * @return Student
  521. */
  522. public function setProfileImagePath($profileImagePath)
  523. {
  524. $this->profileImagePath = $profileImagePath;
  525. return $this;
  526. }
  527. /**
  528. * Get profileImagePath
  529. *
  530. * @return string
  531. */
  532. public function getProfileImagePath()
  533. {
  534. return $this->profileImagePath;
  535. }
  536. /**
  537. * Set residence
  538. *
  539. * @param string $residence
  540. *
  541. * @return Student
  542. */
  543. public function setResidence($residence)
  544. {
  545. $this->residence = $residence;
  546. return $this;
  547. }
  548. /**
  549. * Get residence
  550. *
  551. * @return string
  552. */
  553. public function getResidence()
  554. {
  555. return $this->residence;
  556. }
  557. /**
  558. * @return Collection|Subscription[]
  559. */
  560. public function getSubscriptions(): Collection
  561. {
  562. return $this->subscriptions;
  563. }
  564. public function addSubscription(Subscription $subscription): self
  565. {
  566. if (!$this->subscriptions->contains($subscription)) {
  567. $this->subscriptions[] = $subscription;
  568. $subscription->setStudent($this);
  569. }
  570. return $this;
  571. }
  572. public function removeSubscription(Subscription $subscription): self
  573. {
  574. if ($this->subscriptions->removeElement($subscription)) {
  575. // set the owning side to null (unless already changed)
  576. if ($subscription->getStudent() === $this) {
  577. $subscription->setStudent(null);
  578. }
  579. }
  580. return $this;
  581. }
  582. /**
  583. * Set enrolled
  584. *
  585. * @param boolean $enrolled
  586. *
  587. * @return Student
  588. */
  589. public function setEnrolled($enrolled)
  590. {
  591. $this->enrolled = $enrolled;
  592. return $this;
  593. }
  594. /**
  595. * Get enrolled
  596. *
  597. * @return boolean
  598. */
  599. public function getEnrolled()
  600. {
  601. return $this->enrolled;
  602. }
  603. public function addPayment(Payment $payment)
  604. {
  605. $this->payments[] = $payment;
  606. return $this;
  607. }
  608. public function removePayment(Payment $payment)
  609. {
  610. $this->payments->removeElement($payment);
  611. }
  612. /**
  613. * Get payments
  614. *
  615. * @return \Doctrine\Common\Collections\Collection
  616. */
  617. public function getPayments()
  618. {
  619. return $this->payments;
  620. }
  621. public function isEnrolled(): ?bool
  622. {
  623. return $this->enrolled;
  624. }
  625. public function getEntryClass(): ?ClassRoom
  626. {
  627. return $this->entryClass;
  628. }
  629. public function setEntryClass(?ClassRoom $entryClass): static
  630. {
  631. $this->entryClass = $entryClass;
  632. return $this;
  633. }
  634. }