EducationTiming.php 4.3 KB

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