EducationTiming.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. ),
  29. new Put(
  30. security: 'object.getOrganization().getId() == user.getOrganization().getId()'
  31. ),
  32. new Delete(
  33. security: 'object.getOrganization().getId() == user.getOrganization().getId()'
  34. ),
  35. new GetCollection(
  36. security: 'is_granted(\'ROLE_ORGANIZATION_VIEW\')'
  37. ),
  38. new Post(),
  39. ],
  40. security: 'is_granted(\'ROLE_ORGANIZATION\')'
  41. )]
  42. // #[Auditable]
  43. #[OrganizationDefaultValue(fieldName: 'organization')]
  44. #[ORM\Entity(repositoryClass: EducationTimingRepository::class)]
  45. class EducationTiming
  46. {
  47. #[ORM\Id]
  48. #[ORM\Column]
  49. #[ORM\GeneratedValue]
  50. private ?int $id = null;
  51. #[ORM\ManyToOne(inversedBy: 'educationTimings')]
  52. #[ORM\JoinColumn(nullable: false)]
  53. private Organization $organization;
  54. #[ORM\Column]
  55. private int $timing;
  56. #[ORM\OneToMany(mappedBy: 'educationTiming', targetEntity: EducationStudent::class, orphanRemoval: true)]
  57. private Collection $educationStudents;
  58. #[ORM\ManyToMany(targetEntity: EducationCurriculum::class, mappedBy: 'educationTimings')]
  59. private Collection $educationCurriculums;
  60. public function __construct()
  61. {
  62. $this->educationStudents = new ArrayCollection();
  63. $this->educationCurriculums = new ArrayCollection();
  64. }
  65. public function getId(): ?int
  66. {
  67. return $this->id;
  68. }
  69. public function setOrganization(?Organization $organization): self
  70. {
  71. $this->organization = $organization;
  72. return $this;
  73. }
  74. public function getOrganization(): Organization
  75. {
  76. return $this->organization;
  77. }
  78. public function setTiming(int $timing): self
  79. {
  80. $this->timing = $timing;
  81. return $this;
  82. }
  83. public function getTiming(): int
  84. {
  85. return $this->timing;
  86. }
  87. /**
  88. * @return Collection<int, EducationStudent>
  89. */
  90. public function getEducationStudents(): Collection
  91. {
  92. return $this->educationStudents;
  93. }
  94. public function addEducationStudent(EducationStudent $educationStudent): self
  95. {
  96. if (!$this->educationStudents->contains($educationStudent)) {
  97. $this->educationStudents[] = $educationStudent;
  98. $educationStudent->setEducationTiming($this);
  99. }
  100. return $this;
  101. }
  102. public function removeEducationStudent(EducationStudent $educationStudent): self
  103. {
  104. if ($this->educationStudents->removeElement($educationStudent)) {
  105. // set the owning side to null (unless already changed)
  106. if ($educationStudent->getEducationTiming() === $this) {
  107. $educationStudent->setEducationTiming(null);
  108. }
  109. }
  110. return $this;
  111. }
  112. /**
  113. * @return Collection<int, EducationCurriculum>
  114. */
  115. public function getEducationCurriculums(): Collection
  116. {
  117. return $this->educationCurriculums;
  118. }
  119. public function addEducationCurriculum(EducationCurriculum $educationCurriculum): self
  120. {
  121. if (!$this->educationCurriculums->contains($educationCurriculum)) {
  122. $this->educationCurriculums[] = $educationCurriculum;
  123. $educationCurriculum->addEducationTiming($this);
  124. }
  125. return $this;
  126. }
  127. public function removeEducationCurriculum(EducationCurriculum $educationCurriculum): self
  128. {
  129. if ($this->educationCurriculums->removeElement($educationCurriculum)) {
  130. $educationCurriculum->removeEducationTiming($this);
  131. }
  132. return $this;
  133. }
  134. }