src/Entity/Reservation.php line 79

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  7. use App\Controller\ControllerAnnulerReservation;
  8. use App\Controller\ControllerDeleteReservationAbonnement;
  9. use App\Dto\AbonnementInput;
  10. use App\Dto\ReservationAbonnementInputUpdate;
  11. use App\Dto\ReservationInput;
  12. use App\Dto\ReservationInputUpdate;
  13. use App\Repository\ReservationRepository;
  14. use DateTimeImmutable;
  15. use Doctrine\Common\Collections\ArrayCollection;
  16. use Doctrine\Common\Collections\Collection;
  17. use Doctrine\ORM\Mapping as ORM;
  18. use Symfony\Component\Serializer\Annotation\Groups;
  19. use Symfony\Component\Validator\Constraints as Assert;
  20. #[ORM\Entity(repositoryClassReservationRepository::class)]
  21. #[ApiResource(
  22.     attributes:["fetchEager"=> false],
  23.     denormalizationContext:[
  24.         'groups'=>['reservation:write']
  25.     ],
  26.     normalizationContext:[
  27.         'groups'=>['reservation:read']
  28.     ],
  29.     order: ["id" => "DESC"],
  30.     collectionOperations: [
  31.         "get",
  32.         "post" => [
  33.             "method" => "POST",
  34.             "input" => ReservationInput::class,
  35.         ],
  36.         "abonnement" => [
  37.             'path' => '/reservations/abonnement',
  38.             "method" => "POST",
  39.             "input" => AbonnementInput::class,
  40.         ]
  41.     ],
  42.     itemOperations:[
  43.         'get',
  44.         'annuler'=>[
  45.             'method' => "GET",
  46.             'path' => "/reservations/annuler/{reference}",
  47.             'controller' => ControllerAnnulerReservation::class,
  48.             'read' => false,
  49.             'status' => 204,
  50.             'deserialize' => false,
  51.         ],
  52.         'delete_abnn' => [
  53.             'method' => "DELETE",
  54.             'path' => "/reservations/abonnement/{reference}",
  55.             'controller' => ControllerDeleteReservationAbonnement::class,
  56.             'read' => false,
  57.             'status' => 204,
  58.             'deserialize' => false,
  59.         ],
  60.         'put_reservation_ponctuel'=>[
  61.             "method" => "PUT",
  62.             'path' => '/reservations/ponctuel/{id}',
  63.             "input"=>ReservationInputUpdate::class
  64.         ],
  65.         'put_reservation_abonnement'=>[
  66.             "method" => "PUT",
  67.             'path' => '/reservations/abonnement/{id}',
  68.             "input"=>ReservationAbonnementInputUpdate::class
  69.         ],
  70.         'put'
  71.     ]
  72. )]
  73. #[ApiFilter(SearchFilter::class, properties: ['statut' => 'partial','customer' => 'exact',
  74. 'typeReservation'=>'exact','reference'=>'exact','pitchDisponibilities.houre'=>'exact','pitch'=>'exact'])]
  75. #[ApiFilter(DateFilter::class, properties: ['date'])]
  76. class Reservation
  77. {
  78.     public const STATUT_NOUVEL 'En cour';
  79.     public const STATUT_TERMINER 'Terminer';
  80.     public const STATUT_ANNULER 'Annuler';
  81.     #[ORM\Id]
  82.     #[ORM\GeneratedValue]
  83.     #[ORM\Column(type'integer')]
  84.     #[Groups(['reservation:write','reservation:read','payement:read','user:read'])]
  85.     private $id;
  86.     #[ORM\Column(type'datetime')]
  87.     #[Assert\NotBlank]
  88.     #[Assert\NotNull]
  89.     #[Groups(['reservation:write','reservation:read','payement:read','user:read'])]
  90.     private $date;
  91.     #[ORM\ManyToOne(targetEntityPitch::class, inversedBy'reservations')]
  92.     #[ORM\JoinColumn(nullablefalse)]
  93.     #[Assert\NotBlank]
  94.     #[Assert\NotNull]
  95.     #[Groups(['reservation:write','reservation:read'])]
  96.     private $pitch;
  97.     #[ORM\Column(type'string'length10)]
  98.     private $statut;
  99.     #[ORM\Column(type'string'length10nullabletrue)]
  100.     #[Groups(['reservation:read'])]
  101.     private $reference;
  102.     #[ORM\Column(type'datetime')]
  103.     #[Groups(['reservation:read'])]
  104.     private $dateCreate;
  105.     #[ORM\ManyToOne(targetEntityUser::class, inversedBy'reservations')]
  106.     #[ORM\JoinColumn(nullabletrueonDelete'SET NULL')]
  107.     #[Groups(['reservation:write','reservation:read','payement:read'])]
  108.     private $customer;
  109.     #[ORM\OneToMany(mappedBy'reservation'targetEntityPayment::class, cascade:['persist','remove'])]
  110.     #[Groups(['reservation:write','reservation:read'])]
  111.     private $payements;
  112.     #[ORM\Column(type'boolean'nullabletrue)]
  113.     #[Groups(['reservation:read'])]
  114.     private $isSold false;
  115.     #[Groups(['reservation:read'])]
  116.     public $urlPayement null;
  117.     #[ORM\Column(type'string'length100nullabletrue)]
  118.     private $canal 'place';
  119.     #[ORM\OneToMany(mappedBy'reservation'targetEntityPitchDisponibility::class, cascade:["persist","remove"])]
  120.     #[Groups(['reservation:read'])]
  121.     private $pitchDisponibilities;
  122.     #[ORM\ManyToOne(targetEntityFormule::class, inversedBy'reservations')]
  123.     #[Groups(['reservation:write','reservation:read'])]
  124.     private $formule;
  125.     #[ORM\Column(type'boolean'nullabletrue)]
  126.     #[Groups(['reservation:read'])]
  127.     private $isPrincipale;
  128.     #[ORM\ManyToOne(targetEntityPrice::class, inversedBy'reservations')]
  129.     #[Groups(['reservation:write','reservation:read'])]
  130.     private $price;
  131.     #[ORM\Column(type'integer'nullabletrue)]
  132.     #[Groups(['reservation:write','reservation:read'])]
  133.     private $quantityTime;
  134.     #[ORM\Column(type'boolean'nullabletrue)]
  135.     #[Groups(['reservation:write','reservation:read'])]
  136.     private $isIndisponible false;
  137.     public function __construct()
  138.     {
  139.         $this->dateCreate = new DateTimeImmutable();
  140.         $this->statut Reservation::STATUT_NOUVEL;
  141.         $this->payements = new ArrayCollection();
  142.         $this->pitchDisponibilities = new ArrayCollection();
  143.         $this->isPrincipale true;
  144.         $this->quantityTime 1;
  145.     }
  146.     public function getId(): ?int
  147.     {
  148.         return $this->id;
  149.     }
  150.     public function getDate(): ?\DateTimeInterface
  151.     {
  152.         return $this->date;
  153.     }
  154.     public function setDate(\DateTimeInterface $date): self
  155.     {
  156.         $this->date $date;
  157.         return $this;
  158.     }
  159.     public function getPitch(): ?Pitch
  160.     {
  161.         return $this->pitch;
  162.     }
  163.     public function setPitch(?Pitch $pitch): self
  164.     {
  165.         $this->pitch $pitch;
  166.         return $this;
  167.     }
  168.     public function getStatut(): ?string
  169.     {
  170.         return $this->statut;
  171.     }
  172.     public function setStatut(string $statut): self
  173.     {
  174.         $this->statut $statut;
  175.         return $this;
  176.     }
  177.     public function getReference(): ?string
  178.     {
  179.         return $this->reference;
  180.     }
  181.     public function setReference(?string $reference): self
  182.     {
  183.         $this->reference $reference;
  184.         return $this;
  185.     }
  186.     public function getDateCreate(): ?\DateTimeInterface
  187.     {
  188.         return $this->dateCreate;
  189.     }
  190.     public function setDateCreate(\DateTimeInterface $dateCreate): self
  191.     {
  192.         $this->dateCreate $dateCreate;
  193.         return $this;
  194.     }
  195.     public function getCustomer(): ?User
  196.     {
  197.         return $this->customer;
  198.     }
  199.     public function setCustomer(?User $customer): self
  200.     {
  201.         $this->customer $customer;
  202.         return $this;
  203.     }
  204.     /**
  205.      * @return Collection<int, Payment>
  206.      */
  207.     public function getPayements(): Collection
  208.     {
  209.         return $this->payements;
  210.     }
  211.     public function addPayement(Payment $payement): self
  212.     {
  213.         if (!$this->payements->contains($payement)) {
  214.             $this->payements[] = $payement;
  215.             $payement->setReservation($this);
  216.         }
  217.         return $this;
  218.     }
  219.     public function removePayement(Payment $payement): self
  220.     {
  221.         if ($this->payements->removeElement($payement)) {
  222.             // set the owning side to null (unless already changed)
  223.             if ($payement->getReservation() === $this) {
  224.                 $payement->setReservation(null);
  225.             }
  226.         }
  227.         return $this;
  228.     }
  229.     public function isIsSold(): ?bool
  230.     {
  231.         return $this->isSold;
  232.     }
  233.     public function setIsSold(?bool $isSold): self
  234.     {
  235.         $this->isSold $isSold;
  236.         return $this;
  237.     }
  238.     public function getCanal(): ?string
  239.     {
  240.         return $this->canal;
  241.     }
  242.     public function setCanal(?string $canal): self
  243.     {
  244.         $this->canal $canal;
  245.         return $this;
  246.     }
  247.     /**
  248.      * @return Collection<int, PitchDisponibility>
  249.      */
  250.     public function getPitchDisponibilities(): Collection
  251.     {
  252.         return $this->pitchDisponibilities;
  253.     }
  254.     public function addPitchDisponibility(PitchDisponibility $pitchDisponibility): self
  255.     {
  256.         if (!$this->pitchDisponibilities->contains($pitchDisponibility)) {
  257.             $this->pitchDisponibilities[] = $pitchDisponibility;
  258.             $pitchDisponibility->setReservation($this);
  259.         }
  260.         return $this;
  261.     }
  262.     public function removePitchDisponibility(PitchDisponibility $pitchDisponibility): self
  263.     {
  264.         if ($this->pitchDisponibilities->removeElement($pitchDisponibility)) {
  265.             // set the owning side to null (unless already changed)
  266.             if ($pitchDisponibility->getReservation() === $this) {
  267.                 $pitchDisponibility->setReservation(null);
  268.             }
  269.         }
  270.         return $this;
  271.     }
  272.     public function getFormule(): ?Formule
  273.     {
  274.         return $this->formule;
  275.     }
  276.     public function setFormule(?Formule $formule): self
  277.     {
  278.         $this->formule $formule;
  279.         return $this;
  280.     }
  281.     public function isIsPrincipale(): ?bool
  282.     {
  283.         return $this->isPrincipale;
  284.     }
  285.     public function setIsPrincipale(?bool $isPrincipale): self
  286.     {
  287.         $this->isPrincipale $isPrincipale;
  288.         return $this;
  289.     }
  290.     public function getPrice(): ?Price
  291.     {
  292.         return $this->price;
  293.     }
  294.     public function setPrice(?Price $price): self
  295.     {
  296.         $this->price $price;
  297.         return $this;
  298.     }
  299.     public function getQuantityTime(): ?int
  300.     {
  301.         return $this->quantityTime;
  302.     }
  303.     public function setQuantityTime(?int $quantityTime): self
  304.     {
  305.         $this->quantityTime $quantityTime;
  306.         return $this;
  307.     }
  308.     public function isIsIndisponible(): ?bool
  309.     {
  310.         return $this->isIndisponible;
  311.     }
  312.     public function setIsIndisponible(?bool $isIndisponible): self
  313.     {
  314.         $this->isIndisponible $isIndisponible;
  315.         return $this;
  316.     }
  317. }