src/Entity/Product.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ProductRepository;
  4. use Cocur\Slugify\Slugify;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ORM\Entity(repositoryClass=ProductRepository::class)
  10.  * @ORM\HasLifecycleCallbacks
  11.  *
  12.  */
  13. class Product
  14. {
  15.     /**
  16.      * @ORM\Id
  17.      * @ORM\GeneratedValue
  18.      * @ORM\Column(type="integer")
  19.      */
  20.     private $id;
  21.     /**
  22.      * @ORM\Column(type="string", length=255)
  23.      */
  24.     private $title;
  25.     /**
  26.      * @ORM\Column(type="string", length=255, nullable=true)
  27.      */
  28.     private $subtitle;
  29.     /**
  30.      * @ORM\Column(type="text", nullable=true)
  31.      */
  32.     private $shortContent;
  33.     /**
  34.      * @ORM\Column(type="text", nullable=true)
  35.      */
  36.     private $longContent;
  37.     /**
  38.      * @ORM\Column(type="text", nullable=true)
  39.      */
  40.     private $instructions;
  41.     /**
  42.      * @ORM\Column(type="string", length=255)
  43.      */
  44.     private $slug;
  45.     /**
  46.      * @ORM\ManyToMany(targetEntity=ProductCategory::class, inversedBy="products")
  47.      */
  48.     private $category;
  49.     /**
  50.      * @ORM\ManyToMany(targetEntity=ProductAction::class, inversedBy="products")
  51.      */
  52.     private $action;
  53.     /**
  54.      * @ORM\OneToMany(targetEntity=ProductImage::class, mappedBy="product", orphanRemoval=true, cascade={"persist"})
  55.      */
  56.     private $productImages;
  57.     public function __construct()
  58.     {
  59.         $this->category = new ArrayCollection();
  60.         $this->action = new ArrayCollection();
  61.         $this->productImages = new ArrayCollection();
  62.     }
  63.     /**
  64.      * Permet d'initialiser le slug : ici > avec le persist et avant l'update, si il n'y a pas de slug, on le crée avec le title
  65.      * @ORM\PrePersist
  66.      * @ORM\PreUpdate
  67.      *
  68.      * @return void
  69.      */
  70.     public function initializeSlug()
  71.     {
  72.         if(empty($this->slug))
  73.         {
  74.             $slugify = new Slugify();
  75.             $this->slug $slugify->slugify($this->title);
  76.         }
  77.     }
  78.     public function getId(): ?int
  79.     {
  80.         return $this->id;
  81.     }
  82.     public function getTitle(): ?string
  83.     {
  84.         return $this->title;
  85.     }
  86.     public function setTitle(string $title): self
  87.     {
  88.         $this->title $title;
  89.         return $this;
  90.     }
  91.     public function getSubtitle(): ?string
  92.     {
  93.         return $this->subtitle;
  94.     }
  95.     public function setSubtitle(?string $subtitle): self
  96.     {
  97.         $this->subtitle $subtitle;
  98.         return $this;
  99.     }
  100.     public function getShortContent(): ?string
  101.     {
  102.         return $this->shortContent;
  103.     }
  104.     public function setShortContent(?string $shortContent): self
  105.     {
  106.         $this->shortContent $shortContent;
  107.         return $this;
  108.     }
  109.     public function getLongContent(): ?string
  110.     {
  111.         return $this->longContent;
  112.     }
  113.     public function setLongContent(?string $longContent): self
  114.     {
  115.         $this->longContent $longContent;
  116.         return $this;
  117.     }
  118.     public function getInstructions(): ?string
  119.     {
  120.         return $this->instructions;
  121.     }
  122.     public function setInstructions(?string $instructions): self
  123.     {
  124.         $this->instructions $instructions;
  125.         return $this;
  126.     }
  127.     public function getSlug(): ?string
  128.     {
  129.         return $this->slug;
  130.     }
  131.     public function setSlug(string $slug): self
  132.     {
  133.         $this->slug $slug;
  134.         return $this;
  135.     }
  136.     /**
  137.      * @return Collection<int, ProductCategory>
  138.      */
  139.     public function getCategory(): Collection
  140.     {
  141.         return $this->category;
  142.     }
  143.     public function addCategory(ProductCategory $category): self
  144.     {
  145.         if (!$this->category->contains($category)) {
  146.             $this->category[] = $category;
  147.         }
  148.         return $this;
  149.     }
  150.     public function removeCategory(ProductCategory $category): self
  151.     {
  152.         $this->category->removeElement($category);
  153.         return $this;
  154.     }
  155.     /**
  156.      * @return Collection<int, ProductAction>
  157.      */
  158.     public function getAction(): Collection
  159.     {
  160.         return $this->action;
  161.     }
  162.     public function addAction(ProductAction $action): self
  163.     {
  164.         if (!$this->action->contains($action)) {
  165.             $this->action[] = $action;
  166.         }
  167.         return $this;
  168.     }
  169.     public function removeAction(ProductAction $action): self
  170.     {
  171.         $this->action->removeElement($action);
  172.         return $this;
  173.     }
  174.     /**
  175.      * @return Collection<int, ProductImage>
  176.      */
  177.     public function getProductImages(): Collection
  178.     {
  179.         return $this->productImages;
  180.     }
  181.     public function addProductImage(ProductImage $productImage): self
  182.     {
  183.         if (!$this->productImages->contains($productImage)) {
  184.             $this->productImages[] = $productImage;
  185.             $productImage->setProduct($this);
  186.         }
  187.         return $this;
  188.     }
  189.     public function removeProductImage(ProductImage $productImage): self
  190.     {
  191.         if ($this->productImages->removeElement($productImage)) {
  192.             // set the owning side to null (unless already changed)
  193.             if ($productImage->getProduct() === $this) {
  194.                 $productImage->setProduct(null);
  195.             }
  196.         }
  197.         return $this;
  198.     }
  199. }