|
@@ -0,0 +1,125 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+namespace App\Entity\Booking;
|
|
|
|
|
+
|
|
|
|
|
+use ApiPlatform\Metadata\ApiResource;
|
|
|
|
|
+use ApiPlatform\Metadata\Delete;
|
|
|
|
|
+use ApiPlatform\Metadata\Get;
|
|
|
|
|
+use ApiPlatform\Metadata\GetCollection;
|
|
|
|
|
+use ApiPlatform\Metadata\Post;
|
|
|
|
|
+use ApiPlatform\Metadata\Put;
|
|
|
|
|
+use App\Attribute\OrganizationDefaultValue;
|
|
|
|
|
+use App\Entity\Organization\Organization;
|
|
|
|
|
+use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
|
+use Doctrine\Common\Collections\Collection;
|
|
|
|
|
+use Doctrine\ORM\Mapping as ORM;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * Motif d'absence ou de retard
|
|
|
|
|
+ *
|
|
|
|
|
+ * Security :
|
|
|
|
|
+ *
|
|
|
|
|
+ * @see \App\Doctrine\Education\AttendanceBookingReasonExtension.php
|
|
|
|
|
+ */
|
|
|
|
|
+#[ApiResource(
|
|
|
|
|
+
|
|
|
|
|
+ operations: [
|
|
|
|
|
+ new Get(
|
|
|
|
|
+ security: 'is_granted(\'ROLE_ORGANIZATION_VIEW\') and object.getOrganization().getId() == user.getOrganization().getId()'
|
|
|
|
|
+ ),
|
|
|
|
|
+ new Put(
|
|
|
|
|
+ security: 'is_granted(\'ROLE_ORGANIZATION_VIEW\') and is_granted(\'ROLE_GENERAL_CONFIG\') and object.getOrganization().getId() == user.getOrganization().getId()'
|
|
|
|
|
+ ),
|
|
|
|
|
+ new Delete(
|
|
|
|
|
+ security: 'is_granted(\'ROLE_ORGANIZATION_VIEW\') and is_granted(\'ROLE_GENERAL_CONFIG\') and object.getOrganization().getId() == user.getOrganization().getId()'
|
|
|
|
|
+ ),
|
|
|
|
|
+ new GetCollection(
|
|
|
|
|
+ security: 'is_granted(\'ROLE_ORGANIZATION_VIEW\')'
|
|
|
|
|
+ ),
|
|
|
|
|
+ new Post(
|
|
|
|
|
+ security: 'is_granted(\'ROLE_ORGANIZATION_VIEW\') and is_granted(\'ROLE_GENERAL_CONFIG\')'
|
|
|
|
|
+ )]
|
|
|
|
|
+)]
|
|
|
|
|
+//#[Auditable]
|
|
|
|
|
+#[ORM\Table(name: 'AttendanceBookingReason')]
|
|
|
|
|
+#[OrganizationDefaultValue(fieldName: "organization")]
|
|
|
|
|
+#[ORM\Entity]
|
|
|
|
|
+class AttendanceBookingReason
|
|
|
|
|
+{
|
|
|
|
|
+ #[ORM\Id]
|
|
|
|
|
+ #[ORM\Column]
|
|
|
|
|
+ #[ORM\GeneratedValue]
|
|
|
|
|
+ private ?int $id = null;
|
|
|
|
|
+
|
|
|
|
|
+ #[ORM\ManyToOne(inversedBy: 'attendanceBookingReasons')]
|
|
|
|
|
+ #[ORM\JoinColumn(nullable: false)]
|
|
|
|
|
+ protected Organization $organization;
|
|
|
|
|
+
|
|
|
|
|
+ #[ORM\Column(length: 255, nullable: false)]
|
|
|
|
|
+ private string $reason;
|
|
|
|
|
+
|
|
|
|
|
+ #[ORM\OneToMany(mappedBy: 'reason', targetEntity: AttendanceBooking::class, cascade: ['persist'], orphanRemoval: true)]
|
|
|
|
|
+ private Collection $attendanceBookings;
|
|
|
|
|
+
|
|
|
|
|
+ public function __construct()
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->attendanceBookings = new ArrayCollection();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function getId(): ?int
|
|
|
|
|
+ {
|
|
|
|
|
+ return $this->id;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function setId(?int $id): self
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->id = $id;
|
|
|
|
|
+ return $this;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function getOrganization(): Organization
|
|
|
|
|
+ {
|
|
|
|
|
+ return $this->organization;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function setOrganization(?Organization $organization): self
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->organization = $organization;
|
|
|
|
|
+ return $this;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function getReason(): string
|
|
|
|
|
+ {
|
|
|
|
|
+ return $this->reason;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function setReason(string $reason): self
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->reason = $reason;
|
|
|
|
|
+ return $this;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function getAttendanceBookings(): Collection
|
|
|
|
|
+ {
|
|
|
|
|
+ return $this->attendanceBookings;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function addAttendanceBookings(AttendanceBooking $attendanceBooking): self
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!$this->attendanceBookings->contains($attendanceBooking)) {
|
|
|
|
|
+ $this->attendanceBookings[] = $attendanceBooking;
|
|
|
|
|
+ $attendanceBooking->setReason($this);
|
|
|
|
|
+ }
|
|
|
|
|
+ return $this;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function removeAttendanceBooking(AttendanceBooking $attendanceBooking): self
|
|
|
|
|
+ {
|
|
|
|
|
+ if ($this->attendanceBookings->removeElement($attendanceBooking)) {
|
|
|
|
|
+ // set the owning side to null (unless already changed)
|
|
|
|
|
+ if ($attendanceBooking->getReason() === $this) {
|
|
|
|
|
+ $attendanceBooking->setReason(null);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return $this;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|