src/Entity/Course.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Evaluation;
  4. use App\Entity\Attribution;
  5. use App\Entity\SchoolYear;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use App\Repository\CourseRepository;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use App\Repository\AttributionRepository;
  11. use App\Service\SchoolYearService;
  12. use Symfony\Component\DependencyInjection\ContainerInterface;
  13. /**
  14. * @ORM\Entity(repositoryClass=CourseRepository::class)
  15. */
  16. class Course
  17. {
  18. /**
  19. * @ORM\Id
  20. * @ORM\GeneratedValue
  21. * @ORM\Column(type="integer")
  22. */
  23. private $id;
  24. /**
  25. * @ORM\ManyToOne(targetEntity=Domain::class, inversedBy="courses")
  26. * @ORM\JoinColumn(nullable=false)
  27. */
  28. private $domain;
  29. /**
  30. * @ORM\ManyToOne(targetEntity=Module::class, inversedBy="courses")
  31. */
  32. private $module;
  33. /**
  34. * @ORM\Column(type="string", length=255)
  35. */
  36. private $wording;
  37. /**
  38. * @ORM\Column(type="integer")
  39. */
  40. private $coefficient;
  41. /**
  42. * @ORM\Column(type="string", length=255)
  43. */
  44. private $code;
  45. /**
  46. * @ORM\OneToMany(targetEntity=Evaluation::class, mappedBy="course")
  47. */
  48. private $evaluations;
  49. /**
  50. * @ORM\OneToMany(targetEntity=Attribution::class, mappedBy="course",cascade={"persist"})
  51. * @ORM\JoinColumn(nullable=true)
  52. *
  53. * */
  54. private $attributions;
  55. public function __construct()
  56. {
  57. $this->evaluations = new ArrayCollection();
  58. $this->attributions = new ArrayCollection();
  59. }
  60. public function getId(): ?int
  61. {
  62. return $this->id;
  63. }
  64. public function __toString()
  65. {
  66. $domain = (is_null($this->getDomain())) ? "" : $this->getDomain();
  67. $wording = (is_null($this->getWording())) ? "" : $this->getWording();
  68. $code = (is_null($this->getCode())) ? "" : $this->getCode();
  69. return (string) ($domain . "/" . $code . "_" . $wording);
  70. }
  71. public function getCoefficient(): ?int
  72. {
  73. return $this->coefficient;
  74. }
  75. public function setCoefficient(int $coefficient): self
  76. {
  77. $this->coefficient = $coefficient;
  78. return $this;
  79. }
  80. public function getDomain(): ?Domain
  81. {
  82. return $this->domain;
  83. }
  84. public function setDomain(?Domain $domain): self
  85. {
  86. $this->domain = $domain;
  87. return $this;
  88. }
  89. public function getModule(): ?Module
  90. {
  91. return $this->module;
  92. }
  93. public function setModule(?Module $module): self
  94. {
  95. $this->module = $module;
  96. return $this;
  97. }
  98. public function getWording(): ?string
  99. {
  100. return $this->wording;
  101. }
  102. public function setWording(string $wording): self
  103. {
  104. $this->wording = $wording;
  105. return $this;
  106. }
  107. public function getCode(): ?string
  108. {
  109. return $this->code;
  110. }
  111. public function setCode(string $code): self
  112. {
  113. $this->code = $code;
  114. return $this;
  115. }
  116. public function getCurrentTeacher(AttributionRepository $attRepo, SchoolYear $year) {
  117. $attribution = $attRepo->findOneBy(array("course" => $this, "schoolYear"=> $year));
  118. return $attribution==null ? false : $attribution->getTeacher();
  119. }
  120. /**
  121. * @return Collection|Evaluation[]
  122. */
  123. public function getEvaluations(): Collection
  124. {
  125. return $this->evaluations;
  126. }
  127. public function addEvaluation(Evaluation $evaluation): self
  128. {
  129. if (!$this->evaluations->contains($evaluation)) {
  130. $this->evaluations[] = $evaluation;
  131. $evaluation->setCourse($this);
  132. }
  133. return $this;
  134. }
  135. public function removeEvaluation(Evaluation $evaluation): self
  136. {
  137. if ($this->evaluations->removeElement($evaluation)) {
  138. // set the owning side to null (unless already changed)
  139. if ($evaluation->getCourse() === $this) {
  140. $evaluation->setCourse(null);
  141. }
  142. }
  143. return $this;
  144. }
  145. public function addAttribution(Attribution $attribution)
  146. {
  147. $this->attributions[] = $attribution;
  148. return $this;
  149. }
  150. public function removeAttribution(Attribution $attribution)
  151. {
  152. $this->attributions->removeElement($attribution);
  153. }
  154. /**
  155. * Get attributions
  156. *
  157. * @return \Doctrine\Common\Collections\Collection
  158. */
  159. public function getAttributions()
  160. {
  161. return $this->attributions;
  162. }
  163. }