src/Entity/Subscription.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Student;
  4. use App\Repository\SubscriptionRepository;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use App\Entity\Traits\TimeStampable;
  7. use App\Entity\Traits\Amount;
  8. /**
  9. * @ORM\Entity(repositoryClass=SubscriptionRepository::class)
  10. */
  11. class Subscription
  12. {
  13. public const NUM_ITEMS_PER_PAGE = 20;
  14. use TimeStampable;
  15. use Amount;
  16. /**
  17. * @ORM\Id
  18. * @ORM\GeneratedValue
  19. * @ORM\Column(type="integer")
  20. */
  21. private $id;
  22. /**
  23. * @ORM\ManyToOne(targetEntity=Student::class, inversedBy="subscriptions")
  24. * @ORM\JoinColumn(nullable=false)
  25. */
  26. private $student;
  27. /**
  28. * @ORM\ManyToOne(targetEntity=ClassRoom::class, inversedBy="subscriptions")
  29. * @ORM\JoinColumn(nullable=false)
  30. */
  31. private $classRoom;
  32. /**
  33. * @ORM\ManyToOne(targetEntity=SchoolYear::class, inversedBy="subscriptions")
  34. * @ORM\JoinColumn(nullable=false)
  35. */
  36. private $schoolYear;
  37. /*
  38. 0 : Echec
  39. 1p : Success Passable
  40. 1a : Success Assez-bien
  41. 1b : Success Bien
  42. 1t : Success Tres-Bien
  43. 1e : Success Excellent
  44. A : 5 points
  45. B : 4 points
  46. C : 3 points
  47. D : 2 points
  48. E : 1 point
  49. */
  50. /**
  51. * @var string
  52. *
  53. * @ORM\Column(name="officialExamResult", type="string", length=10 , options={"default" = "1p"})
  54. */
  55. private $officialExamResult;
  56. /**
  57. * @ORM\Column(type="integer", options={"default":0})
  58. */
  59. private $discount;
  60. public function __construct()
  61. {
  62. $this->updateTimestamp();
  63. $this->setOfficialExamResult("1p");
  64. $this->setDiscount(0);
  65. $this->setAmount(0);
  66. }
  67. public function getId(): ?int
  68. {
  69. return $this->id;
  70. }
  71. public function getStudent(): ?Student
  72. {
  73. return $this->student;
  74. }
  75. public function setStudent(?Student $student): self
  76. {
  77. $this->student = $student;
  78. return $this;
  79. }
  80. public function getClassRoom(): ?ClassRoom
  81. {
  82. return $this->classRoom;
  83. }
  84. public function setClassRoom(?ClassRoom $classRoom): self
  85. {
  86. $this->classRoom = $classRoom;
  87. return $this;
  88. }
  89. public function getSchoolYear(): ?SchoolYear
  90. {
  91. return $this->schoolYear;
  92. }
  93. public function setSchoolYear(?SchoolYear $schoolYear): self
  94. {
  95. $this->schoolYear = $schoolYear;
  96. return $this;
  97. }
  98. public function getOfficialExamResult(): ?string
  99. {
  100. return $this->officialExamResult;
  101. }
  102. public function getVerbalOfficialExamResult()
  103. {
  104. $result = "PASSABLE";
  105. switch ($this->officialExamResult) {
  106. case "0":
  107. $result = "ECHEC";
  108. break;
  109. case "1p":
  110. $result = "PASSABLE";
  111. break;
  112. case "1a":
  113. $result = "ASSEZ-BIEN";
  114. break;
  115. case "1b":
  116. $result = "BIEN";
  117. break;
  118. case "1t":
  119. $result = "TRES-BIEN";
  120. break;
  121. case "1e":
  122. $result = "EXCELLENT";
  123. break;
  124. case "A":
  125. $result = "5 POINTS";
  126. break;
  127. case "B":
  128. $result = "4 POINTS";
  129. break;
  130. case "C":
  131. $result = "3 POINTS";
  132. break;
  133. case "D":
  134. $result = "2 POINTS";
  135. break;
  136. case "E":
  137. $result = "1 POINTS";
  138. break;
  139. }
  140. return $result;
  141. }
  142. public function setOfficialExamResult(?string $officialExamResult): static
  143. {
  144. $this->officialExamResult = $officialExamResult;
  145. return $this;
  146. }
  147. public function getDiscount(): ?int
  148. {
  149. return $this->discount;
  150. }
  151. public function setDiscount(int $discount): static
  152. {
  153. $this->discount = $discount;
  154. return $this;
  155. }
  156. /**
  157. *
  158. * @return string
  159. */
  160. public function __toString()
  161. {
  162. $student = (is_null($this->getStudent())) ? "" : $this->getStudent();
  163. $year = (is_null($this->getSchoolYear())) ? "" : $this->getSchoolYear();
  164. return $student . " " . $year ;
  165. }
  166. }