Cycle.php 4.0 KB

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