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\ManyToOne(targetEntity=ClassRoom::class)
  134. * @ORM\JoinColumn(nullable=true)
  135. */
  136. private $entryClass;
  137. /**
  138. * Get updated
  139. *
  140. * @return \DateTime
  141. */
  142. public function getUpdated()
  143. {
  144. return $this->updated;
  145. }
  146. public function getId(): ?int
  147. {
  148. return $this->id;
  149. }
  150. /**
  151. *
  152. * @return string
  153. */
  154. public function __toString()
  155. {
  156. $lastname = (is_null($this->getLastName())) ? "" : $this->getLastName();
  157. $firstname = (is_null($this->getFirstName())) ? "" : $this->getFirstName();
  158. $matricule = (is_null($this->getMatricule())) ? "" : $this->getMatricule();
  159. return $lastname . " " . $firstname . " " . $matricule;
  160. }
  161. /**
  162. *
  163. * @return string
  164. */
  165. public function fullName()
  166. {
  167. $lastname = (is_null($this->getLastName())) ? "" : $this->getLastName();
  168. $firstname = (is_null($this->getFirstName())) ? "" : $this->getFirstName();
  169. return $lastname . " " . $firstname ;
  170. }
  171. /**
  172. * Set matricule
  173. *
  174. * @param string $matricule
  175. *
  176. * @return Student
  177. */
  178. public function setMatricule($matricule)
  179. {
  180. $this->matricule = $matricule;
  181. return $this;
  182. }
  183. /**
  184. * Get matricule
  185. *
  186. * @return string
  187. */
  188. public function getMatricule()
  189. {
  190. return $this->matricule;
  191. }
  192. /**
  193. * Set particularDisease
  194. *
  195. * @param string $particularDisease
  196. *
  197. * @return Student
  198. */
  199. public function setParticularDisease($particularDisease)
  200. {
  201. $this->particularDisease = $particularDisease;
  202. return $this;
  203. }
  204. /**
  205. * Get particularDisease
  206. *
  207. * @return string
  208. */
  209. public function getParticularDisease()
  210. {
  211. return $this->particularDisease;
  212. }
  213. /**
  214. * Set fatherName
  215. *
  216. * @param string $fatherName
  217. *
  218. * @return Student
  219. */
  220. public function setFatherName($fatherName)
  221. {
  222. $this->fatherName = $fatherName;
  223. return $this;
  224. }
  225. /**
  226. * Get fatherName
  227. *
  228. * @return string
  229. */
  230. public function getFatherName()
  231. {
  232. return $this->fatherName;
  233. }
  234. /**
  235. * Set motherName
  236. *
  237. * @param string $motherName
  238. *
  239. * @return Student
  240. */
  241. public function setMotherName($motherName)
  242. {
  243. $this->motherName = $motherName;
  244. return $this;
  245. }
  246. /**
  247. * Get motherName
  248. *
  249. * @return string
  250. */
  251. public function getMotherName()
  252. {
  253. return $this->motherName;
  254. }
  255. /**
  256. * Set primaryContact
  257. *
  258. * @param string $primaryContact
  259. *
  260. * @return Student
  261. */
  262. public function setPrimaryContact($primaryContact)
  263. {
  264. $this->primaryContact = $primaryContact;
  265. return $this;
  266. }
  267. /**
  268. * Get primaryContact
  269. *
  270. * @return string
  271. */
  272. public function getPrimaryContact()
  273. {
  274. return $this->primaryContact;
  275. }
  276. /**
  277. * Set secondaryContact
  278. *
  279. * @param string $secondaryContact
  280. *
  281. * @return Student
  282. */
  283. public function setSecondaryContact($secondaryContact)
  284. {
  285. $this->secondaryContact = $secondaryContact;
  286. return $this;
  287. }
  288. /**
  289. * Get secondaryContact
  290. *
  291. * @return string
  292. */
  293. public function getSecondaryContact()
  294. {
  295. return $this->secondaryContact;
  296. }
  297. /**
  298. * Set otherInformations
  299. *
  300. * @param string $otherInformations
  301. *
  302. * @return Student
  303. */
  304. public function setOtherInformations($otherInformations)
  305. {
  306. $this->otherInformations = $otherInformations;
  307. return $this;
  308. }
  309. /**
  310. * Get otherInformations
  311. *
  312. * @return string
  313. */
  314. public function getOtherInformations()
  315. {
  316. return $this->otherInformations;
  317. }
  318. /**
  319. * Set gender
  320. *
  321. * @param string $gender
  322. *
  323. * @return Student
  324. */
  325. public function setGender($gender)
  326. {
  327. $this->gender = $gender;
  328. return $this;
  329. }
  330. /**
  331. * Get gender
  332. *
  333. * @return string
  334. */
  335. public function getGender()
  336. {
  337. return $this->gender;
  338. }
  339. /**
  340. * Set birthplace
  341. *
  342. * @param string $birthplace
  343. *
  344. * @return Student
  345. */
  346. public function setBirthplace($birthplace)
  347. {
  348. $this->birthplace = $birthplace;
  349. return $this;
  350. }
  351. /**
  352. * Get birthplace
  353. *
  354. * @return string
  355. */
  356. public function getBirthplace()
  357. {
  358. return $this->birthplace;
  359. }
  360. /**
  361. * Set level
  362. *
  363. * @param \AppBundle\Entity\Level $level
  364. *
  365. * @return Student
  366. */
  367. public function setLevel(Level $level)
  368. {
  369. $this->level = $level;
  370. return $this;
  371. }
  372. /**
  373. * Get level
  374. *
  375. * @return \AppBundle\Entity\Level
  376. */
  377. public function getLevel()
  378. {
  379. return $this->level;
  380. }
  381. /**
  382. * Set updated
  383. *
  384. * @param \DateTime $updated
  385. *
  386. * @return Student
  387. */
  388. public function setUpdated($updated)
  389. {
  390. $this->updated = $updated;
  391. return $this;
  392. }
  393. /**
  394. * Class where the student is enrolled in a given school year
  395. *
  396. * @return ClassRoom
  397. */
  398. public function getClassRoom(SchoolYear $year)
  399. {
  400. $subscribtion = $em->getRepository('AppBundle:Subscription')->findBy(array('schoolYear' => $year, 'student' => $std));
  401. return $subscribtion->getClassRoom();
  402. }
  403. /**
  404. * Tuition fees already paid by the student in a given school year
  405. *
  406. * @return int
  407. */
  408. public function getPaymentsSum(SchoolYear $year)
  409. {
  410. $sum = 0;
  411. foreach ($this->payments as $p) {
  412. if($p->getSchoolYear() == $year){
  413. $sum += $p->getAmount();
  414. }
  415. }
  416. return $sum;
  417. }
  418. /**
  419. * Set birthday
  420. *
  421. * @param \DateTime $birthday
  422. *
  423. * @return Student
  424. */
  425. public function setBirthday($birthday)
  426. {
  427. $this->birthday = $birthday;
  428. return $this;
  429. }
  430. /**
  431. * Get birthday
  432. *
  433. * @return \DateTime
  434. */
  435. public function getBirthday()
  436. {
  437. return $this->birthday;
  438. }
  439. /**
  440. * Set firstname
  441. *
  442. * @param string $firstname
  443. *
  444. * @return Student
  445. */
  446. public function setFirstname($firstname)
  447. {
  448. $this->firstname = $firstname;
  449. return $this;
  450. }
  451. /**
  452. * Get firstname
  453. *
  454. * @return string
  455. */
  456. public function getFirstname()
  457. {
  458. return $this->firstname;
  459. }
  460. /**
  461. * Set lastname
  462. *
  463. * @param string $lastname
  464. *
  465. * @return Student
  466. */
  467. public function setLastname($lastname)
  468. {
  469. $this->lastname = $lastname;
  470. return $this;
  471. }
  472. /**
  473. * Get lastname
  474. *
  475. * @return string
  476. */
  477. public function getLastname()
  478. {
  479. return $this->lastname;
  480. }
  481. /**
  482. * Constructor
  483. */
  484. public function __construct()
  485. {
  486. $this->setEnrolled(false);
  487. $this->marks = new \Doctrine\Common\Collections\ArrayCollection();
  488. $this->subscriptions = new \Doctrine\Common\Collections\ArrayCollection();
  489. $this->payments = new ArrayCollection();
  490. }
  491. public function addMark(Mark $mark)
  492. {
  493. $this->marks[] = $mark;
  494. return $this;
  495. }
  496. public function removeMark(Mark $mark)
  497. {
  498. $this->marks->removeElement($mark);
  499. }
  500. /**
  501. * Get marks
  502. *
  503. * @return \Doctrine\Common\Collections\Collection
  504. */
  505. public function getMarks()
  506. {
  507. return $this->marks;
  508. }
  509. /**
  510. * Set profileImagePath
  511. *
  512. * @param string $profileImagePath
  513. *
  514. * @return Student
  515. */
  516. public function setProfileImagePath($profileImagePath)
  517. {
  518. $this->profileImagePath = $profileImagePath;
  519. return $this;
  520. }
  521. /**
  522. * Get profileImagePath
  523. *
  524. * @return string
  525. */
  526. public function getProfileImagePath()
  527. {
  528. return $this->profileImagePath;
  529. }
  530. /**
  531. * Set residence
  532. *
  533. * @param string $residence
  534. *
  535. * @return Student
  536. */
  537. public function setResidence($residence)
  538. {
  539. $this->residence = $residence;
  540. return $this;
  541. }
  542. /**
  543. * Get residence
  544. *
  545. * @return string
  546. */
  547. public function getResidence()
  548. {
  549. return $this->residence;
  550. }
  551. /**
  552. * @return Collection|Subscription[]
  553. */
  554. public function getSubscriptions(): Collection
  555. {
  556. return $this->subscriptions;
  557. }
  558. public function addSubscription(Subscription $subscription): self
  559. {
  560. if (!$this->subscriptions->contains($subscription)) {
  561. $this->subscriptions[] = $subscription;
  562. $subscription->setStudent($this);
  563. }
  564. return $this;
  565. }
  566. public function removeSubscription(Subscription $subscription): self
  567. {
  568. if ($this->subscriptions->removeElement($subscription)) {
  569. // set the owning side to null (unless already changed)
  570. if ($subscription->getStudent() === $this) {
  571. $subscription->setStudent(null);
  572. }
  573. }
  574. return $this;
  575. }
  576. /**
  577. * Set enrolled
  578. *
  579. * @param boolean $enrolled
  580. *
  581. * @return Student
  582. */
  583. public function setEnrolled($enrolled)
  584. {
  585. $this->enrolled = $enrolled;
  586. return $this;
  587. }
  588. /**
  589. * Get enrolled
  590. *
  591. * @return boolean
  592. */
  593. public function getEnrolled()
  594. {
  595. return $this->enrolled;
  596. }
  597. public function addPayment(Payment $payment)
  598. {
  599. $this->payments[] = $payment;
  600. return $this;
  601. }
  602. public function removePayment(Payment $payment)
  603. {
  604. $this->payments->removeElement($payment);
  605. }
  606. /**
  607. * Get payments
  608. *
  609. * @return \Doctrine\Common\Collections\Collection
  610. */
  611. public function getPayments()
  612. {
  613. return $this->payments;
  614. }
  615. public function isEnrolled(): ?bool
  616. {
  617. return $this->enrolled;
  618. }
  619. public function getEntryClass(): ?ClassRoom
  620. {
  621. return $this->entryClass;
  622. }
  623. public function setEntryClass(?ClassRoom $entryClass): static
  624. {
  625. $this->entryClass = $entryClass;
  626. return $this;
  627. }
  628. }