EducationNotationConfig.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php
  2. declare (strict_types=1);
  3. namespace App\Entity\Education;
  4. use ApiPlatform\Metadata\GetCollection;
  5. use ApiPlatform\Metadata\Put;
  6. use ApiPlatform\Metadata\Get;
  7. use ApiPlatform\Metadata\ApiResource;
  8. use App\Attribute\OrganizationDefaultValue;
  9. use App\Entity\Access\Access;
  10. use App\Repository\Education\EducationNotationConfigRepository;
  11. use App\Entity\Organization\Organization;
  12. //use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
  13. use Doctrine\Common\Collections\ArrayCollection;
  14. use Doctrine\Common\Collections\Collection;
  15. use Doctrine\ORM\Mapping as ORM;
  16. use JetBrains\PhpStorm\Pure;
  17. use Symfony\Component\Validator\Constraints as Assert;
  18. /**
  19. * Configuration des grilles d'évaluation
  20. */
  21. #[ApiResource(
  22. operations: [
  23. new Get(
  24. security: 'is_granted(\'ROLE_PEDAGOGICS_ADMINISTRATION_VIEW\') and object.getOrganization().getId() == user.getOrganization().getId()'
  25. ),
  26. new Put(
  27. security: 'object.getOrganization().getId() == user.getOrganization().getId()'
  28. ),
  29. new GetCollection(
  30. security: 'is_granted(\'ROLE_PEDAGOGICS_ADMINISTRATION_VIEW\')'
  31. )
  32. ],
  33. security: 'is_granted(\'ROLE_PEDAGOGICS_ADMINISTRATION\')'
  34. )]
  35. //#[Auditable]
  36. #[ORM\Entity(repositoryClass: EducationNotationConfigRepository::class)]
  37. #[OrganizationDefaultValue(fieldName: "organization")]
  38. class EducationNotationConfig
  39. {
  40. #[ORM\Id]
  41. #[ORM\Column]
  42. #[ORM\GeneratedValue]
  43. private ?int $id = null;
  44. #[ORM\ManyToOne(inversedBy: 'educationNotationConfigs')]
  45. #[ORM\JoinColumn(nullable: false)]
  46. private Organization $organization;
  47. #[ORM\Column(length: 255)]
  48. private string $label;
  49. #[ORM\Column(options: ['default' => true])]
  50. private bool $isActive = true;
  51. #[ORM\Column(type: 'text', nullable: true)]
  52. private ?string $description;
  53. #[ORM\Column(options: ['default' => 1])]
  54. #[Assert\Range(notInRangeMessage: 'between_{{ min }}_and_{{ max }}', min: 1, max: 10)]
  55. private int $coefficient = 1;
  56. #[ORM\OneToMany(mappedBy: 'educationNotationConfig', targetEntity: Access::class)]
  57. private Collection $teachers;
  58. #[ORM\OneToMany(mappedBy: 'educationNotationConfig', targetEntity: EducationCurriculum::class)]
  59. private Collection $educationCurriculums;
  60. #[ORM\OneToMany(mappedBy: 'educationNotationConfig', targetEntity: EducationNotationCriteriaConfig::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
  61. private Collection $educationNotationCriteriaConfigs;
  62. #[Pure]
  63. public function __construct()
  64. {
  65. $this->teachers = new ArrayCollection();
  66. $this->educationCurriculums = new ArrayCollection();
  67. $this->educationNotationCriteriaConfigs = new ArrayCollection();
  68. }
  69. public function getId(): ?int
  70. {
  71. return $this->id;
  72. }
  73. public function setOrganization(Organization $organization): self
  74. {
  75. $this->organization = $organization;
  76. return $this;
  77. }
  78. public function getOrganization(): Organization
  79. {
  80. return $this->organization;
  81. }
  82. public function setLabel(string $label): self
  83. {
  84. $this->label = $label;
  85. return $this;
  86. }
  87. public function getLabel(): string
  88. {
  89. return $this->label;
  90. }
  91. public function setIsActive(bool $isActive): self
  92. {
  93. $this->isActive = $isActive;
  94. return $this;
  95. }
  96. public function getIsActive(): bool
  97. {
  98. return $this->isActive;
  99. }
  100. public function setDescription(?string $description): self
  101. {
  102. $this->description = $description;
  103. return $this;
  104. }
  105. public function getDescription(): ?string
  106. {
  107. return $this->description;
  108. }
  109. public function setCoefficient(?int $coefficient): self
  110. {
  111. if ($coefficient === null) {
  112. $coefficient = 1;
  113. }
  114. $this->coefficient = $coefficient;
  115. return $this;
  116. }
  117. public function getCoefficient(): int
  118. {
  119. return $this->coefficient;
  120. }
  121. public function addTeacher(Access $teacher): self
  122. {
  123. if (!$this->teachers->contains($teacher)) {
  124. $this->teachers[] = $teacher;
  125. $teacher->setEducationNotationConfig($this);
  126. }
  127. return $this;
  128. }
  129. public function removeTeacher(Access $teacher): self
  130. {
  131. if ($this->teachers->removeElement($teacher)) {
  132. // set the owning side to null (unless already changed)
  133. if ($teacher->getEducationNotationConfig() === $this) {
  134. $teacher->setEducationNotationConfig(null);
  135. }
  136. }
  137. return $this;
  138. }
  139. public function getTeachers(): Collection
  140. {
  141. return $this->teachers;
  142. }
  143. public function addEducationCurriculum(EducationCurriculum $educationCurriculums): self
  144. {
  145. if (!$this->educationCurriculums->contains($educationCurriculums)) {
  146. $this->educationCurriculums[] = $educationCurriculums;
  147. $educationCurriculums->setEducationNotationConfig($this);
  148. }
  149. return $this;
  150. }
  151. public function removeEducationCurriculum(EducationCurriculum $educationCurriculums): self
  152. {
  153. if ($this->educationCurriculums->removeElement($educationCurriculums)) {
  154. // set the owning side to null (unless already changed)
  155. if ($educationCurriculums->getEducationNotationConfig() === $this) {
  156. $educationCurriculums->setEducationNotationConfig(null);
  157. }
  158. }
  159. return $this;
  160. }
  161. public function getEducationCurriculums(): Collection
  162. {
  163. return $this->educationCurriculums;
  164. }
  165. /**
  166. * @return Collection<int, EducationNotationCriteriaConfig>
  167. */
  168. public function getEducationNotationCriteriaConfigs(): Collection
  169. {
  170. return $this->educationNotationCriteriaConfigs;
  171. }
  172. public function addEducationNotationCriteriaConfig(EducationNotationCriteriaConfig $educationNotationCriteriaConfig): self
  173. {
  174. if (!$this->educationNotationCriteriaConfigs->contains($educationNotationCriteriaConfig)) {
  175. $this->educationNotationCriteriaConfigs[] = $educationNotationCriteriaConfig;
  176. $educationNotationCriteriaConfig->setEducationNotationConfig($this);
  177. }
  178. return $this;
  179. }
  180. public function removeEducationNotationCriteriaConfig(EducationNotationCriteriaConfig $educationNotationCriteriaConfig): self
  181. {
  182. if ($this->educationNotationCriteriaConfigs->removeElement($educationNotationCriteriaConfig)) {
  183. // set the owning side to null (unless already changed)
  184. if ($educationNotationCriteriaConfig->getEducationNotationConfig() === $this) {
  185. $educationNotationCriteriaConfig->setEducationNotationConfig(null);
  186. }
  187. }
  188. return $this;
  189. }
  190. }