src/Entity/Price.php line 36

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\BooleanFilter;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  7. use App\Repository\PriceRepository;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. #[ORM\Entity(repositoryClassPriceRepository::class)]
  14. #[ApiResource(
  15.     normalizationContext: ['groups' => ['price:read']],
  16.     denormalizationContext:[
  17.         'groups'=>['price:write']
  18.     ],
  19.     order: ["id" => "DESC"],
  20.     collectionOperations: [
  21.         "get",
  22.         "post"
  23.     ],
  24.     itemOperations:[
  25.         "get",
  26.         'put' => [
  27.             'denormalization_context' => ['groups' => ['price:put']],
  28.         ]
  29.     ]
  30. )]
  31. #[ApiFilter(SearchFilter::class, properties: ['typeReservation' => 'exact','typePitch'=>'exact'])]
  32. #[ApiFilter(BooleanFilter::class, properties: ['isDelete'])]
  33. class Price
  34. {
  35.     #[ORM\Id]
  36.     #[ORM\GeneratedValue]
  37.     #[ORM\Column(type'integer')]
  38.     #[Groups(['pitch:read','reservation:read','price:write','price:read','price:put'])]
  39.     private $id;
  40.     #[ORM\Column(type'integer')]
  41.     #[Assert\Type(type:"integer")]
  42.     #[Assert\NotBlank]
  43.     #[Assert\NotNull]
  44.     #[Assert\Positive]
  45.     #[Groups(['pitch:read','price:write','price:read','price:put'])]
  46.     private int $time;
  47.     #[ORM\Column(type'integer')]
  48.     #[Assert\Type(type:"integer")]
  49.     #[Assert\NotBlank]
  50.     #[Assert\NotNull]
  51.     #[Groups(['pitch:read','reservation:read','price:write','price:read','price:put'])]
  52.     private $montant;
  53.     #[ORM\ManyToOne(targetEntityTypeReservation::class, inversedBy'prices')]
  54.     #[Groups(['pitch:read','reservation:read','price:write','price:read','price:put'])]
  55.     private $typeReservation;
  56.     #[ORM\OneToMany(mappedBy'price'targetEntityReservation::class)]
  57.     private $reservations;
  58.     #[Groups(['pitch:read','reservation:read','price:write','price:read','price:put'])]
  59.     #[ORM\ManyToOne(targetEntityTypePitch::class, inversedBy'prices')]
  60.     private $typePitch;
  61.     #[Groups(['pitch:read','price:read','price:put'])]
  62.     #[ORM\Column(type'boolean')]
  63.     private $isDelete false;
  64.     public function __construct()
  65.     {
  66.         $this->reservations = new ArrayCollection();
  67.     }
  68.     public function getId(): ?int
  69.     {
  70.         return $this->id;
  71.     }
  72.     public function getTime(): ?int
  73.     {
  74.         return (string)$this->time;
  75.     }
  76.     public function setTime(int $time): self
  77.     {
  78.         $this->time = (string)$time;
  79.         return $this;
  80.     }
  81.     public function getMontant(): ?int
  82.     {
  83.         return $this->montant;
  84.     }
  85.     public function setMontant(int $montant): self
  86.     {
  87.         $this->montant $montant;
  88.         return $this;
  89.     }
  90.     public function getTypeReservation(): ?TypeReservation
  91.     {
  92.         return $this->typeReservation;
  93.     }
  94.     public function setTypeReservation(?TypeReservation $typeReservation): self
  95.     {
  96.         $this->typeReservation $typeReservation;
  97.         return $this;
  98.     }
  99.     /**
  100.      * @return Collection<int, Reservation>
  101.      */
  102.     public function getReservations(): Collection
  103.     {
  104.         return $this->reservations;
  105.     }
  106.     public function addReservation(Reservation $reservation): self
  107.     {
  108.         if (!$this->reservations->contains($reservation)) {
  109.             $this->reservations[] = $reservation;
  110.             $reservation->setPrice($this);
  111.         }
  112.         return $this;
  113.     }
  114.     public function removeReservation(Reservation $reservation): self
  115.     {
  116.         if ($this->reservations->removeElement($reservation)) {
  117.             // set the owning side to null (unless already changed)
  118.             if ($reservation->getPrice() === $this) {
  119.                 $reservation->setPrice(null);
  120.             }
  121.         }
  122.         return $this;
  123.     }
  124.     public function getTypePitch(): ?TypePitch
  125.     {
  126.         return $this->typePitch;
  127.     }
  128.     public function setTypePitch(?TypePitch $typePitch): self
  129.     {
  130.         $this->typePitch $typePitch;
  131.         return $this;
  132.     }
  133.     public function isIsDelete(): ?bool
  134.     {
  135.         return $this->isDelete;
  136.     }
  137.     public function setIsDelete(bool $isDelete): self
  138.     {
  139.         $this->isDelete $isDelete;
  140.         return $this;
  141.     }
  142. }