EducationNotation.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Education;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use App\Entity\Billing\ResidenceArea;
  6. use App\Entity\Core\Tagg;
  7. use App\Repository\Education\EducationNotationRepository;
  8. // use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. /**
  14. * Classe ... qui ...
  15. */
  16. #[ApiResource(operations: [])]
  17. // #[Auditable]
  18. #[ORM\Entity(repositoryClass: EducationNotationRepository::class)]
  19. class EducationNotation
  20. {
  21. #[ORM\Id]
  22. #[ORM\Column]
  23. #[ORM\GeneratedValue]
  24. private ?int $id = null;
  25. #[ORM\ManyToOne(inversedBy: 'educationNotations')]
  26. #[ORM\JoinColumn(nullable: false)]
  27. private EducationStudent $educationStudent;
  28. #[ORM\ManyToOne(inversedBy: 'educationNotations')]
  29. #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
  30. private ?CriteriaNotation $criteriaNotation;
  31. #[ORM\ManyToOne(inversedBy: 'educationNotations')]
  32. #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
  33. private ?EducationNotationCriteriaConfig $criteriaNotationConfig;
  34. /** @var Collection<int, Tagg> */
  35. #[ORM\ManyToMany(targetEntity: Tagg::class, inversedBy: 'educationNotations', cascade: ['persist'])]
  36. #[ORM\JoinTable(name: 'tag_educationNotation')]
  37. #[ORM\JoinColumn(name: 'educationNotation_id', referencedColumnName: 'id')]
  38. #[ORM\InverseJoinColumn(name: 'tag_id', referencedColumnName: 'id')]
  39. private Collection $tags;
  40. // @see https://github.com/symfony/symfony/discussions/43599#discussioncomment-1514811
  41. #[ORM\Column(type: 'decimal', precision: 10, scale: 2, nullable: true)]
  42. #[Assert\Range(notInRangeMessage: 'between_{{ min }}_and_{{ max }}', min: 0, max: 100)]
  43. private ?string $note = null;
  44. public function __construct()
  45. {
  46. $this->tags = new ArrayCollection();
  47. }
  48. public function getId(): ?int
  49. {
  50. return $this->id;
  51. }
  52. public function getEducationStudent(): ?EducationStudent
  53. {
  54. return $this->educationStudent;
  55. }
  56. public function setEducationStudent(?EducationStudent $educationStudent): self
  57. {
  58. $this->educationStudent = $educationStudent;
  59. return $this;
  60. }
  61. public function getCriteriaNotation(): ?CriteriaNotation
  62. {
  63. return $this->criteriaNotation;
  64. }
  65. public function setCriteriaNotation(?CriteriaNotation $criteriaNotation): self
  66. {
  67. $this->criteriaNotation = $criteriaNotation;
  68. return $this;
  69. }
  70. public function getCriteriaNotationConfig(): ?EducationNotationCriteriaConfig
  71. {
  72. return $this->criteriaNotationConfig;
  73. }
  74. public function setCriteriaNotationConfig(?EducationNotationCriteriaConfig $criteriaNotationConfig): self
  75. {
  76. $this->criteriaNotationConfig = $criteriaNotationConfig;
  77. return $this;
  78. }
  79. /**
  80. * @return Collection<int, Tagg>
  81. */
  82. public function getTags(): Collection
  83. {
  84. return $this->tags;
  85. }
  86. public function addTag(Tagg $tag): self
  87. {
  88. if (!$this->tags->contains($tag)) {
  89. $this->tags[] = $tag;
  90. }
  91. return $this;
  92. }
  93. public function removeTag(Tagg $tag): self
  94. {
  95. $this->tags->removeElement($tag);
  96. return $this;
  97. }
  98. public function setNote(?float $note): self
  99. {
  100. $this->note = (string)$note;
  101. return $this;
  102. }
  103. public function getNote(): ?float
  104. {
  105. // TODO: pour moi le round il est pas à sa place ici? vaudrait pas mieux le mettre dans le setter?
  106. return !is_null($this->note) ? round((float)$this->note, 2) : null;
  107. }
  108. }