src/Entity/Abonnement.php line 32

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\GetCollection;
  5. use ApiPlatform\Metadata\Get;
  6. use App\Repository\AbonnementRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\DBAL\Types\Types;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. #[ORM\Entity(repositoryClassAbonnementRepository::class)]
  13. #[ApiResource(
  14.     operations: [
  15.         new Get(
  16.             normalizationContext: ['groups' => ['read:abonnement:collection''read:abonnement:item']]
  17.         ),
  18.         new GetCollection(
  19.             normalizationContext: ['groups' => ['read:abonnement:collection']],
  20.             order: ['montant' => 'ASC']
  21.         )
  22.     ],
  23.     paginationItemsPerPage50,
  24.     paginationMaximumItemsPerPage50,
  25.     normalizationContext: [
  26.         'groups' => ['read:abonnement:collection']
  27.     ],
  28. )]
  29. class Abonnement
  30. {
  31.     #[ORM\Id]
  32.     #[ORM\GeneratedValue]
  33.     #[ORM\Column]
  34.     #[Groups(['read:abonnement:collection''read:payment:collection'])]
  35.     private ?int $id null;
  36.     #[ORM\Column(length255)]
  37.     #[Groups(['read:abonnement:collection''read:payment:collection'])]
  38.     private ?string $label null;
  39.     #[ORM\Column(length255)]
  40.     #[Groups(['read:abonnement:collection''read:payment:collection'])]
  41.     private ?string $slug null;
  42.     #[ORM\Column]
  43.     #[Groups(['read:abonnement:collection''read:payment:collection'])]
  44.     private ?float $montant null;
  45.     #[ORM\Column(typeTypes::SMALLINT)]
  46.     #[Groups(['read:abonnement:collection''read:payment:collection'])]
  47.     private ?int $duree null;
  48.     #[ORM\OneToMany(mappedBy'abonnement'targetEntityPayment::class)]
  49.     private Collection $payments;
  50.     #[ORM\Column]
  51.     #[Groups(['read:abonnement:collection''read:payment:collection'])]
  52.     private ?bool $isRecommended false;
  53.     #[ORM\ManyToMany(targetEntityAbonnementItem::class, inversedBy'abonnements')]
  54.     #[Groups(['read:abonnement:collection'])]
  55.     private Collection $items;
  56.     #[ORM\ManyToMany(targetEntityPaymentMethod::class, inversedBy'abonnements')]
  57.     #[Groups(['read:payment:collection'])]
  58.     private Collection $paymentMethods;
  59.     #[ORM\Column(nullabletrue)]
  60.     private ?int $NbrePoint null;
  61.     public function __construct()
  62.     {
  63.         $this->payments = new ArrayCollection();
  64.         $this->items = new ArrayCollection();
  65.         $this->paymentMethods = new ArrayCollection();
  66.     }
  67.     public function getId(): ?int
  68.     {
  69.         return $this->id;
  70.     }
  71.     public function getLabel(): ?string
  72.     {
  73.         return $this->label;
  74.     }
  75.     public function setLabel(string $label): self
  76.     {
  77.         $this->label $label;
  78.         return $this;
  79.     }
  80.     public function getSlug(): ?string
  81.     {
  82.         return $this->slug;
  83.     }
  84.     public function setSlug(string $slug): self
  85.     {
  86.         $this->slug $slug;
  87.         return $this;
  88.     }
  89.     public function getMontant(): ?float
  90.     {
  91.         return $this->montant;
  92.     }
  93.     public function setMontant(float $montant): self
  94.     {
  95.         $this->montant $montant;
  96.         return $this;
  97.     }
  98.     public function getDuree(): ?int
  99.     {
  100.         return $this->duree;
  101.     }
  102.     public function setDuree(int $duree): self
  103.     {
  104.         $this->duree $duree;
  105.         return $this;
  106.     }
  107.     /**
  108.      * @return Collection<int, Payment>
  109.      */
  110.     public function getPayments(): Collection
  111.     {
  112.         return $this->payments;
  113.     }
  114.     public function addPayment(Payment $payment): self
  115.     {
  116.         if (!$this->payments->contains($payment)) {
  117.             $this->payments->add($payment);
  118.             $payment->setAbonnement($this);
  119.         }
  120.         return $this;
  121.     }
  122.     public function removePayment(Payment $payment): self
  123.     {
  124.         if ($this->payments->removeElement($payment)) {
  125.             // set the owning side to null (unless already changed)
  126.             if ($payment->getAbonnement() === $this) {
  127.                 $payment->setAbonnement(null);
  128.             }
  129.         }
  130.         return $this;
  131.     }
  132.     public function isIsRecommended(): ?bool
  133.     {
  134.         return $this->isRecommended;
  135.     }
  136.     public function setIsRecommended(bool $isRecommended): self
  137.     {
  138.         $this->isRecommended $isRecommended;
  139.         return $this;
  140.     }
  141.     /**
  142.      * @return Collection<int, AbonnementItem>
  143.      */
  144.     public function getItems(): Collection
  145.     {
  146.         return $this->items;
  147.     }
  148.     public function addItem(AbonnementItem $item): self
  149.     {
  150.         if (!$this->items->contains($item)) {
  151.             $this->items->add($item);
  152.         }
  153.         return $this;
  154.     }
  155.     public function removeItem(AbonnementItem $item): self
  156.     {
  157.         $this->items->removeElement($item);
  158.         return $this;
  159.     }
  160.     /**
  161.      * @return Collection<int, PaymentMethod>
  162.      */
  163.     public function getPaymentMethods(): Collection
  164.     {
  165.         return $this->paymentMethods;
  166.     }
  167.     public function addPaymentMethod(PaymentMethod $paymentMethod): self
  168.     {
  169.         if (!$this->paymentMethods->contains($paymentMethod)) {
  170.             $this->paymentMethods->add($paymentMethod);
  171.         }
  172.         return $this;
  173.     }
  174.     public function removePaymentMethod(PaymentMethod $paymentMethod): self
  175.     {
  176.         $this->paymentMethods->removeElement($paymentMethod);
  177.         return $this;
  178.     }
  179.     public function getNbrePoint(): ?int
  180.     {
  181.         return $this->NbrePoint;
  182.     }
  183.     public function setNbrePoint(?int $NbrePoint): static
  184.     {
  185.         $this->NbrePoint $NbrePoint;
  186.         return $this;
  187.     }
  188. }