src/Entity/ProductCategory.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. //use Symfony\Bridge\Doctrine\Validator\Constraints as DoctrineAssert;
  9. use Gedmo\Mapping\Annotation as Gedmo;
  10. /**
  11.  * @ORM\Entity
  12.  * @ORM\Table(name="product_category")
  13.  */
  14. class ProductCategory
  15. {
  16.     /**
  17.     * @ORM\Id
  18.     * @ORM\Column(type="integer")
  19.     * @ORM\GeneratedValue(strategy="AUTO")
  20.     */
  21.     protected $id;
  22.     /**
  23.     * @var boolean $public
  24.     *
  25.     * @ORM\Column(type="boolean", nullable=true)
  26.     */
  27.     protected $public;
  28.     /**
  29.     * @var string $name
  30.     *
  31.     * @ORM\Column(type="string", nullable=true)
  32.     */
  33.     protected $name;
  34.     /**
  35.      * @var string $slug
  36.      * @Gedmo\Slug(fields={"name"}, updatable=true, unique=true)
  37.      *
  38.      * @ORM\Column(type="string", nullable=true)
  39.      */
  40.     protected $slug;
  41.     /**
  42.     * @var \App\Entity\GeneralCategory $general_category
  43.      *
  44.      * @Assert\NotBlank(message="El campo no puede quedar vacio")
  45.     *
  46.     * @ORM\ManyToOne(targetEntity="App\Entity\GeneralCategory", inversedBy="product_categories")
  47.     * @ORM\JoinColumn(name="general_category_id", referencedColumnName="id")
  48.     */
  49.     private $general_category;
  50.     /**
  51.     * Many category have Many products.
  52.     * @ORM\ManyToMany(targetEntity="App\Entity\Product", mappedBy="categories")
  53.     */
  54.     private $products;
  55.     /**
  56.     * @var \App\Entity\Seo $seo
  57.     *
  58.     * @ORM\ManyToOne(targetEntity="App\Entity\Seo", inversedBy="product_category")
  59.     * @ORM\JoinColumn(name="seo_id", referencedColumnName="id")
  60.     */
  61.     private $seo;
  62.     /**
  63.      * @Gedmo\SortablePosition
  64.      * @var string $position
  65.      *
  66.      * @ORM\Column(type="integer", nullable=true)
  67.      */
  68.     protected $position;
  69.     /**
  70.      * @var string $create_at
  71.      *
  72.      * @Gedmo\Timestampable(on="create")
  73.      * @ORM\Column(type="datetime", nullable=true)
  74.      */
  75.     protected $create_at;
  76.     /**
  77.      * @var string $update_at
  78.      *
  79.      * @Gedmo\Timestampable(on="update")
  80.      * @ORM\Column(type="datetime", nullable=true)
  81.      */
  82.     protected $update_at;
  83.     public function __construct()
  84.     {
  85.         $this->products = new ArrayCollection();
  86.     }
  87.     public function __toString(): string
  88.     {
  89.         return $this->general_category->getName() . ' - ' $this->name;
  90.     }
  91.     public function getId(): ?int
  92.     {
  93.         return $this->id;
  94.     }
  95.     public function getName(): ?string
  96.     {
  97.         return $this->name;
  98.     }
  99.     public function setName(?string $name): static
  100.     {
  101.         $this->name $name;
  102.         return $this;
  103.     }
  104.     public function getSlug(): ?string
  105.     {
  106.         return $this->slug;
  107.     }
  108.     public function setSlug(?string $slug): static
  109.     {
  110.         $this->slug $slug;
  111.         return $this;
  112.     }
  113.     public function getCreateAt(): ?\DateTimeInterface
  114.     {
  115.         return $this->create_at;
  116.     }
  117.     public function setCreateAt(?\DateTimeInterface $create_at): static
  118.     {
  119.         $this->create_at $create_at;
  120.         return $this;
  121.     }
  122.     public function getUpdateAt(): ?\DateTimeInterface
  123.     {
  124.         return $this->update_at;
  125.     }
  126.     public function setUpdateAt(?\DateTimeInterface $update_at): static
  127.     {
  128.         $this->update_at $update_at;
  129.         return $this;
  130.     }
  131.     public function getGeneralCategory(): ?GeneralCategory
  132.     {
  133.         return $this->general_category;
  134.     }
  135.     public function setGeneralCategory(?GeneralCategory $general_category): static
  136.     {
  137.         $this->general_category $general_category;
  138.         return $this;
  139.     }
  140.     public function getSeo(): ?Seo
  141.     {
  142.         return $this->seo;
  143.     }
  144.     public function setSeo(?Seo $seo): static
  145.     {
  146.         $this->seo $seo;
  147.         return $this;
  148.     }
  149.     /**
  150.      * @return Collection<int, Product>
  151.      */
  152.     public function getProducts(): Collection
  153.     {
  154.         return $this->products;
  155.     }
  156.     public function addProduct(Product $product): static
  157.     {
  158.         if (!$this->products->contains($product)) {
  159.             $this->products->add($product);
  160.             $product->addCategory($this);
  161.         }
  162.         return $this;
  163.     }
  164.     public function removeProduct(Product $product): static
  165.     {
  166.         if ($this->products->removeElement($product)) {
  167.             $product->removeCategory($this);
  168.         }
  169.         return $this;
  170.     }
  171.     public function isPublic(): ?bool
  172.     {
  173.         return $this->public;
  174.     }
  175.     public function setPublic(?bool $public): static
  176.     {
  177.         $this->public $public;
  178.         return $this;
  179.     }
  180.     public function getPosition(): ?int
  181.     {
  182.         return $this->position;
  183.     }
  184.     public function setPosition(?int $position): static
  185.     {
  186.         $this->position $position;
  187.         return $this;
  188.     }
  189. }