src/Entity/Tag.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\TagRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use JsonSerializable;
  8. /**
  9.  * @ORM\Entity(repositoryClass=TagRepository::class)
  10.  */
  11. class Tag implements JsonSerializable
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="string", length=255)
  21.      */
  22.     private $name;
  23.     /**
  24.      * @ORM\ManyToMany(targetEntity=Produit::class, mappedBy="tags")
  25.      */
  26.     private $produits;
  27.     public function __construct()
  28.     {
  29.         $this->produits = new ArrayCollection();
  30.     }
  31.     public function getId(): ?int
  32.     {
  33.         return $this->id;
  34.     }
  35.     public function getName(): ?string
  36.     {
  37.         return $this->name;
  38.     }
  39.     public function setName(string $name): self
  40.     {
  41.         $this->name $name;
  42.         return $this;
  43.     }
  44.     /**
  45.      * @return Collection|Produit[]
  46.      */
  47.     public function getProduits(): Collection
  48.     {
  49.         return $this->produits;
  50.     }
  51.     public function addProduit(Produit $produit): self
  52.     {
  53.         if (!$this->produits->contains($produit)) {
  54.             $this->produits[] = $produit;
  55.             $produit->addTag($this);
  56.         }
  57.         return $this;
  58.     }
  59.     public function removeProduit(Produit $produit): self
  60.     {
  61.         if ($this->produits->removeElement($produit)) {
  62.             $produit->removeTag($this);
  63.         }
  64.         return $this;
  65.     }
  66.     public function jsonSerialize()
  67.     {
  68.         return array(
  69.             'id' => $this->getId(),
  70.             //'produits' => $this->getProduits()->toArray(),
  71.         );
  72.     }
  73. }