Cycle.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Education;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\GetCollection;
  7. use ApiPlatform\Metadata\Patch;
  8. use ApiPlatform\Metadata\Put;
  9. use App\Entity\Organization\Organization;
  10. use App\Enum\Education\CycleEnum;
  11. use App\Repository\Education\CycleRepository;
  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. /**
  17. * Enum des cycles éducatifs, utilisés par les EducationCurriculum
  18. * NB: le nombre de cycles est fixé à 6, mais chaque Organization peut en modifier le label.
  19. *
  20. * Security :
  21. *
  22. * * @see App\Doctrine\Education\CurrentCycleExtension
  23. */
  24. #[ApiResource(
  25. operations: [
  26. new Get(
  27. security: 'is_granted(\'ROLE_ORGANIZATION_VIEW\') and object.getOrganization().getId() == user.getOrganization().getId()'
  28. ),
  29. new Patch(
  30. security: 'is_granted(\'ROLE_ORGANIZATION\') and object.getOrganization().getId() == user.getOrganization().getId()'
  31. ),
  32. new GetCollection(
  33. security: 'is_granted(\'ROLE_ORGANIZATION_VIEW\')'
  34. ),
  35. ]
  36. )]
  37. #[Auditable]
  38. #[ORM\Entity(repositoryClass: CycleRepository::class)]
  39. class Cycle
  40. {
  41. #[ORM\Id]
  42. #[ORM\Column]
  43. #[ORM\GeneratedValue]
  44. private ?int $id = null;
  45. #[ORM\ManyToOne(inversedBy: 'cycles')]
  46. #[ORM\JoinColumn(nullable: false)]
  47. private Organization $organization;
  48. #[ORM\Column(name: '`order`', nullable: true)]
  49. private ?int $order = null;
  50. #[ORM\Column(length: 255)]
  51. private string $label;
  52. #[ORM\Column(length: 50, enumType: CycleEnum::class)]
  53. private CycleEnum $cycleEnum;
  54. #[ORM\Column(options: ['default' => false])]
  55. private bool $isSystem = false;
  56. /** @var Collection<int, CycleByEducation> */
  57. #[ORM\OneToMany(targetEntity: CycleByEducation::class, mappedBy: 'cycle', orphanRemoval: true)]
  58. private Collection $cycleByEducations;
  59. /** @var Collection<int, EducationCurriculum> */
  60. #[ORM\OneToMany(targetEntity: EducationCurriculum::class, mappedBy: 'cycle', cascade: [], orphanRemoval: false)]
  61. protected Collection $educationCurriculums;
  62. public function __construct()
  63. {
  64. $this->cycleByEducations = new ArrayCollection();
  65. $this->educationCurriculums = new ArrayCollection();
  66. }
  67. public function getId(): ?int
  68. {
  69. return $this->id;
  70. }
  71. public function setOrganization(?Organization $organization): self
  72. {
  73. $this->organization = $organization;
  74. return $this;
  75. }
  76. public function getOrganization(): Organization
  77. {
  78. return $this->organization;
  79. }
  80. public function setOrder(?int $order): self
  81. {
  82. $this->order = $order;
  83. return $this;
  84. }
  85. public function getOrder(): ?int
  86. {
  87. return $this->order;
  88. }
  89. public function setLabel(string $label): self
  90. {
  91. $this->label = $label;
  92. return $this;
  93. }
  94. public function getLabel(): string
  95. {
  96. return $this->label;
  97. }
  98. public function setCycleEnum(CycleEnum $cycleEnum): self
  99. {
  100. $this->cycleEnum = $cycleEnum;
  101. return $this;
  102. }
  103. public function getCycleEnum(): CycleEnum
  104. {
  105. return $this->cycleEnum;
  106. }
  107. public function setIsSystem(bool $isSystem): self
  108. {
  109. $this->isSystem = $isSystem;
  110. return $this;
  111. }
  112. public function getIsSystem(): bool
  113. {
  114. return $this->isSystem;
  115. }
  116. /**
  117. * @return Collection<int, CycleByEducation>
  118. */
  119. public function getCycleByEducations(): Collection
  120. {
  121. return $this->cycleByEducations;
  122. }
  123. public function addCycleByEducation(CycleByEducation $cycleByEducation): self
  124. {
  125. if (!$this->cycleByEducations->contains($cycleByEducation)) {
  126. $this->cycleByEducations[] = $cycleByEducation;
  127. $cycleByEducation->setCycle($this);
  128. }
  129. return $this;
  130. }
  131. public function removeCycleByEducation(CycleByEducation $cycleByEducation): self
  132. {
  133. if ($this->cycleByEducations->removeElement($cycleByEducation)) {
  134. // set the owning side to null (unless already changed)
  135. if ($cycleByEducation->getCycle() === $this) {
  136. $cycleByEducation->setCycle(null);
  137. }
  138. }
  139. return $this;
  140. }
  141. public function getEducationCurriculums(): Collection
  142. {
  143. return $this->educationCurriculums;
  144. }
  145. public function addEducationCurriculum(EducationCurriculum $educationCurriculum): self
  146. {
  147. if (!$this->educationCurriculums->contains($educationCurriculum)) {
  148. $this->educationCurriculums[] = $educationCurriculum;
  149. $educationCurriculum->setCycle($this);
  150. }
  151. return $this;
  152. }
  153. public function removeEducationCurriculum(EducationCurriculum $educationCurriculum): self
  154. {
  155. if ($this->educationCurriculums->removeElement($educationCurriculum)) {
  156. $educationCurriculum->setCycle(null);
  157. }
  158. return $this;
  159. }
  160. }