<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
//use Symfony\Bridge\Doctrine\Validator\Constraints as DoctrineAssert;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity
* @ORM\Table(name="product_category")
*/
class ProductCategory
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var boolean $public
*
* @ORM\Column(type="boolean", nullable=true)
*/
protected $public;
/**
* @var string $name
*
* @ORM\Column(type="string", nullable=true)
*/
protected $name;
/**
* @var string $slug
* @Gedmo\Slug(fields={"name"}, updatable=true, unique=true)
*
* @ORM\Column(type="string", nullable=true)
*/
protected $slug;
/**
* @var \App\Entity\GeneralCategory $general_category
*
* @Assert\NotBlank(message="El campo no puede quedar vacio")
*
* @ORM\ManyToOne(targetEntity="App\Entity\GeneralCategory", inversedBy="product_categories")
* @ORM\JoinColumn(name="general_category_id", referencedColumnName="id")
*/
private $general_category;
/**
* Many category have Many products.
* @ORM\ManyToMany(targetEntity="App\Entity\Product", mappedBy="categories")
*/
private $products;
/**
* @var \App\Entity\Seo $seo
*
* @ORM\ManyToOne(targetEntity="App\Entity\Seo", inversedBy="product_category")
* @ORM\JoinColumn(name="seo_id", referencedColumnName="id")
*/
private $seo;
/**
* @Gedmo\SortablePosition
* @var string $position
*
* @ORM\Column(type="integer", nullable=true)
*/
protected $position;
/**
* @var string $create_at
*
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime", nullable=true)
*/
protected $create_at;
/**
* @var string $update_at
*
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime", nullable=true)
*/
protected $update_at;
public function __construct()
{
$this->products = new ArrayCollection();
}
public function __toString(): string
{
return $this->general_category->getName() . ' - ' . $this->name;
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): static
{
$this->name = $name;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): static
{
$this->slug = $slug;
return $this;
}
public function getCreateAt(): ?\DateTimeInterface
{
return $this->create_at;
}
public function setCreateAt(?\DateTimeInterface $create_at): static
{
$this->create_at = $create_at;
return $this;
}
public function getUpdateAt(): ?\DateTimeInterface
{
return $this->update_at;
}
public function setUpdateAt(?\DateTimeInterface $update_at): static
{
$this->update_at = $update_at;
return $this;
}
public function getGeneralCategory(): ?GeneralCategory
{
return $this->general_category;
}
public function setGeneralCategory(?GeneralCategory $general_category): static
{
$this->general_category = $general_category;
return $this;
}
public function getSeo(): ?Seo
{
return $this->seo;
}
public function setSeo(?Seo $seo): static
{
$this->seo = $seo;
return $this;
}
/**
* @return Collection<int, Product>
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Product $product): static
{
if (!$this->products->contains($product)) {
$this->products->add($product);
$product->addCategory($this);
}
return $this;
}
public function removeProduct(Product $product): static
{
if ($this->products->removeElement($product)) {
$product->removeCategory($this);
}
return $this;
}
public function isPublic(): ?bool
{
return $this->public;
}
public function setPublic(?bool $public): static
{
$this->public = $public;
return $this;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(?int $position): static
{
$this->position = $position;
return $this;
}
}