src/Entity/Promote.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\PromoteRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=PromoteRepository::class)
  9.  */
  10. class Promote
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=255)
  20.      */
  21.     private $name;
  22.     /**
  23.      * @ORM\ManyToMany(targetEntity=Product::class, mappedBy="promotes")
  24.      * @ORM\OrderBy({"createdAt" = "DESC"})
  25.      */
  26.     private $products;
  27.     public function __construct()
  28.     {
  29.         $this->products = 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|Product[]
  46.      */
  47.     public function getProducts(): Collection
  48.     {
  49.         return $this->products;
  50.     }
  51.     public function addProduct(Product $product): self
  52.     {
  53.         if (!$this->products->contains($product)) {
  54.             $this->products[] = $product;
  55.             $product->addPromote($this);
  56.         }
  57.         return $this;
  58.     }
  59.     public function removeProduct(Product $product): self
  60.     {
  61.         if ($this->products->removeElement($product)) {
  62.             $product->removePromote($this);
  63.         }
  64.         return $this;
  65.     }
  66.     public function __toString()
  67.     {
  68.         return $this->name;
  69.     }
  70. }