src/Entity/Student.php line 25

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