<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Behaviors\TranslatableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\CategoryRepository")
* @ORM\EntityListeners({"App\Listener\EntityListener"})
* @Vich\Uploadable()
*/
class Category implements TranslatableInterface
{
use TranslatableTrait;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="boolean")
*/
private $isActive = true;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Category", inversedBy="subCategories")
*/
private $parent;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Category", mappedBy="parent", cascade={"persist"})
*/
private $subCategories;
/**
* @ORM\Column(type="datetime")
*/
private $createts;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User")
* @ORM\JoinColumn(nullable=true)
*/
private $createUser;
/**
* @Vich\UploadableField(mapping="category_image", fileNameProperty="image")
* @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg", "image/gif"})
* @var File|null
*/
private $imageFile;
/**
* @ORM\Column(type="string", length=199, nullable=true)
*/
private $image;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $editts;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User")
*/
private $editUser;
/**
* @ORM\Column(type="boolean")
*/
private $showProducts = true;
/**
* @ORM\Column(type="boolean")
*/
private $onlyForAdults = false;
/**
* @ORM\Column(type="boolean")
*/
private $showSize = true;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $orderBy;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="category", cascade={"persist"})
*/
private $products;
public function __construct()
{
$this->subCategories = new ArrayCollection();
$this->products = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection|self[]
*/
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;
}
public function getCreatets(): ?\DateTimeInterface
{
return $this->createts;
}
public function setCreatets(\DateTimeInterface $createts): self
{
$this->createts = $createts;
return $this;
}
public function getCreateUser(): ?User
{
return $this->createUser;
}
public function setCreateUser(?User $createUser): self
{
$this->createUser = $createUser;
return $this;
}
public function getEditts(): ?\DateTimeInterface
{
return $this->editts;
}
public function setEditts(?\DateTimeInterface $editts): self
{
$this->editts = $editts;
return $this;
}
public function getEditUser(): ?User
{
return $this->editUser;
}
public function setEditUser(?User $editUser): self
{
$this->editUser = $editUser;
return $this;
}
public function getOrderBy(): ?int
{
return $this->orderBy;
}
public function setOrderBy(?int $orderBy): self
{
$this->orderBy = $orderBy;
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
public function __call($method, $arguments)
{
$ret = $this->proxyCurrentLocaleTranslation($method, $arguments);
if(empty($ret)) {
$ret = call_user_func_array( [ $this->translate( \Locale::getDefault() ), $method ], $arguments );
}
return $ret;
}
/**
* Get ImageFile
*
* @return null|File
*/
public function getImageFile()
{
return $this->imageFile;
}
/**
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
*/
public function setImageFile(?File $imageFile = null): void
{
$this->imageFile = $imageFile;
if (null !== $imageFile) {
$this->editts = new \DateTime();
}
}
/**
* @return Collection|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->contains($product)) {
$this->products->removeElement($product);
// set the owning side to null (unless already changed)
if ($product->getCategory() === $this) {
$product->setCategory(null);
}
}
return $this;
}
public function getFullName()
{
$name=$this->getName();
$ex = $this;
while($ex->getParent() !== null){
$ex = $ex->getParent();
$name = $ex->getName().' -> '.$name;
}
return $name;
}
/**
* Get ShowProducts
*
* @return mixed
*/
public function getShowProducts()
{
return $this->showProducts;
}
/**
* Set ShowProducts
*
* @param mixed $showProducts
*/
public function setShowProducts( $showProducts )
{
$this->showProducts = $showProducts;
}
/**
* Get ShowSize
*
* @return mixed
*/
public function getShowSize()
{
return $this->showSize;
}
/**
* Set ShowSize
*
* @param mixed $showSize
*/
public function setShowSize( $showSize )
{
$this->showSize = $showSize;
}
/**
* Get OnlyForAdults
*
* @return mixed
*/
public function getOnlyForAdults()
{
return $this->onlyForAdults;
}
/**
* Set OnlyForAdults
*
* @param mixed $onlyForAdults
*/
public function setOnlyForAdults( $onlyForAdults )
{
$this->onlyForAdults = $onlyForAdults;
}
}