src/Entity/Pack.php line 37

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Get;
  5. use ApiPlatform\Metadata\GetCollection;
  6. use ApiPlatform\Metadata\Post;
  7. use ApiPlatform\Metadata\Put;
  8. use ApiPlatform\Metadata\Patch;
  9. use App\Repository\PackRepository;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  15. use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
  16. use ApiPlatform\Metadata\ApiFilter;
  17. #[ORM\Entity(repositoryClassPackRepository::class)]
  18. #[ApiResource(
  19.     normalizationContext: ['groups' => ['read:pack']],
  20.     denormalizationContext: ['groups' => ['write:pack']],
  21.     operations: [
  22.         new Get(),
  23.         new GetCollection(),
  24.         new Post(),
  25.         new Put(),
  26.         new Patch(),
  27.     ],
  28.     paginationEnabledtrue,
  29.     paginationItemsPerPage30
  30. ),
  31. ApiFilter(SearchFilter::class, properties: ['niveauPack' => 'exact']),
  32. ApiFilter(BooleanFilter::class, properties: ['promotion'])]
  33. class Pack
  34. {
  35.     #[ORM\Id]
  36.     #[ORM\GeneratedValue]
  37.     #[ORM\Column]
  38.     #[Groups(['read:pack','write:pack'])]
  39.     private ?int $id null;
  40.     #[ORM\ManyToOne(inversedBy'packs')]
  41.     #[Groups(['read:pack','write:pack','read:acheter'])]
  42.     private ?NiveauPack $niveauPack null;
  43.     #[ORM\Column(length255)]
  44.     #[Groups(['read:pack','write:pack','read:acheter'])]
  45.     private ?string $gainPack null;
  46.     #[ORM\Column(length255)]
  47.     #[Groups(['read:pack','write:pack','read:acheter'])]
  48.     private ?string $montantPack null;
  49.     #[ORM\OneToMany(mappedBy'packAcheter'targetEntityAcheter::class)]
  50.     private Collection $acheters;
  51.     #[ORM\Column(nullabletrue)]
  52.     #[Groups(['read:pack''write:pack'])]
  53.     private ?bool $promotion null;
  54.     public function __construct()
  55.     {
  56.         $this->acheters = new ArrayCollection();
  57.     }
  58.     public function getId(): ?int
  59.     {
  60.         return $this->id;
  61.     }
  62.     public function getNiveauPack(): ?NiveauPack
  63.     {
  64.         return $this->niveauPack;
  65.     }
  66.     public function setNiveauPack(?NiveauPack $niveauPack): self
  67.     {
  68.         $this->niveauPack $niveauPack;
  69.         return $this;
  70.     }
  71.     public function getGainPack(): ?string
  72.     {
  73.         return $this->gainPack;
  74.     }
  75.     public function setGainPack(string $gainPack): self
  76.     {
  77.         $this->gainPack $gainPack;
  78.         return $this;
  79.     }
  80.     public function getMontantPack(): ?string
  81.     {
  82.         return $this->montantPack;
  83.     }
  84.     public function setMontantPack(string $montantPack): self
  85.     {
  86.         $this->montantPack $montantPack;
  87.         return $this;
  88.     }
  89.     /**
  90.      * @return Collection<int, Acheter>
  91.      */
  92.     public function getAcheters(): Collection
  93.     {
  94.         return $this->acheters;
  95.     }
  96.     public function addAcheter(Acheter $acheter): self
  97.     {
  98.         if (!$this->acheters->contains($acheter)) {
  99.             $this->acheters->add($acheter);
  100.             $acheter->setPackAcheter($this);
  101.         }
  102.         return $this;
  103.     }
  104.     public function removeAcheter(Acheter $acheter): self
  105.     {
  106.         if ($this->acheters->removeElement($acheter)) {
  107.             // set the owning side to null (unless already changed)
  108.             if ($acheter->getPackAcheter() === $this) {
  109.                 $acheter->setPackAcheter(null);
  110.             }
  111.         }
  112.         return $this;
  113.     }
  114.     public function isPromotion(): ?bool
  115.     {
  116.         return $this->promotion;
  117.     }
  118.     public function setPromotion(?bool $promotion): static
  119.     {
  120.         $this->promotion $promotion;
  121.         return $this;
  122.     }
  123. }