<?php
namespace App\Entity;
use App\Repository\ProductRepository;
use Cocur\Slugify\Slugify;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ProductRepository::class)
* @ORM\HasLifecycleCallbacks
*
*/
class Product
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $subtitle;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $shortContent;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $longContent;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $instructions;
/**
* @ORM\Column(type="string", length=255)
*/
private $slug;
/**
* @ORM\ManyToMany(targetEntity=ProductCategory::class, inversedBy="products")
*/
private $category;
/**
* @ORM\ManyToMany(targetEntity=ProductAction::class, inversedBy="products")
*/
private $action;
/**
* @ORM\OneToMany(targetEntity=ProductImage::class, mappedBy="product", orphanRemoval=true, cascade={"persist"})
*/
private $productImages;
public function __construct()
{
$this->category = new ArrayCollection();
$this->action = new ArrayCollection();
$this->productImages = new ArrayCollection();
}
/**
* 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
* @ORM\PrePersist
* @ORM\PreUpdate
*
* @return void
*/
public function initializeSlug()
{
if(empty($this->slug))
{
$slugify = new Slugify();
$this->slug = $slugify->slugify($this->title);
}
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getSubtitle(): ?string
{
return $this->subtitle;
}
public function setSubtitle(?string $subtitle): self
{
$this->subtitle = $subtitle;
return $this;
}
public function getShortContent(): ?string
{
return $this->shortContent;
}
public function setShortContent(?string $shortContent): self
{
$this->shortContent = $shortContent;
return $this;
}
public function getLongContent(): ?string
{
return $this->longContent;
}
public function setLongContent(?string $longContent): self
{
$this->longContent = $longContent;
return $this;
}
public function getInstructions(): ?string
{
return $this->instructions;
}
public function setInstructions(?string $instructions): self
{
$this->instructions = $instructions;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
/**
* @return Collection<int, ProductCategory>
*/
public function getCategory(): Collection
{
return $this->category;
}
public function addCategory(ProductCategory $category): self
{
if (!$this->category->contains($category)) {
$this->category[] = $category;
}
return $this;
}
public function removeCategory(ProductCategory $category): self
{
$this->category->removeElement($category);
return $this;
}
/**
* @return Collection<int, ProductAction>
*/
public function getAction(): Collection
{
return $this->action;
}
public function addAction(ProductAction $action): self
{
if (!$this->action->contains($action)) {
$this->action[] = $action;
}
return $this;
}
public function removeAction(ProductAction $action): self
{
$this->action->removeElement($action);
return $this;
}
/**
* @return Collection<int, ProductImage>
*/
public function getProductImages(): Collection
{
return $this->productImages;
}
public function addProductImage(ProductImage $productImage): self
{
if (!$this->productImages->contains($productImage)) {
$this->productImages[] = $productImage;
$productImage->setProduct($this);
}
return $this;
}
public function removeProductImage(ProductImage $productImage): self
{
if ($this->productImages->removeElement($productImage)) {
// set the owning side to null (unless already changed)
if ($productImage->getProduct() === $this) {
$productImage->setProduct(null);
}
}
return $this;
}
}