Cycle.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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\Repository\Education\CycleRepository;
  9. use App\Entity\Organization\Organization;
  10. //use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. use Doctrine\Common\Collections\Collection;
  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. #[ApiResource(operations: [])] // @see App\Doctrine\Education\CurrentCycleExtension
  20. //#[Auditable]
  21. #[ORM\Entity(repositoryClass: CycleRepository::class)]
  22. class Cycle
  23. {
  24. #[ORM\Id]
  25. #[ORM\Column]
  26. #[ORM\GeneratedValue]
  27. private ?int $id = null;
  28. #[ORM\ManyToOne(inversedBy: 'cycles')]
  29. #[ORM\JoinColumn(nullable: false)]
  30. private Organization $organization;
  31. #[ORM\Column(nullable: true)]
  32. private ?int $order = null;
  33. #[ORM\Column(length: 255)]
  34. private string $label;
  35. #[ORM\Column(length: 255)]
  36. #[Assert\Choice(callback: ['\\App\\Enum\\Education\\CycleEnum', 'toArray'], message: 'invalid-cycle')]
  37. private string $cycleEnum;
  38. #[ORM\Column(options: ['default' => false])]
  39. private bool $isSystem = false;
  40. #[ORM\OneToMany(mappedBy: 'cycle', targetEntity: CycleByEducation::class, orphanRemoval: true)]
  41. private Collection $cycleByEducations;
  42. public function __construct()
  43. {
  44. $this->cycleByEducations = new ArrayCollection();
  45. }
  46. public function getId(): ?int
  47. {
  48. return $this->id;
  49. }
  50. public function setOrganization(?Organization $organization): self
  51. {
  52. $this->organization = $organization;
  53. return $this;
  54. }
  55. public function getOrganization(): Organization
  56. {
  57. return $this->organization;
  58. }
  59. public function setOrder(?int $order): self
  60. {
  61. $this->order = $order;
  62. return $this;
  63. }
  64. public function getOrder(): ?int
  65. {
  66. return $this->order;
  67. }
  68. public function setLabel(string $label): self
  69. {
  70. $this->label = $label;
  71. return $this;
  72. }
  73. public function getLabel(): string
  74. {
  75. return $this->label;
  76. }
  77. public function setCycleEnum(string $cycleEnum): self
  78. {
  79. $this->cycleEnum = $cycleEnum;
  80. return $this;
  81. }
  82. public function getCycleEnum(): string
  83. {
  84. return $this->cycleEnum;
  85. }
  86. public function setIsSystem(bool $isSystem): self
  87. {
  88. $this->isSystem = $isSystem;
  89. return $this;
  90. }
  91. public function getIsSystem(): bool
  92. {
  93. return $this->isSystem;
  94. }
  95. /**
  96. * @return Collection<int, CycleByEducation>
  97. */
  98. public function getCycleByEducations(): Collection
  99. {
  100. return $this->cycleByEducations;
  101. }
  102. public function addCycleByEducation(CycleByEducation $cycleByEducation): self
  103. {
  104. if (!$this->cycleByEducations->contains($cycleByEducation)) {
  105. $this->cycleByEducations[] = $cycleByEducation;
  106. $cycleByEducation->setCycle($this);
  107. }
  108. return $this;
  109. }
  110. public function removeCycleByEducation(CycleByEducation $cycleByEducation): self
  111. {
  112. if ($this->cycleByEducations->removeElement($cycleByEducation)) {
  113. // set the owning side to null (unless already changed)
  114. if ($cycleByEducation->getCycle() === $this) {
  115. $cycleByEducation->setCycle(null);
  116. }
  117. }
  118. return $this;
  119. }
  120. }