src/Entity/Produits.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use Doctrine\ORM\Mapping\OrderBy;
  6. use Symfony\Component\HttpFoundation\File\File;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. use App\Repository\ProduitsRepository;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Gedmo\Mapping\Annotation as Gedmo;
  13. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  14. use ApiPlatform\Core\Bridge\Elasticsearch\DataProvider\Filter\OrderFilter;
  15. /**
  16.  * @ORM\Entity(repositoryClass=ProduitsRepository::class)
  17.  * @ApiResource(
  18.  * normalizationContext={"groups"={"produit:read"}, "skip_null_values" = false},
  19.  *
  20.  * denormalizationContext={"groups"={"produit:write"}} ,
  21.  *     attributes= {"pagination_items_per_page" = 10},
  22.  *     order= {"id" = "DESC"},
  23.  *     )
  24.  * @ApiFilter(SearchFilter::class, properties={"libelle" : "partial"})
  25.  * @ApiFilter(OrderFilter::class, properties={"id" : "DESC"})
  26.  *
  27.  * )
  28.  */
  29. class Produits
  30. {
  31.     /**
  32.      * @ORM\Id
  33.      * @ORM\GeneratedValue
  34.      * @ORM\Column(type="integer")
  35.      * @Groups({"produit:read","commandes:read","user:read","panier"})
  36.      *
  37.      */
  38.     private $id;
  39.     /**
  40.      * @ORM\Column(type="string", length=255, nullable=true)
  41.      * @Groups({"produit:read","commandes:read","user:read","panier","produit:write"})
  42.      */
  43.     private $libelle;
  44.     /**
  45.      * @ORM\Column(type="string", length=255, nullable=true)
  46.      * @Gedmo\Slug(fields={"libelle"})
  47.      */
  48.     private $slug;
  49.     /**
  50.      * @ORM\Column(type="text", nullable=true)
  51.      * @Groups({"produit:read","commandes:read","user:read","produit:write","panier"})
  52.      */
  53.     private $description;
  54.     /**
  55.      * @ORM\Column(type="datetime", nullable=true)
  56.      * @Groups({"produit:read","commandes:read","user:read","produit:write","panier"})
  57.      */
  58.     private $disponibilite;
  59.     /**
  60.      * @ORM\Column(type="string", length=255, nullable=true)
  61.      * @Groups({"produit:read","commandes:read","user:read","produit:write","panier"})
  62.      */
  63.     private $uniteMesure;
  64.     /**
  65.      * @ORM\Column(type="string", length=255, nullable=true)
  66.      * @Groups({"produit:read"})
  67.      */
  68.     private $typePrix;
  69.     /**
  70.      * @ORM\Column(type="float", nullable=true)
  71.      * @Groups({"produit:read","user:read","produit:write","panier"})
  72.      */
  73.     private $prix;
  74.     /**
  75.      * @ORM\Column(type="float", nullable=true)
  76.      * @Groups({"produit:read","user:read","produit:write","panier"})
  77.      */
  78.     private $stock;
  79.     /**
  80.      * @ORM\ManyToOne(targetEntity=Quartier::class, inversedBy="produit")
  81.      * @Groups({"produit:read","user:read","produit:write","panier"})
  82.      */
  83.     private $localite;
  84.     /**
  85.      * @ORM\Column(type="boolean", nullable=true)
  86.      * @Groups({"produit:read","user:read"})
  87.      */
  88.     private $valide;
  89.     /**
  90.      * @ORM\Column(type="boolean", nullable=true)
  91.      * @Groups({"produit:read","user:read"})
  92.      */
  93.     private $feature;
  94.     /**
  95.      * @ORM\Column(type="string", length=255, nullable=true)
  96.      * @Groups({"produit:read","user:read","produit:write"})
  97.      */
  98.     private $terminal;
  99.     /**
  100.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="produits")
  101.      * @Groups({"produit:read","commandes:read","produit:write"})
  102.      */
  103.     private $utilisateur;
  104.     /**
  105.      * @ORM\OneToMany(targetEntity=ImagesProduits::class, mappedBy="produit")
  106.      * @Groups({"produit:read","commandes:read","user:read","produit:write","panier"})
  107.      */
  108.     private $imagesProduits;
  109.     /**
  110.      * @ORM\OneToMany(targetEntity=LignesCommandes::class, mappedBy="produit")
  111.      *
  112.      */
  113.     private $lignesCommandes;
  114.     /**
  115.      * @ORM\OneToMany(targetEntity=Panier::class, mappedBy="produit")
  116.      */
  117.     private $paniers;
  118.     /**
  119.      * @ORM\Column(type="boolean", nullable=true)
  120.      * @Groups({"produit:read","commandes:read","user:read","produit:write"})
  121.      */
  122.     private $active;
  123.     /**
  124.      * @ORM\ManyToOne(targetEntity=CategorieProduits::class, inversedBy="produits")
  125.      * @Groups({"produit:read","commandes:read","produit:write"})
  126.      */
  127.     private $categorie;
  128.     /**
  129.      * @ORM\OneToMany(targetEntity=Produitstatsvisite::class, mappedBy="produit")
  130.      *
  131.      */
  132.     private $statsproduit;
  133.     /**
  134.      * @ORM\OneToMany(targetEntity=FavorisProduits::class, mappedBy="produit")
  135.      */
  136.     private $favoris;
  137.     public function __construct()
  138.     {
  139.         $this->imagesProduits = new ArrayCollection();
  140.         $this->lignesCommandes = new ArrayCollection();
  141.         $this->paniers = new ArrayCollection();
  142.         $this->active true;
  143.         $this->valide true;
  144.         $this->favoris = new ArrayCollection();
  145.         $this->statsproduit = new ArrayCollection();
  146.     }
  147.     public function getId(): ?int
  148.     {
  149.         return $this->id;
  150.     }
  151.     public function getLibelle(): ?string
  152.     {
  153.         return $this->libelle;
  154.     }
  155.     public function setLibelle(?string $libelle): self
  156.     {
  157.         $this->libelle $libelle;
  158.         return $this;
  159.     }
  160.     public function getSlug(): ?string
  161.     {
  162.         return $this->slug;
  163.     }
  164.     public function setSlug(?string $slug): self
  165.     {
  166.         $this->slug $slug;
  167.         return $this;
  168.     }
  169.     public function getDescription(): ?string
  170.     {
  171.         return $this->description;
  172.     }
  173.     public function setDescription(?string $description): self
  174.     {
  175.         $this->description $description;
  176.         return $this;
  177.     }
  178.     public function getDisponibilite(): ?\DateTime
  179.     {
  180.         return $this->disponibilite;
  181.     }
  182.     public function setDisponibilite(?\DateTime $disponibilite): self
  183.     {
  184.         $this->disponibilite $disponibilite;
  185.         return $this;
  186.     }
  187.     public function getUniteMesure(): ?string
  188.     {
  189.         return $this->uniteMesure;
  190.     }
  191.     public function setUniteMesure(?string $uniteMesure): self
  192.     {
  193.         $this->uniteMesure $uniteMesure;
  194.         return $this;
  195.     }
  196.     public function getTypePrix(): ?string
  197.     {
  198.         return $this->typePrix;
  199.     }
  200.     public function setTypePrix(?string $typePrix): self
  201.     {
  202.         $this->typePrix $typePrix;
  203.         return $this;
  204.     }
  205.     public function getPrix(): ?float
  206.     {
  207.         return $this->prix;
  208.     }
  209.     public function setPrix(?float $prix): self
  210.     {
  211.         $this->prix $prix;
  212.         return $this;
  213.     }
  214.     public function getStock(): ?float
  215.     {
  216.         return $this->stock;
  217.     }
  218.     public function setStock(?float $stock): self
  219.     {
  220.         $this->stock $stock;
  221.         return $this;
  222.     }
  223.     public function getLocalite(): ?Quartier
  224.     {
  225.         return $this->localite;
  226.     }
  227.     public function setLocalite(?Quartier $localite): self
  228.     {
  229.         $this->localite $localite;
  230.         return $this;
  231.     }
  232.     public function isValide(): ?bool
  233.     {
  234.         return $this->valide;
  235.     }
  236.     public function setValide(?bool $valide): self
  237.     {
  238.         $this->valide $valide;
  239.         return $this;
  240.     }
  241.     public function isFeature(): ?bool
  242.     {
  243.         return $this->feature;
  244.     }
  245.     public function setFeature(?bool $feature): self
  246.     {
  247.         $this->feature $feature;
  248.         return $this;
  249.     }
  250.     public function getTerminal(): ?string
  251.     {
  252.         return $this->terminal;
  253.     }
  254.     public function setTerminal(?string $terminal): self
  255.     {
  256.         $this->terminal $terminal;
  257.         return $this;
  258.     }
  259.     public function getUtilisateur(): ?User
  260.     {
  261.         return $this->utilisateur;
  262.     }
  263.     public function setUtilisateur(?User $utilisateur): self
  264.     {
  265.         $this->utilisateur $utilisateur;
  266.         return $this;
  267.     }
  268.     /**
  269.      * @return Collection<int, ImagesProduits>
  270.      */
  271.     public function getImagesProduits(): Collection
  272.     {
  273.         return $this->imagesProduits;
  274.     }
  275.     public function addImagesProduit(ImagesProduits $imagesProduit): self
  276.     {
  277.         if (!$this->imagesProduits->contains($imagesProduit)) {
  278.             $this->imagesProduits[] = $imagesProduit;
  279.             $imagesProduit->setProduit($this);
  280.         }
  281.         return $this;
  282.     }
  283.     public function removeImagesProduit(ImagesProduits $imagesProduit): self
  284.     {
  285.         if ($this->imagesProduits->removeElement($imagesProduit)) {
  286.             // set the owning side to null (unless already changed)
  287.             if ($imagesProduit->getProduit() === $this) {
  288.                 $imagesProduit->setProduit(null);
  289.             }
  290.         }
  291.         return $this;
  292.     }
  293.     /**
  294.      * @return Collection<int, LignesCommandes>
  295.      */
  296.     public function getLignesCommandes(): Collection
  297.     {
  298.         return $this->lignesCommandes;
  299.     }
  300.     public function addLignesCommande(LignesCommandes $lignesCommande): self
  301.     {
  302.         if (!$this->lignesCommandes->contains($lignesCommande)) {
  303.             $this->lignesCommandes[] = $lignesCommande;
  304.             $lignesCommande->setProduit($this);
  305.         }
  306.         return $this;
  307.     }
  308.     public function removeLignesCommande(LignesCommandes $lignesCommande): self
  309.     {
  310.         if ($this->lignesCommandes->removeElement($lignesCommande)) {
  311.             // set the owning side to null (unless already changed)
  312.             if ($lignesCommande->getProduit() === $this) {
  313.                 $lignesCommande->setProduit(null);
  314.             }
  315.         }
  316.         return $this;
  317.     }
  318.     /**
  319.      * @return Collection<int, Panier>
  320.      */
  321.     public function getPaniers(): Collection
  322.     {
  323.         return $this->paniers;
  324.     }
  325.     public function addPanier(Panier $panier): self
  326.     {
  327.         if (!$this->paniers->contains($panier)) {
  328.             $this->paniers[] = $panier;
  329.             $panier->setProduit($this);
  330.         }
  331.         return $this;
  332.     }
  333.     public function removePanier(Panier $panier): self
  334.     {
  335.         if ($this->paniers->removeElement($panier)) {
  336.             // set the owning side to null (unless already changed)
  337.             if ($panier->getProduit() === $this) {
  338.                 $panier->setProduit(null);
  339.             }
  340.         }
  341.         return $this;
  342.     }
  343.     public function isActive(): ?bool
  344.     {
  345.         return $this->active;
  346.     }
  347.     public function setActive(?bool $active): self
  348.     {
  349.         $this->active $active;
  350.         return $this;
  351.     }
  352.     public function getCategorie(): ?CategorieProduits
  353.     {
  354.         return $this->categorie;
  355.     }
  356.     public function setCategorie(?CategorieProduits $categorie): self
  357.     {
  358.         $this->categorie $categorie;
  359.         return $this;
  360.     }
  361.     /**
  362.      * @return Collection<int, FavorisProduits>
  363.      */
  364.     public function getFavoris(): Collection
  365.     {
  366.         return $this->favoris;
  367.     }
  368.     public function addFavori(FavorisProduits $favori): self
  369.     {
  370.         if (!$this->favoris->contains($favori)) {
  371.             $this->favoris[] = $favori;
  372.             $favori->setProduit($this);
  373.         }
  374.         return $this;
  375.     }
  376.     public function removeFavori(FavorisProduits $favori): self
  377.     {
  378.         if ($this->favoris->removeElement($favori)) {
  379.             // set the owning side to null (unless already changed)
  380.             if ($favori->getProduit() === $this) {
  381.                 $favori->setProduit(null);
  382.             }
  383.         }
  384.         return $this;
  385.     }
  386.     /**
  387.      * Permet d'obtenir la moyenne globale des notes pour cette annonce
  388.      *
  389.      * @return float
  390.      */
  391.     public function getNbVisite()
  392.     {
  393.         // Calculer la somme des notations
  394.         $sum array_reduce($this->statsproduit->toArray(), function ($total$comment) {
  395.             return $total $comment->getNbVisite();
  396.         }, 0);
  397.         // Faire la division avec le nombre de notes
  398.         if (count($this->statsproduit) > 0) return $sum;
  399.         return 0;
  400.     }
  401.     /**
  402.      * @return Collection|Produitstatsvisite[]
  403.      */
  404.     public function getStatsproduit(): Collection
  405.     {
  406.         return $this->statsproduit;
  407.     }
  408.     public function addStatsproduit(Produitstatsvisite $statsproduit): self
  409.     {
  410.         if (!$this->statsproduit->contains($statsproduit)) {
  411.             $this->statsproduit[] = $statsproduit;
  412.             $statsproduit->setProduit($this);
  413.         }
  414.         return $this;
  415.     }
  416.     public function removeStatsproduit(Produitstatsvisite $statsproduit): self
  417.     {
  418.         if ($this->statsproduit->contains($statsproduit)) {
  419.             $this->statsproduit->removeElement($statsproduit);
  420.             // set the owning side to null (unless already changed)
  421.             if ($statsproduit->getProduit() === $this) {
  422.                 $statsproduit->setProduit(null);
  423.             }
  424.         }
  425.         return $this;
  426.     }
  427. }