Cycle.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Education;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Repository\Education\CycleRepository;
  6. use App\Entity\Organization\Organization;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10. * Enum des cycles éducatifs, utilisés par les EducationCurriculum
  11. * NB: le nombre de cycles est fixé à 6, mais chaque Organization peut en modifier le label
  12. */
  13. #[ApiResource(
  14. collectionOperations: [
  15. "get" => ["security" => "is_granted('ROLE_ORGANIZATION_VIEW')"]
  16. ],
  17. itemOperations: [
  18. "get" => ["security" => "is_granted('ROLE_ORGANIZATION_VIEW') and object.getOrganization().getId() == user.getOrganization().getId()"],
  19. "put" => ["security" => "object.getOrganization().getId() == user.getOrganization().getId()"],
  20. ],
  21. attributes: ["security" => "is_granted('ROLE_ORGANIZATION')"]
  22. )]
  23. #[ORM\Entity(repositoryClass: CycleRepository::class)]
  24. class Cycle
  25. {
  26. #[ORM\Id]
  27. #[ORM\Column]
  28. #[ORM\GeneratedValue]
  29. private ?int $id = null;
  30. #[ORM\ManyToOne(inversedBy: 'cycles')]
  31. private Organization $organization;
  32. #[ORM\Column(nullable: true)]
  33. private ?int $order = null;
  34. #[ORM\Column(length: 255)]
  35. private string $label;
  36. #[ORM\Column(length: 255)]
  37. #[Assert\Choice(callback: ['\App\Enum\Education\CycleEnum', 'toArray'], message: 'invalid-cycle')]
  38. private string $cycleEnum;
  39. #[ORM\Column(options: ['default' => false])]
  40. private bool $isSystem = false;
  41. public function getId() :?int
  42. {
  43. return $this->id;
  44. }
  45. public function setOrganization(Organization $organization): self
  46. {
  47. $this->organization = $organization;
  48. return $this;
  49. }
  50. public function getOrganization(): Organization
  51. {
  52. return $this->organization;
  53. }
  54. public function setOrder(?int $order): self
  55. {
  56. $this->order = $order;
  57. return $this;
  58. }
  59. public function getOrder(): ?int
  60. {
  61. return $this->order;
  62. }
  63. public function setLabel(string $label): self
  64. {
  65. $this->label = $label;
  66. return $this;
  67. }
  68. public function getLabel(): string
  69. {
  70. return $this->label;
  71. }
  72. public function setCycleEnum(string $cycleEnum): self
  73. {
  74. $this->cycleEnum = $cycleEnum;
  75. return $this;
  76. }
  77. public function getCycleEnum(): string
  78. {
  79. return $this->cycleEnum;
  80. }
  81. public function setIsSystem(bool $isSystem): self
  82. {
  83. $this->isSystem = $isSystem;
  84. return $this;
  85. }
  86. public function getIsSystem(): bool
  87. {
  88. return $this->isSystem;
  89. }
  90. }