<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\CategorieProduitsRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\SerializedName;
/**
* @ORM\Entity(repositoryClass=CategorieProduitsRepository::class)
* @ApiResource(normalizationContext={"groups"={"cat:read","panier"}})
*/
class CategorieProduits
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"cat:read","produit:read","commandes:read","user:read","produit:write"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"cat:read","produit:read","commandes:read","user:read","produit:write"})
*/
private $libelle;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $slug;
/**
* @ORM\ManyToOne(targetEntity=CategorieProduits::class, inversedBy="children")
*/
private $parent;
/**
* @ORM\OneToMany(targetEntity=CategorieProduits::class, mappedBy="parent")
*/
private $children;
/**
* @ORM\OneToMany(targetEntity=Produits::class, mappedBy="categorie")
* @Groups({"cat:read"})
*
*/
private $produits;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"cat:read","produit:read","commandes:read","user:read","produit:write"})
* @SerializedName("url")
*/
private $images;
public function __construct()
{
$this->children = new ArrayCollection();
$this->produits = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getLibelle(): ?string
{
return $this->libelle;
}
public function setLibelle(?string $libelle): self
{
$this->libelle = $libelle;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getChildren(): Collection
{
return $this->children;
}
public function addChild(self $child): self
{
if (!$this->children->contains($child)) {
$this->children[] = $child;
$child->setParent($this);
}
return $this;
}
public function removeChild(self $child): self
{
if ($this->children->removeElement($child)) {
// set the owning side to null (unless already changed)
if ($child->getParent() === $this) {
$child->setParent(null);
}
}
return $this;
}
/**
* @return Collection<int, Produits>
*/
public function getProduits(): Collection
{
return $this->produits;
}
public function addProduit(Produits $produit): self
{
if (!$this->produits->contains($produit)) {
$this->produits[] = $produit;
$produit->setCategorie($this);
}
return $this;
}
public function removeProduit(Produits $produit): self
{
if ($this->produits->removeElement($produit)) {
// set the owning side to null (unless already changed)
if ($produit->getCategorie() === $this) {
$produit->setCategorie(null);
}
}
return $this;
}
public function getImages(): ?string
{
return 'https://'.$_SERVER['SERVER_NAME'].'/uploads/images/categorie/'.$this->images;
}
public function setImages(?string $images): self
{
$this->images = $images;
return $this;
}
/**
* @Groups({"cat:read","produit:read","commandes:read","user:read","produit:write"})
*
*/
public function getUrl(){
return 'https://'.$_SERVER['SERVER_NAME'].'/uploads/images/categorie/'.$this->images;
}
}