src/Entity/Product.php line 21

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  4. use ApiPlatform\Metadata\ApiFilter;
  5. use ApiPlatform\Metadata\ApiResource;
  6. use App\Repository\ProductRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. #[ApiResource(
  13.     normalizationContext: ['groups' => ['read_prod']]
  14. )]
  15. #[ApiFilter(SearchFilter::class, properties: ['name' => 'exact''qrCode' => 'exact'])]
  16. #[ORM\Entity(repositoryClassProductRepository::class)]
  17. #[UniqueEntity("qrCode")]
  18. class Product
  19. {
  20.     #[Groups('read_prod')]
  21.     #[ORM\Id]
  22.     #[ORM\GeneratedValue]
  23.     #[ORM\Column]
  24.     private ?int $id null;
  25.     #[Groups('read_prod')]
  26.     #[ORM\Column(length255)]
  27.     private ?string $name null;
  28.     #[ORM\Column(length255nullabletrue)]
  29.     private ?string $description null;
  30.     #[Groups('read_prod')]
  31.     #[ORM\Column]
  32.     private ?float $qty null;
  33.     #[ORM\Column(nullabletrue)]
  34.     private ?float $prixRevient null;
  35.     #[Groups('read_prod')]
  36.     #[ORM\Column(nullabletrue)]
  37.     private ?float $prixVente null;
  38.     #[Groups('read_prod')]
  39.     #[ORM\Column(length255,uniquetrue,nullabletrue)]
  40.     private ?string $qrCode null;
  41.     #[ORM\OneToMany(mappedBy'product'targetEntityOrderLine::class)]
  42.     private Collection $orderLines;
  43.     #[ORM\OneToMany(mappedBy'product'targetEntityStock::class)]
  44.     private Collection $stocks;
  45.     public function __construct()
  46.     {
  47.         $this->orderLines = new ArrayCollection();
  48.         $this->stocks = new ArrayCollection();
  49.         $this->qty 0;
  50.         $this->prixRevient 0;
  51.     }
  52.     public function getId(): ?int
  53.     {
  54.         return $this->id;
  55.     }
  56.     public function getName(): ?string
  57.     {
  58.         return $this->name;
  59.     }
  60.     public function setName(string $name): self
  61.     {
  62.         $this->name $name;
  63.         return $this;
  64.     }
  65.     public function getDescription(): ?string
  66.     {
  67.         return $this->description;
  68.     }
  69.     public function setDescription(?string $description): self
  70.     {
  71.         $this->description $description;
  72.         return $this;
  73.     }
  74.     public function getQty(): ?float
  75.     {
  76.         return $this->qty;
  77.     }
  78.     public function setQty(float $qty): self
  79.     {
  80.         $this->qty $qty;
  81.         return $this;
  82.     }
  83.     public function getPrixRevient(): ?float
  84.     {
  85.         return $this->prixRevient;
  86.     }
  87.     public function setPrixRevient(?float $prixRevient): self
  88.     {
  89.         $this->prixRevient $prixRevient;
  90.         return $this;
  91.     }
  92.     public function getPrixVente(): ?float
  93.     {
  94.         return $this->prixVente;
  95.     }
  96.     public function setPrixVente(?float $prixVente): self
  97.     {
  98.         $this->prixVente $prixVente;
  99.         return $this;
  100.     }
  101.     public function getQrCode(): ?string
  102.     {
  103.         return $this->qrCode;
  104.     }
  105.     public function setQrCode(?string $qrCode): self
  106.     {
  107.         $this->qrCode $qrCode;
  108.         return $this;
  109.     }
  110.     /**
  111.      * @return Collection<int, OrderLine>
  112.      */
  113.     public function getOrderLines(): Collection
  114.     {
  115.         return $this->orderLines;
  116.     }
  117.     public function addOrderLine(OrderLine $orderLine): self
  118.     {
  119.         if (!$this->orderLines->contains($orderLine)) {
  120.             $this->orderLines->add($orderLine);
  121.             $orderLine->setProduct($this);
  122.         }
  123.         return $this;
  124.     }
  125.     public function removeOrderLine(OrderLine $orderLine): self
  126.     {
  127.         if ($this->orderLines->removeElement($orderLine)) {
  128.             // set the owning side to null (unless already changed)
  129.             if ($orderLine->getProduct() === $this) {
  130.                 $orderLine->setProduct(null);
  131.             }
  132.         }
  133.         return $this;
  134.     }
  135.     /**
  136.      * @return Collection<int, Stock>
  137.      */
  138.     public function getStocks(): Collection
  139.     {
  140.         return $this->stocks;
  141.     }
  142.     public function addStock(Stock $stock): self
  143.     {
  144.         if (!$this->stocks->contains($stock)) {
  145.             $this->stocks->add($stock);
  146.             $stock->setProduct($this);
  147.         }
  148.         return $this;
  149.     }
  150.     public function removeStock(Stock $stock): self
  151.     {
  152.         if ($this->stocks->removeElement($stock)) {
  153.             // set the owning side to null (unless already changed)
  154.             if ($stock->getProduct() === $this) {
  155.                 $stock->setProduct(null);
  156.             }
  157.         }
  158.         return $this;
  159.     }
  160.     public function __toString(): string
  161.     {
  162.         return $this->name;
  163.     }
  164. }