| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?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: 'object.getOrganization().getId() == user.getOrganization().getId()'
- ),
- new Delete(
- security: 'object.getOrganization().getId() == user.getOrganization().getId()'
- ),
- new GetCollection(
- security: 'is_granted(\'ROLE_ORGANIZATION_VIEW\')'
- ),
- new Post()
- ])]
- //#[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;
- }
- }
|