<?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 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="furniture_type")
*/
class FurnitureType implements TranslatableInterface, LangParamInterface
, BlameableInterface, TimestampableInterface, SoftDeletableInterface {
use BlameableTrait;
use TimestampableTrait;
use TranslatableTrait;
use SoftDeletableTrait;
/**
* @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();
}
/**
* @ORM\OneToMany(targetEntity="App\Entity\FurnitureTypeLangParam", mappedBy="furnitureType", cascade={"all"})
*/
protected $langParams;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductFurnitureType", mappedBy="furnitureType", cascade={"all"})
*/
protected $products;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Product", inversedBy="furnitureType", cascade={"all"})
* @ORM\JoinColumn(name="vat_id", referencedColumnName="id", onDelete="CASCADE")
*/
protected $furnitureType;
/**
*
* 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->langParams = new ArrayCollection();
$this->products = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getFurnitureType(): ?Product
{
return $this->furnitureType;
}
public function setFurnitureType(?Product $furnitureType): self
{
$this->furnitureType = $furnitureType;
return $this;
}
/**
* @return Collection|FurnitureTypeLangParam[]
*/
public function getLangParams(): Collection
{
return $this->langParams;
}
public function addLangParam(LangParamRelationInterface $langParam): self
{
if (!$this->langParams->contains($langParam)) {
$this->langParams[] = $langParam;
$langParam->setFurnitureType($this);
}
return $this;
}
public function removeLangParam(LangParamRelationInterface $langParam): self
{
if ($this->langParams->contains($langParam)) {
$this->langParams->removeElement($langParam);
// set the owning side to null (unless already changed)
if ($langParam->getFurnitureType() === $this) {
$langParam->setFurnitureType(null);
}
}
return $this;
}
/**
* @return Collection|ProductFurnitureType[]
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(ProductFurnitureType $product): self
{
if (!$this->products->contains($product)) {
$this->products[] = $product;
$product->setFurnitureType($this);
}
return $this;
}
public function removeProduct(ProductFurnitureType $product): self
{
if ($this->products->contains($product)) {
$this->products->removeElement($product);
// set the owning side to null (unless already changed)
if ($product->getFurnitureType() === $this) {
$product->setFurnitureType(null);
}
}
return $this;
}
}