src/Entity/FurnitureType.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Knp\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface;
  4. use Knp\DoctrineBehaviors\Model\SoftDeletable\SoftDeletableTrait;
  5. use Knp\DoctrineBehaviors\Model\Blameable\BlameableTrait;
  6. use Knp\DoctrineBehaviors\Contract\Entity\BlameableInterface;
  7. use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
  8. use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
  9. use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
  10. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  11. use App\Model\LangParamInterface;
  12. use App\Model\LangParamRelationInterface;
  13. use Doctrine\Common\Collections\ArrayCollection;
  14. use Doctrine\Common\Collections\Collection;
  15. use Doctrine\ORM\Mapping as ORM;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. use Symfony\Component\HttpFoundation\File\UploadedFile;
  18. use Symfony\Component\HttpFoundation\File\File;
  19. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  20. /**
  21.  * @ORM\Entity
  22.  * @ORM\Table(name="furniture_type")
  23.  */
  24. class FurnitureType implements TranslatableInterfaceLangParamInterface
  25. BlameableInterfaceTimestampableInterfaceSoftDeletableInterface {
  26.     use BlameableTrait;
  27.     use TimestampableTrait;
  28.     use TranslatableTrait;
  29.     use SoftDeletableTrait;
  30.     
  31.     
  32.     
  33.     /**
  34.      * @ORM\Id
  35.      * @ORM\Column(type="integer")
  36.      * @ORM\GeneratedValue(strategy="AUTO")
  37.      */
  38.     protected $id;
  39.     /**
  40.      * Obsługa tłumaczeń
  41.      * @param $method
  42.      * @param $arguments
  43.      * @return mixed
  44.      */
  45.     public function __call($method$arguments)
  46.     {
  47.         return $this->proxyCurrentLocaleTranslation($method$arguments);
  48.     }
  49.     public function getName()
  50.     {
  51.         return $this->translate()->getName();
  52.     }
  53.     public function getDescription()
  54.     {
  55.         return $this->translate()->getDescription();
  56.     }
  57.     public function getMetaDescription()
  58.     {
  59.         return $this->translate()->getMetaDescription();
  60.     }
  61.     public function getMetaTitle()
  62.     {
  63.         return $this->translate()->getMetaTitle();
  64.     }
  65.     public function getCanonical()
  66.     {
  67.         return $this->translate()->getCanonical();
  68.     }
  69.     public function getMetaKeywords()
  70.     {
  71.         return $this->translate()->getMetaKeywords();
  72.     }
  73.     public function getSlug()
  74.     {
  75.         if ($this->translate()->getSlug()) {
  76.             return $this->translate()->getSlug();
  77.         } else {
  78.             return '-';
  79.         }
  80.     }
  81.     public function getShortDescription()
  82.     {
  83.         return $this->translate()->getShortDescription();
  84.     }
  85.     /**
  86.      * @ORM\OneToMany(targetEntity="App\Entity\FurnitureTypeLangParam", mappedBy="furnitureType", cascade={"all"})
  87.      */
  88.     protected $langParams;
  89.     /**
  90.      * @ORM\OneToMany(targetEntity="App\Entity\ProductFurnitureType", mappedBy="furnitureType", cascade={"all"})
  91.      */
  92.     protected $products;
  93.     /**
  94.      * @ORM\ManyToOne(targetEntity="App\Entity\Product", inversedBy="furnitureType", cascade={"all"})
  95.      * @ORM\JoinColumn(name="vat_id", referencedColumnName="id", onDelete="CASCADE")
  96.      */
  97.     protected $furnitureType;
  98.     /**
  99.      *
  100.      * note This is not a mapped field of entity metadata, just a simple property.
  101.      *
  102.      * @var File $imageFile
  103.      */
  104.     protected $imageFile;
  105.     /**
  106.      * @ORM\Column(type="string", length=255, name="image_name", nullable=true)
  107.      * @var string $imageName
  108.      */
  109.     protected $imageName;
  110.     public function setImageFile(File $image null)
  111.     {
  112.         $this->imageFile $image;
  113.         if ($image) {
  114.             $fileName md5(uniqid()).'.'.$image->guessExtension();
  115.             // Move the file to the directory where brochures are stored
  116.             $brochuresDir getcwd().'/images/category/';
  117.             $image->move($brochuresDir$fileName);
  118.             // Update the 'brochure' property to store the PDF file name
  119.             // instead of its contents
  120.             $this->setImageName($fileName);
  121.             $this->updatedAt = new \DateTime('now');
  122.         }
  123.         return $this;
  124.     }
  125.     /**
  126.      * @return File
  127.      */
  128.     public function getImageFile()
  129.     {
  130.         return $this->imageFile;
  131.     }
  132.     /**
  133.      * @param string $imageName
  134.      */
  135.     public function setImageName($imageName)
  136.     {
  137.         $this->imageName $imageName;
  138.     }
  139.     /**
  140.      * @return string
  141.      */
  142.     public function getImageName()
  143.     {
  144.         return $this->imageName;
  145.     }
  146.     /**
  147.      * Constructor
  148.      */
  149.     public function __construct()
  150.     {
  151.         $this->langParams = new ArrayCollection();
  152.         $this->products = new ArrayCollection();
  153.     }
  154.     public function getId(): ?int
  155.     {
  156.         return $this->id;
  157.     }
  158.     public function getFurnitureType(): ?Product
  159.     {
  160.         return $this->furnitureType;
  161.     }
  162.     public function setFurnitureType(?Product $furnitureType): self
  163.     {
  164.         $this->furnitureType $furnitureType;
  165.         return $this;
  166.     }
  167.     /**
  168.      * @return Collection|FurnitureTypeLangParam[]
  169.      */
  170.     public function getLangParams(): Collection
  171.     {
  172.         return $this->langParams;
  173.     }
  174.     public function addLangParam(LangParamRelationInterface $langParam): self
  175.     {
  176.         if (!$this->langParams->contains($langParam)) {
  177.             $this->langParams[] = $langParam;
  178.             $langParam->setFurnitureType($this);
  179.         }
  180.         return $this;
  181.     }
  182.     public function removeLangParam(LangParamRelationInterface $langParam): self
  183.     {
  184.         if ($this->langParams->contains($langParam)) {
  185.             $this->langParams->removeElement($langParam);
  186.             // set the owning side to null (unless already changed)
  187.             if ($langParam->getFurnitureType() === $this) {
  188.                 $langParam->setFurnitureType(null);
  189.             }
  190.         }
  191.         return $this;
  192.     }
  193.     /**
  194.      * @return Collection|ProductFurnitureType[]
  195.      */
  196.     public function getProducts(): Collection
  197.     {
  198.         return $this->products;
  199.     }
  200.     public function addProduct(ProductFurnitureType $product): self
  201.     {
  202.         if (!$this->products->contains($product)) {
  203.             $this->products[] = $product;
  204.             $product->setFurnitureType($this);
  205.         }
  206.         return $this;
  207.     }
  208.     public function removeProduct(ProductFurnitureType $product): self
  209.     {
  210.         if ($this->products->contains($product)) {
  211.             $this->products->removeElement($product);
  212.             // set the owning side to null (unless already changed)
  213.             if ($product->getFurnitureType() === $this) {
  214.                 $product->setFurnitureType(null);
  215.             }
  216.         }
  217.         return $this;
  218.     }
  219. }