<?php
namespace App\Entity;
use Knp\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface;
use Knp\DoctrineBehaviors\Model\SoftDeletable\SoftDeletableTrait;
use Knp\DoctrineBehaviors\Model\Blameable\BlameableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\BlameableInterface;
use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
use App\Model\LangParamInterface;
use App\Model\LangParamRelationInterface;
use AppBundle\Entity\Article;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity
* @ORM\Table(name="category")
*/
class Category implements TranslatableInterface, LangParamInterface
, BlameableInterface, TimestampableInterface, SoftDeletableInterface {
use BlameableTrait;
use TimestampableTrait;
use TranslatableTrait;
use SoftDeletableTrait;
const TYPE_24h = 209;
const TYPE_OUTLET = 237;
const TYPE_SZOK_CENOWY = 121;
const TYPE_NEW_PRODUCTS = 316;
const TYPE_BESTSELLERS = 315;
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* Obsługa tłumaczeń
* @param $method
* @param $arguments
* @return mixed
*/
public function __call($method, $arguments)
{
return $this->proxyCurrentLocaleTranslation($method, $arguments);
}
public function getName()
{
return $this->translate()->getName();
}
public function getDescription()
{
return $this->translate()->getDescription();
}
public function getMetaDescription()
{
return $this->translate()->getMetaDescription();
}
public function getMetaTitle()
{
return $this->translate()->getMetaTitle();
}
public function getCanonical()
{
return $this->translate()->getCanonical();
}
public function getMetaKeywords()
{
return $this->translate()->getMetaKeywords();
}
public function getSlug()
{
if ($this->translate()->getSlug()) {
return $this->translate()->getSlug();
} else {
return '-';
}
}
public function getShortDescription()
{
return $this->translate()->getShortDescription();
}
public function getGoogleProductCategory()
{
return $this->translate()->getGoogleProductCategory();
}
public function getGoogleProductType()
{
return $this->translate()->getGoogleProductType();
}
public function getSpecialProductCategory()
{
return $this->translate()->getSpecialProductCategory();
}
/**
* @var string
*
* @ORM\Column(name="level", type="string", length=255, nullable=true)
*/
private $level;
/**
* @var integer
*
* @ORM\Column(name="position", type="integer", length=8, nullable=true)
*/
private $position;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Category", cascade={"all"}, inversedBy="children")
* @ORM\JoinColumn(name="category_parent_id", referencedColumnName="id", onDelete="CASCADE")
*/
protected $parent;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Category", mappedBy="parent", cascade={"persist"})
* @Doctrine\ORM\Mapping\OrderBy({"position" = "ASC"})
*/
protected $children;
/**
* @Doctrine\ORM\Mapping\ManyToMany(targetEntity="App\Entity\Category", mappedBy="parents")
* @Doctrine\ORM\Mapping\OrderBy({"position" = "ASC"})
**/
protected $childrens;
/**
* @Doctrine\ORM\Mapping\ManyToMany(targetEntity="App\Entity\Category", inversedBy="childrens")
* @Doctrine\ORM\Mapping\JoinTable(name="category_parent_relation",
* joinColumns={@Doctrine\ORM\Mapping\JoinColumn(name="category_id", referencedColumnName="id")},
* inverseJoinColumns={@Doctrine\ORM\Mapping\JoinColumn(name="parent_id", referencedColumnName="id")}
* )
**/
protected $parents;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductCategory", mappedBy="category", cascade={"persist"})
* @Doctrine\ORM\Mapping\OrderBy({"position" = "ASC"})
*/
protected $products;
/**
* @ORM\OneToMany(targetEntity="App\Entity\CompareParameter", mappedBy="category", cascade={"persist"})
*/
protected $compareParameters;
/**
* @ORM\OneToMany(targetEntity="App\Entity\CategoryLangParam", mappedBy="category", cascade={"all"})
*/
protected $langParams;
/**
* @Doctrine\ORM\Mapping\ManyToMany(targetEntity="App\Entity\ProductParameter")
* @Doctrine\ORM\Mapping\JoinTable(name="category_parameter_relations")
*/
private $parameters;
/**
* @var string
*
* @ORM\Column(name="alt", type="string", length=255, nullable=true)
*/
private $alt;
/**
* @var string
*
* @ORM\Column(name="image_custom_name", type="string", length=255, nullable=true)
*/
private $imageCustomName;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set level
*
* @param string $level
*
* @return Category
*/
public function setLevel($level)
{
$this->level = $level;
return $this;
}
/**
* Get level
*
* @return string
*/
public function getLevel()
{
return $this->level;
}
/**
*
* note This is not a mapped field of entity metadata, just a simple property.
*
* @var File $imageFile
*/
protected $imageFile2;
/**
* @ORM\Column(type="string", length=255, name="image_name_2", nullable=true)
* @var string $imageName2
*/
protected $imageName2;
/////
///
///
/**
*
* note This is not a mapped field of entity metadata, just a simple property.
*
* @var File $imageFile3
*/
protected $imageFile3;
/**
* Mobile zdjęcie kategorii
* @ORM\Column(type="string", length=255, name="image_name_3", nullable=true)
* @var string $imageName3
*/
protected $imageName3;
public function setImageFile3(File $image3 = null)
{
$this->imageFile3 = $image3;
if ($image3) {
$fileName3 = md5(uniqid()).'.'.$image3->guessExtension();
// Move the file to the directory where brochures are stored
$brochuresDir = getcwd().'/images/category/';
$image3->move($brochuresDir, $fileName3);
// Update the 'brochure' property to store the PDF file name
// instead of its contents
$this->setImageName3($fileName3);
$this->updatedAt = new \DateTime('now');
}
return $this;
}
/**
* @return File
*/
public function getImageFile3()
{
return $this->imageFile3;
}
/**
* @param string $imageName
*/
public function setImageName3($imageName)
{
$this->imageName3 = $imageName;
}
/**
* @return string
*/
public function getImageName3()
{
return $this->imageName3;
}
////
///
///
public function setImageFile2(File $image2 = null)
{
$this->imageFile2 = $image2;
if ($image2) {
$fileName2 = md5(uniqid()).'.'.$image2->guessExtension();
// Move the file to the directory where brochures are stored
$brochuresDir = getcwd().'/images/category/';
$image2->move($brochuresDir, $fileName2);
// Update the 'brochure' property to store the PDF file name
// instead of its contents
$this->setImageName2($fileName2);
$this->updatedAt = new \DateTime('now');
}
return $this;
}
/**
* @return File
*/
public function getImageFile2()
{
return $this->imageFile2;
}
/**
* @param string $imageName
*/
public function setImageName2($imageName)
{
$this->imageName2 = $imageName;
}
/**
* @return string
*/
public function getImageName2()
{
return $this->imageName2;
}
//////////////
/**
*
* note This is not a mapped field of entity metadata, just a simple property.
*
* @var File $imageFile
*/
protected $imageFile;
/**
* @ORM\Column(type="string", length=255, name="image_name", nullable=true)
* @var string $imageName
*/
protected $imageName;
public function setImageFile(File $image = null)
{
$this->imageFile = $image;
if ($image) {
$fileName = md5(uniqid()).'.'.$image->guessExtension();
// Move the file to the directory where brochures are stored
$brochuresDir = getcwd().'/images/category/';
$image->move($brochuresDir, $fileName);
// Update the 'brochure' property to store the PDF file name
// instead of its contents
$this->setImageName($fileName);
$this->updatedAt = new \DateTime('now');
}
return $this;
}
/**
* @return File
*/
public function getImageFile()
{
return $this->imageFile;
}
/**
* @param string $imageName
*/
public function setImageName($imageName)
{
$this->imageName = $imageName;
}
/**
* @return string
*/
public function getImageName()
{
return $this->imageName;
}
/**
* Constructor
*/
public function __construct()
{
$this->parents = new \Doctrine\Common\Collections\ArrayCollection();
$this->childrens = new \Doctrine\Common\Collections\ArrayCollection();
$this->children = new \Doctrine\Common\Collections\ArrayCollection();
$this->products = new ArrayCollection();
$this->langParams = new ArrayCollection();
$this->compareParameters = new ArrayCollection();
$this->parameters = new ArrayCollection();
}
/**
* Add child
*
* @param \App\Entity\Category $child
*
* @return Category
*/
public function addChild(\App\Entity\Category $child)
{
$this->children[] = $child;
return $this;
}
/**
* Remove child
*
* @param \App\Entity\Category $child
*/
public function removeChild(\App\Entity\Category $child)
{
$this->children->removeElement($child);
}
/**
* Get children
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getChildren()
{
return $this->children;
}
public function getChildrenIds() {
$ids = [];
foreach ($this->getChildren() as $child) {
$ids[] = $child->getId();
}
return $ids;
}
/**
* Add product
*
* @param \App\Entity\ProductCategory $product
*
* @return Category
*/
public function addProduct(\App\Entity\ProductCategory $product)
{
$this->products[] = $product;
return $this;
}
/**
* Remove product
*
* @param \App\Entity\ProductCategory $product
*/
public function removeProduct(\App\Entity\ProductCategory $product)
{
$this->products->removeElement($product);
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection|ProductCategory[]
*/
public function getProducts(): Collection
{
return $this->products;
}
/**
* @return Collection|CategoryLangParam[]
*/
public function getLangParams(): Collection
{
return $this->langParams;
}
public function addLangParam(LangParamRelationInterface $langParam): self
{
if (!$this->langParams->contains($langParam)) {
$this->langParams[] = $langParam;
$langParam->setCategory($this);
}
return $this;
}
public function removeLangParam(CategoryLangParam $langParam): self
{
if ($this->langParams->contains($langParam)) {
$this->langParams->removeElement($langParam);
// set the owning side to null (unless already changed)
if ($langParam->getCategory() === $this) {
$langParam->setCategory(null);
}
}
return $this;
}
/**
* @return Collection|CompareParameter[]
*/
public function getCompareParameters(): Collection
{
return $this->compareParameters;
}
public function addCompareParameter(CompareParameter $compareParameter): self
{
if (!$this->compareParameters->contains($compareParameter)) {
$this->compareParameters[] = $compareParameter;
$compareParameter->setCategory($this);
}
return $this;
}
public function removeCompareParameter(CompareParameter $compareParameter): self
{
if ($this->compareParameters->contains($compareParameter)) {
$this->compareParameters->removeElement($compareParameter);
// set the owning side to null (unless already changed)
if ($compareParameter->getCategory() === $this) {
$compareParameter->setCategory(null);
}
}
return $this;
}
/**
* @return Collection|ProductParameter[]
*/
public function getParameters(): Collection
{
return $this->parameters;
}
public function addParameter(ProductParameter $parameter): self
{
if (!$this->parameters->contains($parameter)) {
$this->parameters[] = $parameter;
}
return $this;
}
public function removeParameter(ProductParameter $parameter): self
{
if ($this->parameters->contains($parameter)) {
$this->parameters->removeElement($parameter);
}
return $this;
}
public function getFilterParameters(): ArrayCollection {
$arr = new ArrayCollection();
foreach ($this->getParameters() as $parameter) {
if ($parameter->getSimple() and $parameter->getFilter()) {
$arr->add($parameter);
}
}
return $arr;
}
/**
* @return string
*/
public function getAlt()
{
return $this->alt;
}
/**
* @param string $alt
*/
public function setAlt($alt)
{
$this->alt = $alt;
}
/**
* @return string
*/
public function getImageCustomName()
{
return $this->imageCustomName;
}
/**
* @param string $imageCustomName
*/
public function setImageCustomName($imageCustomName)
{
$this->imageCustomName = $imageCustomName;
}
/**
* Add children
*
* @param \App\Entity\Category $children
*
* @return Article
*/
public function addChildren(\App\Entity\Category $children)
{
$this->childrens[] = $children;
return $this;
}
/**
* Remove children
*
* @param \App\Entity\Category $children
*/
public function removeChildren(\App\Entity\Category $children)
{
$this->childrens->removeElement($children);
}
/**
* Get childrens
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getChildrens()
{
$col = new ArrayCollection();
foreach ($this->childrens as $children) {
if ($children->getDeletedBy() == null) {
$col->add($children);
}
}
return $col;
}
/**
* Add parent
*
* @param \App\Entity\Category $parent
*
* @return Article
*/
public function addParent(\App\Entity\Category $parent)
{
$this->parents[] = $parent;
return $this;
}
/**
* Remove parent
*
* @param \App\Entity\Category $parent
*/
public function removeParent(\App\Entity\Category $parent)
{
$this->parents->removeElement($parent);
}
/**
* Get parents
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getParents()
{
$col = new ArrayCollection();
foreach ($this->parents as $parent) {
if ($parent->getDeletedBy() == null) {
$col->add($parent);
}
}
return $col;
}
/**
* @return int
*/
public function getPosition()
{
return $this->position;
}
/**
* @param int $position
*/
public function setPosition($position)
{
$this->position = $position;
}
}