src/Entity/CategorieProduits.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\CategorieProduitsRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Symfony\Component\Serializer\Annotation\SerializedName;
  10. /**
  11.  * @ORM\Entity(repositoryClass=CategorieProduitsRepository::class)
  12.  * @ApiResource(normalizationContext={"groups"={"cat:read","panier"}})
  13.  */
  14. class CategorieProduits
  15. {
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue
  19.      * @ORM\Column(type="integer")
  20.      * @Groups({"cat:read","produit:read","commandes:read","user:read","produit:write"})
  21.      */
  22.     private $id;
  23.     /**
  24.      * @ORM\Column(type="string", length=255, nullable=true)
  25.      * @Groups({"cat:read","produit:read","commandes:read","user:read","produit:write"})
  26.      */
  27.     private $libelle;
  28.     /**
  29.      * @ORM\Column(type="string", length=255, nullable=true)
  30.      */
  31.     private $slug;
  32.     /**
  33.      * @ORM\ManyToOne(targetEntity=CategorieProduits::class, inversedBy="children")
  34.      */
  35.     private $parent;
  36.     /**
  37.      * @ORM\OneToMany(targetEntity=CategorieProduits::class, mappedBy="parent")
  38.      */
  39.     private $children;
  40.     /**
  41.      * @ORM\OneToMany(targetEntity=Produits::class, mappedBy="categorie")
  42.      * @Groups({"cat:read"})
  43.      *
  44.      */
  45.     private $produits;
  46.     /**
  47.      * @ORM\Column(type="string", length=255, nullable=true)
  48.      * @Groups({"cat:read","produit:read","commandes:read","user:read","produit:write"})
  49.      * @SerializedName("url")
  50.      */
  51.     private $images;
  52.     public function __construct()
  53.     {
  54.         $this->children = new ArrayCollection();
  55.         $this->produits = new ArrayCollection();
  56.     }
  57.     public function getId(): ?int
  58.     {
  59.         return $this->id;
  60.     }
  61.     public function getLibelle(): ?string
  62.     {
  63.         return $this->libelle;
  64.     }
  65.     public function setLibelle(?string $libelle): self
  66.     {
  67.         $this->libelle $libelle;
  68.         return $this;
  69.     }
  70.     public function getSlug(): ?string
  71.     {
  72.         return $this->slug;
  73.     }
  74.     public function setSlug(?string $slug): self
  75.     {
  76.         $this->slug $slug;
  77.         return $this;
  78.     }
  79.     public function getParent(): ?self
  80.     {
  81.         return $this->parent;
  82.     }
  83.     public function setParent(?self $parent): self
  84.     {
  85.         $this->parent $parent;
  86.         return $this;
  87.     }
  88.     /**
  89.      * @return Collection<int, self>
  90.      */
  91.     public function getChildren(): Collection
  92.     {
  93.         return $this->children;
  94.     }
  95.     public function addChild(self $child): self
  96.     {
  97.         if (!$this->children->contains($child)) {
  98.             $this->children[] = $child;
  99.             $child->setParent($this);
  100.         }
  101.         return $this;
  102.     }
  103.     public function removeChild(self $child): self
  104.     {
  105.         if ($this->children->removeElement($child)) {
  106.             // set the owning side to null (unless already changed)
  107.             if ($child->getParent() === $this) {
  108.                 $child->setParent(null);
  109.             }
  110.         }
  111.         return $this;
  112.     }
  113.     /**
  114.      * @return Collection<int, Produits>
  115.      */
  116.     public function getProduits(): Collection
  117.     {
  118.         return $this->produits;
  119.     }
  120.     public function addProduit(Produits $produit): self
  121.     {
  122.         if (!$this->produits->contains($produit)) {
  123.             $this->produits[] = $produit;
  124.             $produit->setCategorie($this);
  125.         }
  126.         return $this;
  127.     }
  128.     public function removeProduit(Produits $produit): self
  129.     {
  130.         if ($this->produits->removeElement($produit)) {
  131.             // set the owning side to null (unless already changed)
  132.             if ($produit->getCategorie() === $this) {
  133.                 $produit->setCategorie(null);
  134.             }
  135.         }
  136.         return $this;
  137.     }
  138.     public function getImages(): ?string
  139.     {
  140.         return 'https://'.$_SERVER['SERVER_NAME'].'/uploads/images/categorie/'.$this->images;
  141.     }
  142.     public function setImages(?string $images): self
  143.     {
  144.         $this->images $images;
  145.         return $this;
  146.     }
  147.     /**
  148.      * @Groups({"cat:read","produit:read","commandes:read","user:read","produit:write"})
  149.      *
  150.      */
  151.     public function getUrl(){
  152.         return 'https://'.$_SERVER['SERVER_NAME'].'/uploads/images/categorie/'.$this->images;
  153.     }
  154. }