src/Entity/Category.php line 13
<?php
namespace App\Entity;
use App\Repository\CategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
#[ORM\Entity(repositoryClass: CategoryRepository::class)]
#[UniqueEntity(fields: "name", message: "Naziv kategorije već postoji")]
class Category
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255, unique: true, nullable: true)]
private $name;
#[ORM\Column(type: 'boolean', nullable: true)]
private $isActive;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $image;
#[ORM\ManyToOne(targetEntity: Category::class, inversedBy: "subcategories")]
private $parent;
#[ORM\OneToMany(mappedBy: "parent", targetEntity: Category::class)]
private $subcategories;
#[ORM\OneToMany(mappedBy: 'category', targetEntity: Article::class)]
private $articles;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $slug;
#[ORM\OneToMany(mappedBy: 'category', targetEntity: Product::class)]
private $products;
#[ORM\Column(nullable: true)]
private ?bool $extractHome = null;
#[ORM\Column(nullable: true)]
private ?bool $extractMenu = null;
#[ORM\Column(length: 50, nullable: true)]
private ?string $iconClass = null;
#[ORM\OneToMany(mappedBy: 'category', targetEntity: CategoryTranslation::class)]
private Collection $categoryTranslations;
public function __construct()
{
$this->subcategories = new ArrayCollection();
$this->articles = new ArrayCollection();
$this->products = new ArrayCollection();
$this->categoryTranslations = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(?bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection
*/
public function getSubcategories(): Collection
{
return $this->subcategories;
}
public function addSubcategory(self $subcategory): self
{
if (!$this->subcategories->contains($subcategory)) {
$this->subcategories[] = $subcategory;
$subcategory->setParent($this);
}
return $this;
}
public function removeSubcategory(self $subcategory): self
{
if ($this->subcategories->contains($subcategory)) {
$this->subcategories->removeElement($subcategory);
// set the owning side to null (unless already changed)
if ($subcategory->getParent() === $this) {
$subcategory->setParent(null);
}
}
return $this;
}
/**
* @return Collection<int, Article>
*/
public function getArticles(): Collection
{
return $this->articles;
}
public function addArticle(Article $article): self
{
if (!$this->articles->contains($article)) {
$this->articles[] = $article;
$article->setCategory($this);
}
return $this;
}
public function removeArticle(Article $article): self
{
if ($this->articles->removeElement($article)) {
// set the owning side to null (unless already changed)
if ($article->getCategory() === $this) {
$article->setCategory(null);
}
}
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): self
{
$this->slug = $slug;
return $this;
}
/**
* @return Collection<int, Product>
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Product $product): self
{
if (!$this->products->contains($product)) {
$this->products[] = $product;
$product->setCategory($this);
}
return $this;
}
public function removeProduct(Product $product): self
{
if ($this->products->removeElement($product)) {
// set the owning side to null (unless already changed)
if ($product->getCategory() === $this) {
$product->setCategory(null);
}
}
return $this;
}
public function isExtractHome(): ?bool
{
return $this->extractHome;
}
public function setExtractHome(?bool $extractHome): self
{
$this->extractHome = $extractHome;
return $this;
}
public function isExtractMenu(): ?bool
{
return $this->extractMenu;
}
public function setExtractMenu(?bool $extractMenu): self
{
$this->extractMenu = $extractMenu;
return $this;
}
public function getIconClass(): ?string
{
return $this->iconClass;
}
public function setIconClass(?string $iconClass): self
{
$this->iconClass = $iconClass;
return $this;
}
/**
* @return Collection<int, CategoryTranslation>
*/
public function getCategoryTranslations(): Collection
{
return $this->categoryTranslations;
}
public function addCategoryTranslation(CategoryTranslation $categoryTranslation): self
{
if (!$this->categoryTranslations->contains($categoryTranslation)) {
$this->categoryTranslations->add($categoryTranslation);
$categoryTranslation->setCategory($this);
}
return $this;
}
public function removeCategoryTranslation(CategoryTranslation $categoryTranslation): self
{
if ($this->categoryTranslations->removeElement($categoryTranslation)) {
// set the owning side to null (unless already changed)
if ($categoryTranslation->getCategory() === $this) {
$categoryTranslation->setCategory(null);
}
}
return $this;
}
}