Cycle.php 5.1 KB

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