EducationTiming.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Education;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use ApiPlatform\Metadata\Delete;
  6. use ApiPlatform\Metadata\Get;
  7. use ApiPlatform\Metadata\GetCollection;
  8. use ApiPlatform\Metadata\Post;
  9. use ApiPlatform\Metadata\Put;
  10. use App\Attribute\OrganizationDefaultValue;
  11. use App\Entity\Organization\Organization;
  12. use App\Repository\Education\EducationTimingRepository;
  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. * Temps d'un enseignement.
  19. *
  20. * Security :
  21. *
  22. * @see \App\Doctrine\Education\CurrentEducationTimingExtension
  23. */
  24. #[ApiResource(
  25. operations: [
  26. new Get(
  27. security: 'is_granted(\'ROLE_ORGANIZATION_VIEW\') and object.getOrganization().getId() == user.getOrganization().getId()',
  28. securityMessage: 'You do not have access to this course duration'
  29. ),
  30. new Put(
  31. security: 'object.getOrganization().getId() == user.getOrganization().getId()',
  32. securityMessage: 'You do not have access to this course duration'
  33. ),
  34. new Delete(
  35. security: 'object.getOrganization().getId() == user.getOrganization().getId()',
  36. securityMessage: 'You do not have access to this course duration'
  37. ),
  38. new GetCollection(
  39. security: 'is_granted(\'ROLE_ORGANIZATION_VIEW\')',
  40. securityMessage: 'You do not have access to this course duration'
  41. ),
  42. new Post(
  43. security: 'is_granted(\'ROLE_ORGANIZATION\')'
  44. ),
  45. ],
  46. security: 'is_granted(\'ROLE_ORGANIZATION\')'
  47. )]
  48. // #[Auditable]
  49. #[OrganizationDefaultValue(fieldName: 'organization')]
  50. #[ORM\Entity(repositoryClass: EducationTimingRepository::class)]
  51. class EducationTiming
  52. {
  53. #[ORM\Id]
  54. #[ORM\Column]
  55. #[ORM\GeneratedValue]
  56. private ?int $id = null;
  57. #[ORM\ManyToOne(inversedBy: 'educationTimings')]
  58. #[ORM\JoinColumn(nullable: false)]
  59. private Organization $organization;
  60. #[ORM\Column]
  61. private int $timing;
  62. /** @var Collection<int, EducationStudent> */
  63. #[ORM\OneToMany(targetEntity: EducationStudent::class, mappedBy: 'educationTiming', orphanRemoval: true)]
  64. private Collection $educationStudents;
  65. /** @var Collection<int, EducationCurriculum> */
  66. #[ORM\ManyToMany(targetEntity: EducationCurriculum::class, mappedBy: 'educationTimings')]
  67. private Collection $educationCurriculums;
  68. public function __construct()
  69. {
  70. $this->educationStudents = new ArrayCollection();
  71. $this->educationCurriculums = new ArrayCollection();
  72. }
  73. public function getId(): ?int
  74. {
  75. return $this->id;
  76. }
  77. public function setOrganization(?Organization $organization): self
  78. {
  79. $this->organization = $organization;
  80. return $this;
  81. }
  82. public function getOrganization(): Organization
  83. {
  84. return $this->organization;
  85. }
  86. public function setTiming(int $timing): self
  87. {
  88. $this->timing = $timing;
  89. return $this;
  90. }
  91. public function getTiming(): int
  92. {
  93. return $this->timing;
  94. }
  95. /**
  96. * @return Collection<int, EducationStudent>
  97. */
  98. public function getEducationStudents(): Collection
  99. {
  100. return $this->educationStudents;
  101. }
  102. public function addEducationStudent(EducationStudent $educationStudent): self
  103. {
  104. if (!$this->educationStudents->contains($educationStudent)) {
  105. $this->educationStudents[] = $educationStudent;
  106. $educationStudent->setEducationTiming($this);
  107. }
  108. return $this;
  109. }
  110. public function removeEducationStudent(EducationStudent $educationStudent): self
  111. {
  112. if ($this->educationStudents->removeElement($educationStudent)) {
  113. // set the owning side to null (unless already changed)
  114. if ($educationStudent->getEducationTiming() === $this) {
  115. $educationStudent->setEducationTiming(null);
  116. }
  117. }
  118. return $this;
  119. }
  120. /**
  121. * @return Collection<int, EducationCurriculum>
  122. */
  123. public function getEducationCurriculums(): Collection
  124. {
  125. return $this->educationCurriculums;
  126. }
  127. public function addEducationCurriculum(EducationCurriculum $educationCurriculum): self
  128. {
  129. if (!$this->educationCurriculums->contains($educationCurriculum)) {
  130. $this->educationCurriculums[] = $educationCurriculum;
  131. $educationCurriculum->addEducationTiming($this);
  132. }
  133. return $this;
  134. }
  135. public function removeEducationCurriculum(EducationCurriculum $educationCurriculum): self
  136. {
  137. if ($this->educationCurriculums->removeElement($educationCurriculum)) {
  138. $educationCurriculum->removeEducationTiming($this);
  139. }
  140. return $this;
  141. }
  142. }