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 string $image
  43.     *
  44.     * @ORM\ManyToOne(targetEntity="App\Entity\SonataMediaMedia", cascade = {"persist"})
  45.     * @ORM\JoinColumn(name="image_id", referencedColumnName="id", onDelete="SET NULL")
  46.     */
  47.     protected $image;
  48.     /**
  49.     * @var \App\Entity\GeneralCategory $general_category
  50.      *
  51.      * @Assert\NotBlank(message="El campo no puede quedar vacio")
  52.     *
  53.     * @ORM\ManyToOne(targetEntity="App\Entity\GeneralCategory", inversedBy="product_categories")
  54.     * @ORM\JoinColumn(name="general_category_id", referencedColumnName="id")
  55.     */
  56.     private $general_category;
  57.     /**
  58.     * Many category have Many products.
  59.     * @ORM\ManyToMany(targetEntity="App\Entity\Product", mappedBy="categories")
  60.     */
  61.     private $products;
  62.     /**
  63.     * @var \App\Entity\Seo $seo
  64.     *
  65.     * @ORM\ManyToOne(targetEntity="App\Entity\Seo", inversedBy="product_category")
  66.     * @ORM\JoinColumn(name="seo_id", referencedColumnName="id")
  67.     */
  68.     private $seo;
  69.     /**
  70.      * @Gedmo\SortablePosition
  71.      * @var string $position
  72.      *
  73.      * @ORM\Column(type="integer", nullable=true)
  74.      */
  75.     protected $position;
  76.     /**
  77.      * @var string $create_at
  78.      *
  79.      * @Gedmo\Timestampable(on="create")
  80.      * @ORM\Column(type="datetime", nullable=true)
  81.      */
  82.     protected $create_at;
  83.     /**
  84.      * @var string $update_at
  85.      *
  86.      * @Gedmo\Timestampable(on="update")
  87.      * @ORM\Column(type="datetime", nullable=true)
  88.      */
  89.     protected $update_at;
  90.     public function __construct()
  91.     {
  92.         $this->products = new ArrayCollection();
  93.     }
  94.     public function __toString(): string
  95.     {
  96.         return $this->general_category->getName() . ' - ' $this->name;
  97.     }
  98.     public function getId(): ?int
  99.     {
  100.         return $this->id;
  101.     }
  102.     public function getName(): ?string
  103.     {
  104.         return $this->name;
  105.     }
  106.     public function setName(?string $name): static
  107.     {
  108.         $this->name $name;
  109.         return $this;
  110.     }
  111.     public function getSlug(): ?string
  112.     {
  113.         return $this->slug;
  114.     }
  115.     public function setSlug(?string $slug): static
  116.     {
  117.         $this->slug $slug;
  118.         return $this;
  119.     }
  120.     public function getCreateAt(): ?\DateTimeInterface
  121.     {
  122.         return $this->create_at;
  123.     }
  124.     public function setCreateAt(?\DateTimeInterface $create_at): static
  125.     {
  126.         $this->create_at $create_at;
  127.         return $this;
  128.     }
  129.     public function getUpdateAt(): ?\DateTimeInterface
  130.     {
  131.         return $this->update_at;
  132.     }
  133.     public function setUpdateAt(?\DateTimeInterface $update_at): static
  134.     {
  135.         $this->update_at $update_at;
  136.         return $this;
  137.     }
  138.     public function getGeneralCategory(): ?GeneralCategory
  139.     {
  140.         return $this->general_category;
  141.     }
  142.     public function setGeneralCategory(?GeneralCategory $general_category): static
  143.     {
  144.         $this->general_category $general_category;
  145.         return $this;
  146.     }
  147.     public function getSeo(): ?Seo
  148.     {
  149.         return $this->seo;
  150.     }
  151.     public function setSeo(?Seo $seo): static
  152.     {
  153.         $this->seo $seo;
  154.         return $this;
  155.     }
  156.     /**
  157.      * @return Collection<int, Product>
  158.      */
  159.     public function getProducts(): Collection
  160.     {
  161.         return $this->products;
  162.     }
  163.     public function addProduct(Product $product): static
  164.     {
  165.         if (!$this->products->contains($product)) {
  166.             $this->products->add($product);
  167.             $product->addCategory($this);
  168.         }
  169.         return $this;
  170.     }
  171.     public function removeProduct(Product $product): static
  172.     {
  173.         if ($this->products->removeElement($product)) {
  174.             $product->removeCategory($this);
  175.         }
  176.         return $this;
  177.     }
  178.     public function isPublic(): ?bool
  179.     {
  180.         return $this->public;
  181.     }
  182.     public function setPublic(?bool $public): static
  183.     {
  184.         $this->public $public;
  185.         return $this;
  186.     }
  187.     public function getPosition(): ?int
  188.     {
  189.         return $this->position;
  190.     }
  191.     public function setPosition(?int $position): static
  192.     {
  193.         $this->position $position;
  194.         return $this;
  195.     }
  196.     public function getImage(): ?SonataMediaMedia
  197.     {
  198.         return $this->image;
  199.     }
  200.     public function setImage(?SonataMediaMedia $image): static
  201.     {
  202.         $this->image $image;
  203.         return $this;
  204.     }
  205. }