Attendance.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. declare (strict_types=1);
  3. namespace App\Entity\Booking;
  4. use ApiPlatform\Metadata\Get;
  5. use ApiPlatform\Metadata\ApiResource;
  6. use App\Entity\Access\Access;
  7. use App\Entity\Organization\Organization;
  8. //use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. /**
  13. * Classe ... qui ...
  14. */
  15. #[ApiResource(
  16. operations: [
  17. new Get(
  18. security: 'is_granted(\'ROLE_ADMIN\') and object.getOrganization().getId() == user.getOrganization().getId()'
  19. )
  20. ]
  21. )]
  22. //#[Auditable]
  23. #[ORM\Entity]
  24. class Attendance
  25. {
  26. #[ORM\Id]
  27. #[ORM\Column]
  28. #[ORM\GeneratedValue]
  29. private ?int $id = null;
  30. #[ORM\ManyToOne(inversedBy: 'attendances')]
  31. private Organization $organization;
  32. #[ORM\ManyToOne(inversedBy: 'attendances')]
  33. private Access $access;
  34. #[ORM\ManyToOne(inversedBy: 'attendanceReplacements')]
  35. private Access $replacement;
  36. #[ORM\OneToMany(mappedBy: 'attendance', targetEntity: AttendanceBooking::class, cascade: ['persist'], orphanRemoval: true)]
  37. #[ORM\JoinColumn(nullable: false)]
  38. private Collection $attendanceBooking;
  39. public function __construct()
  40. {
  41. $this->attendanceBooking = new ArrayCollection();
  42. }
  43. public function getId(): ?int
  44. {
  45. return $this->id;
  46. }
  47. public function getOrganization(): ?Organization
  48. {
  49. return $this->organization;
  50. }
  51. public function setOrganization(?Organization $organization): self
  52. {
  53. $this->organization = $organization;
  54. return $this;
  55. }
  56. public function getAccess(): ?Access
  57. {
  58. return $this->access;
  59. }
  60. public function setAccess(?Access $access): self
  61. {
  62. $this->access = $access;
  63. return $this;
  64. }
  65. public function getReplacement(): ?Access
  66. {
  67. return $this->replacement;
  68. }
  69. public function setReplacement(?Access $replacement): self
  70. {
  71. $this->replacement = $replacement;
  72. return $this;
  73. }
  74. /**
  75. * @return Collection<int, AttendanceBooking>
  76. */
  77. public function getAttendanceBooking(): Collection
  78. {
  79. return $this->attendanceBooking;
  80. }
  81. public function addAttendanceBooking(AttendanceBooking $attendanceBooking): self
  82. {
  83. if (!$this->attendanceBooking->contains($attendanceBooking)) {
  84. $this->attendanceBooking[] = $attendanceBooking;
  85. $attendanceBooking->setAttendance($this);
  86. }
  87. return $this;
  88. }
  89. public function removeAttendanceBooking(AttendanceBooking $attendanceBooking): self
  90. {
  91. if ($this->attendanceBooking->removeElement($attendanceBooking)) {
  92. // set the owning side to null (unless already changed)
  93. if ($attendanceBooking->getAttendance() === $this) {
  94. $attendanceBooking->setAttendance(null);
  95. }
  96. }
  97. return $this;
  98. }
  99. }