PersonHoliday.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Booking;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Entity\Access\Access;
  6. use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. /**
  11. * @todo : A la suite de la migration, il faut supprimer le nom de la table pour avoir une table PersonHoliday, et supprimer l'attribut discr.
  12. *
  13. * Classe ... qui ...
  14. */
  15. #[Auditable]
  16. #[ORM\Entity]
  17. #[ORM\Table(name: 'Booking')]
  18. #[ApiResource(
  19. collectionOperations:[],
  20. itemOperations: [
  21. "get" => ["security" => "is_granted('ROLE_ADMIN') and object.getAccess().getOrganization().getId() == user.getOrganization().getId()"]
  22. ]
  23. )]
  24. class PersonHoliday extends AbstractBooking
  25. {
  26. #[ORM\Column(length: 255, nullable: false)]
  27. private string $discr = 'personholiday';
  28. #[ORM\OneToMany(mappedBy: 'event', targetEntity: PersonHolidayRecur::class, cascade: ['persist'], orphanRemoval: true)]
  29. protected Collection $eventRecur;
  30. #[ORM\ManyToOne(inversedBy: 'holidays')]
  31. private Access $access;
  32. public function __construct()
  33. {
  34. $this->eventRecur = new ArrayCollection();
  35. }
  36. public function getDiscr(): ?string
  37. {
  38. return $this->discr;
  39. }
  40. public function setDiscr(string $discr): self
  41. {
  42. $this->discr = $discr;
  43. return $this;
  44. }
  45. /**
  46. * @return Collection<int, PersonHolidayRecur>
  47. */
  48. public function getEventRecur(): Collection
  49. {
  50. return $this->eventRecur;
  51. }
  52. public function addEventRecur(PersonHolidayRecur $eventRecur): self
  53. {
  54. if (!$this->eventRecur->contains($eventRecur)) {
  55. $this->eventRecur[] = $eventRecur;
  56. $eventRecur->setEvent($this);
  57. }
  58. return $this;
  59. }
  60. public function removeEventRecur(PersonHolidayRecur $eventRecur): self
  61. {
  62. if ($this->eventRecur->removeElement($eventRecur)) {
  63. // set the owning side to null (unless already changed)
  64. if ($eventRecur->getEvent() === $this) {
  65. $eventRecur->setEvent(null);
  66. }
  67. }
  68. return $this;
  69. }
  70. public function getAccess(): ?Access
  71. {
  72. return $this->access;
  73. }
  74. public function setAccess(?Access $access): self
  75. {
  76. $this->access = $access;
  77. return $this;
  78. }
  79. }