src/Entity/Category.php line 13

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CategoryRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. #[ORM\Entity(repositoryClassCategoryRepository::class)]
  9. #[UniqueEntity(fields"name"message"Naziv kategorije već postoji")]
  10. class Category
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column(type'integer')]
  15.     private $id;
  16.     #[ORM\Column(type'string'length255uniquetruenullabletrue)]
  17.     private $name;
  18.     #[ORM\Column(type'boolean'nullabletrue)]
  19.     private $isActive;
  20.     #[ORM\Column(type'string'length255nullabletrue)]
  21.     private $image;
  22.     #[ORM\ManyToOne(targetEntityCategory::class, inversedBy"subcategories")]
  23.     private $parent;
  24.     #[ORM\OneToMany(mappedBy"parent"targetEntityCategory::class)]
  25.     private $subcategories;
  26.     #[ORM\OneToMany(mappedBy'category'targetEntityArticle::class)]
  27.     private $articles;
  28.     #[ORM\Column(type'string'length255nullabletrue)]
  29.     private $slug;
  30.     #[ORM\OneToMany(mappedBy'category'targetEntityProduct::class)]
  31.     private $products;
  32.     #[ORM\Column(nullabletrue)]
  33.     private ?bool $extractHome null;
  34.     #[ORM\Column(nullabletrue)]
  35.     private ?bool $extractMenu null;
  36.     #[ORM\Column(length50nullabletrue)]
  37.     private ?string $iconClass null;
  38.     #[ORM\OneToMany(mappedBy'category'targetEntityCategoryTranslation::class)]
  39.     private Collection $categoryTranslations;
  40.     public function __construct()
  41.     {
  42.         $this->subcategories = new ArrayCollection();
  43.         $this->articles = new ArrayCollection();
  44.         $this->products = new ArrayCollection();
  45.         $this->categoryTranslations = new ArrayCollection();
  46.     }
  47.     public function getId(): ?int
  48.     {
  49.         return $this->id;
  50.     }
  51.     public function getName(): ?string
  52.     {
  53.         return $this->name;
  54.     }
  55.     public function setName(?string $name): self
  56.     {
  57.         $this->name $name;
  58.         return $this;
  59.     }
  60.     public function getIsActive(): ?bool
  61.     {
  62.         return $this->isActive;
  63.     }
  64.     public function setIsActive(?bool $isActive): self
  65.     {
  66.         $this->isActive $isActive;
  67.         return $this;
  68.     }
  69.     public function getImage(): ?string
  70.     {
  71.         return $this->image;
  72.     }
  73.     public function setImage(?string $image): self
  74.     {
  75.         $this->image $image;
  76.         return $this;
  77.     }
  78.     public function getParent(): ?self
  79.     {
  80.         return $this->parent;
  81.     }
  82.     public function setParent(?self $parent): self
  83.     {
  84.         $this->parent $parent;
  85.         return $this;
  86.     }
  87.     /**
  88.      * @return Collection
  89.      */
  90.     public function getSubcategories(): Collection
  91.     {
  92.         return $this->subcategories;
  93.     }
  94.     public function addSubcategory(self $subcategory): self
  95.     {
  96.         if (!$this->subcategories->contains($subcategory)) {
  97.             $this->subcategories[] = $subcategory;
  98.             $subcategory->setParent($this);
  99.         }
  100.         return $this;
  101.     }
  102.     public function removeSubcategory(self $subcategory): self
  103.     {
  104.         if ($this->subcategories->contains($subcategory)) {
  105.             $this->subcategories->removeElement($subcategory);
  106.             // set the owning side to null (unless already changed)
  107.             if ($subcategory->getParent() === $this) {
  108.                 $subcategory->setParent(null);
  109.             }
  110.         }
  111.         return $this;
  112.     }
  113.     /**
  114.      * @return Collection<int, Article>
  115.      */
  116.     public function getArticles(): Collection
  117.     {
  118.         return $this->articles;
  119.     }
  120.     public function addArticle(Article $article): self
  121.     {
  122.         if (!$this->articles->contains($article)) {
  123.             $this->articles[] = $article;
  124.             $article->setCategory($this);
  125.         }
  126.         return $this;
  127.     }
  128.     public function removeArticle(Article $article): self
  129.     {
  130.         if ($this->articles->removeElement($article)) {
  131.             // set the owning side to null (unless already changed)
  132.             if ($article->getCategory() === $this) {
  133.                 $article->setCategory(null);
  134.             }
  135.         }
  136.         return $this;
  137.     }
  138.     public function getSlug(): ?string
  139.     {
  140.         return $this->slug;
  141.     }
  142.     public function setSlug(?string $slug): self
  143.     {
  144.         $this->slug $slug;
  145.         return $this;
  146.     }
  147.     /**
  148.      * @return Collection<int, Product>
  149.      */
  150.     public function getProducts(): Collection
  151.     {
  152.         return $this->products;
  153.     }
  154.     public function addProduct(Product $product): self
  155.     {
  156.         if (!$this->products->contains($product)) {
  157.             $this->products[] = $product;
  158.             $product->setCategory($this);
  159.         }
  160.         return $this;
  161.     }
  162.     public function removeProduct(Product $product): self
  163.     {
  164.         if ($this->products->removeElement($product)) {
  165.             // set the owning side to null (unless already changed)
  166.             if ($product->getCategory() === $this) {
  167.                 $product->setCategory(null);
  168.             }
  169.         }
  170.         return $this;
  171.     }
  172.     public function isExtractHome(): ?bool
  173.     {
  174.         return $this->extractHome;
  175.     }
  176.     public function setExtractHome(?bool $extractHome): self
  177.     {
  178.         $this->extractHome $extractHome;
  179.         return $this;
  180.     }
  181.     public function isExtractMenu(): ?bool
  182.     {
  183.         return $this->extractMenu;
  184.     }
  185.     public function setExtractMenu(?bool $extractMenu): self
  186.     {
  187.         $this->extractMenu $extractMenu;
  188.         return $this;
  189.     }
  190.     public function getIconClass(): ?string
  191.     {
  192.         return $this->iconClass;
  193.     }
  194.     public function setIconClass(?string $iconClass): self
  195.     {
  196.         $this->iconClass $iconClass;
  197.         return $this;
  198.     }
  199.     /**
  200.      * @return Collection<int, CategoryTranslation>
  201.      */
  202.     public function getCategoryTranslations(): Collection
  203.     {
  204.         return $this->categoryTranslations;
  205.     }
  206.     public function addCategoryTranslation(CategoryTranslation $categoryTranslation): self
  207.     {
  208.         if (!$this->categoryTranslations->contains($categoryTranslation)) {
  209.             $this->categoryTranslations->add($categoryTranslation);
  210.             $categoryTranslation->setCategory($this);
  211.         }
  212.         return $this;
  213.     }
  214.     public function removeCategoryTranslation(CategoryTranslation $categoryTranslation): self
  215.     {
  216.         if ($this->categoryTranslations->removeElement($categoryTranslation)) {
  217.             // set the owning side to null (unless already changed)
  218.             if ($categoryTranslation->getCategory() === $this) {
  219.                 $categoryTranslation->setCategory(null);
  220.             }
  221.         }
  222.         return $this;
  223.     }
  224. }