src/Entity/Pitch.php line 30

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\OrderFilter;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  8. use App\Repository\PitchRepository;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. #[ORM\Entity(repositoryClassPitchRepository::class)]
  16. #[UniqueEntity(fields:'label'message:'Le nom existe déjà')]
  17. #[ApiFilter(SearchFilter::class, properties: ['location.label' => 'ipartial','label' => 'ipartial','typePitch'=>'exact'])]
  18. #[ApiFilter(BooleanFilter::class, properties: ['isActived'])]
  19. #[ApiFilter(OrderFilter::class, properties: ['note' => 'DESC'])]
  20. #[ApiResource(
  21.     normalizationContext: ['groups' => ['pitch:read']],
  22.     denormalizationContext:[
  23.         'groups'=>['pitch:write']
  24.     ],
  25.     order: ["id" => "DESC"]
  26. )]
  27. class Pitch
  28. {
  29.     #[ORM\Id]
  30.     #[ORM\GeneratedValue]
  31.     #[ORM\Column(type'integer')]
  32.     #[Groups(['pitch:read','reservation:read','favoris:read','abonnement:read'])]
  33.     private $id;
  34.     #[ORM\Column(type'string'length45)]
  35.     #[Assert\NotBlank]
  36.     #[Assert\NotNull]
  37.     #[Groups(['pitch:read','pitch:write','reservation:read','favoris:read','abonnement:read'])]
  38.     private $label;
  39.     #[ORM\Column(type'integer'nullabletrue)]
  40.     #[Assert\Type(type:"integer")]
  41.     #[Assert\Positive]
  42.     private $note;
  43.     #[ORM\Column(type'boolean'nullabletrue)]
  44.     #[Assert\Type(type:"bool")]
  45.     private $isDisponible;
  46.     #[ORM\ManyToOne(targetEntityLocation::class, inversedBy'pitches')]
  47.     #[Assert\NotBlank]
  48.     #[Assert\NotNull]
  49.     #[ORM\JoinColumn(nullablefalse)]
  50.     #[Groups(['pitch:read','pitch:write','reservation:read','favoris:read'])]
  51.     private $location;
  52.     #[ORM\OneToMany(mappedBy'pitch'targetEntityAlbum::class)]
  53.     #[Assert\NotBlank]
  54.     #[Assert\NotNull]
  55.     #[Groups(['pitch:read','pitch:write','favoris:read','reservation:read'])]
  56.     private $albums;
  57.     #[ORM\Column(type'text'nullabletrue)]
  58.     #[Groups(['pitch:read','pitch:write','favoris:read'])]
  59.     private $description;
  60.     #[ORM\Column(type'string'length255nullabletrue)]
  61.     private $indicator;
  62.     #[ORM\OneToMany(mappedBy'pitch'targetEntityReservation::class)]
  63.     private $reservations;
  64.     #[ORM\Column(type'boolean'nullabletrue)]
  65.     private $isActived;
  66.     #[ORM\OneToMany(mappedBy'pitch'targetEntityAbonnement::class)]
  67.     private $abonnements;
  68.     #[ORM\OneToMany(mappedBy'pitch'targetEntityAcademy::class)]
  69.     private $academies;
  70.     #[Groups(['pitch:read','pitch:write','favoris:read','reservation:read'])]
  71.     #[ORM\ManyToOne(targetEntityTypePitch::class, inversedBy'pitches')]
  72.     private $typePitch;
  73.     public function __construct()
  74.     {
  75.         $this->albums = new ArrayCollection();
  76.         $this->reservations = new ArrayCollection();
  77.         $this->abonnements = new ArrayCollection();
  78.         $this->academies = new ArrayCollection();
  79.     }
  80.     public function getId(): ?int
  81.     {
  82.         return $this->id;
  83.     }
  84.     public function getLabel(): ?string
  85.     {
  86.         return $this->label;
  87.     }
  88.     public function setLabel(string $label): self
  89.     {
  90.         $this->label $label;
  91.         return $this;
  92.     }
  93.     public function getNote(): ?int
  94.     {
  95.         return $this->note;
  96.     }
  97.     public function setNote(int $note): self
  98.     {
  99.         $this->note $note;
  100.         return $this;
  101.     }
  102.     public function isIsDisponible(): ?bool
  103.     {
  104.         return $this->isDisponible;
  105.     }
  106.     public function setIsDisponible(bool $isDisponible): self
  107.     {
  108.         $this->isDisponible $isDisponible;
  109.         return $this;
  110.     }
  111.     public function getLocation(): ?Location
  112.     {
  113.         return $this->location;
  114.     }
  115.     public function setLocation(?Location $location): self
  116.     {
  117.         $this->location $location;
  118.         return $this;
  119.     }
  120.     public function getPrice(): ?int
  121.     {
  122.         return $this->price;
  123.     }
  124.     public function setPrice(?int $price): self
  125.     {
  126.         $this->price $price;
  127.         return $this;
  128.     }
  129.     /**
  130.      * @return Collection<int, Album>
  131.      */
  132.     public function getAlbums(): Collection
  133.     {
  134.         return $this->albums;
  135.     }
  136.     public function addAlbum(Album $album): self
  137.     {
  138.         if (!$this->albums->contains($album)) {
  139.             $this->albums[] = $album;
  140.             $album->setPitch($this);
  141.         }
  142.         return $this;
  143.     }
  144.     public function removeAlbum(Album $album): self
  145.     {
  146.         if ($this->albums->removeElement($album)) {
  147.             // set the owning side to null (unless already changed)
  148.             if ($album->getPitch() === $this) {
  149.                 $album->setPitch(null);
  150.             }
  151.         }
  152.         return $this;
  153.     }
  154.     public function getDescription(): ?string
  155.     {
  156.         return $this->description;
  157.     }
  158.     public function setDescription(?string $description): self
  159.     {
  160.         $this->description $description;
  161.         return $this;
  162.     }
  163.     public function getIndicator(): ?string
  164.     {
  165.         return $this->indicator;
  166.     }
  167.     public function setIndicator(string $indicator): self
  168.     {
  169.         $this->indicator $indicator;
  170.         return $this;
  171.     }
  172.     /**
  173.      * @return Collection<int, Reservation>
  174.      */
  175.     public function getReservations(): Collection
  176.     {
  177.         return $this->reservations;
  178.     }
  179.     public function addReservation(Reservation $reservation): self
  180.     {
  181.         if (!$this->reservations->contains($reservation)) {
  182.             $this->reservations[] = $reservation;
  183.             $reservation->setPitch($this);
  184.         }
  185.         return $this;
  186.     }
  187.     public function removeReservation(Reservation $reservation): self
  188.     {
  189.         if ($this->reservations->removeElement($reservation)) {
  190.             // set the owning side to null (unless already changed)
  191.             if ($reservation->getPitch() === $this) {
  192.                 $reservation->setPitch(null);
  193.             }
  194.         }
  195.         return $this;
  196.     }
  197.     public function isIsActived(): ?bool
  198.     {
  199.         return $this->isActived;
  200.     }
  201.     public function setIsActived(?bool $isActived): self
  202.     {
  203.         $this->isActived $isActived;
  204.         return $this;
  205.     }
  206.     /**
  207.      * @return Collection<int, Abonnement>
  208.      */
  209.     public function getAbonnements(): Collection
  210.     {
  211.         return $this->abonnements;
  212.     }
  213.     /**
  214.      * @return Collection<int, Academy>
  215.      */
  216.     public function getAcademies(): Collection
  217.     {
  218.         return $this->academies;
  219.     }
  220.     public function addAcademy(Academy $academy): self
  221.     {
  222.         if (!$this->academies->contains($academy)) {
  223.             $this->academies[] = $academy;
  224.             $academy->setPitch($this);
  225.         }
  226.         return $this;
  227.     }
  228.     public function removeAcademy(Academy $academy): self
  229.     {
  230.         if ($this->academies->removeElement($academy)) {
  231.             // set the owning side to null (unless already changed)
  232.             if ($academy->getPitch() === $this) {
  233.                 $academy->setPitch(null);
  234.             }
  235.         }
  236.         return $this;
  237.     }
  238.     public function getTypePitch(): ?TypePitch
  239.     {
  240.         return $this->typePitch;
  241.     }
  242.     public function setTypePitch(?TypePitch $typePitch): self
  243.     {
  244.         $this->typePitch $typePitch;
  245.         return $this;
  246.     }
  247. }