EducationNotation.php 3.7 KB

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