src/Entity/Category.php line 32

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 AppBundle\Entity\Article;
  14. use Doctrine\Common\Collections\ArrayCollection;
  15. use Doctrine\Common\Collections\Collection;
  16. use Doctrine\ORM\Mapping as ORM;
  17. use Symfony\Component\Validator\Constraints as Assert;
  18. use Symfony\Component\HttpFoundation\File\UploadedFile;
  19. use Symfony\Component\HttpFoundation\File\File;
  20. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  21. /**
  22.  * @ORM\Entity
  23.  * @ORM\Table(name="category")
  24.  */
  25. class Category implements TranslatableInterfaceLangParamInterface
  26. BlameableInterfaceTimestampableInterfaceSoftDeletableInterface {
  27.     use BlameableTrait;
  28.     use TimestampableTrait;
  29.     use TranslatableTrait;
  30.     use SoftDeletableTrait;
  31.     
  32. const TYPE_24h 209;
  33.     const TYPE_OUTLET 237;
  34.     const TYPE_SZOK_CENOWY 121;
  35.     const TYPE_NEW_PRODUCTS 316;
  36.     const TYPE_BESTSELLERS 315;
  37.     
  38.     
  39.     
  40.     /**
  41.      * @ORM\Id
  42.      * @ORM\Column(type="integer")
  43.      * @ORM\GeneratedValue(strategy="AUTO")
  44.      */
  45.     protected $id;
  46.     /**
  47.      * Obsługa tłumaczeń
  48.      * @param $method
  49.      * @param $arguments
  50.      * @return mixed
  51.      */
  52.     public function __call($method$arguments)
  53.     {
  54.         return $this->proxyCurrentLocaleTranslation($method$arguments);
  55.     }
  56.     public function getName()
  57.     {
  58.         return $this->translate()->getName();
  59.     }
  60.     public function getDescription()
  61.     {
  62.         return $this->translate()->getDescription();
  63.     }
  64.     public function getMetaDescription()
  65.     {
  66.         return $this->translate()->getMetaDescription();
  67.     }
  68.     public function getMetaTitle()
  69.     {
  70.         return $this->translate()->getMetaTitle();
  71.     }
  72.     public function getCanonical()
  73.     {
  74.         return $this->translate()->getCanonical();
  75.     }
  76.     public function getMetaKeywords()
  77.     {
  78.         return $this->translate()->getMetaKeywords();
  79.     }
  80.     public function getSlug()
  81.     {
  82.         if ($this->translate()->getSlug()) {
  83.             return $this->translate()->getSlug();
  84.         } else {
  85.             return '-';
  86.         }
  87.     }
  88.     public function getShortDescription()
  89.     {
  90.         return $this->translate()->getShortDescription();
  91.     }
  92.     public function getGoogleProductCategory()
  93.     {
  94.         return $this->translate()->getGoogleProductCategory();
  95.     }
  96.     public function getGoogleProductType()
  97.     {
  98.         return $this->translate()->getGoogleProductType();
  99.     }
  100.     public function getSpecialProductCategory()
  101.     {
  102.         return $this->translate()->getSpecialProductCategory();
  103.     }
  104.     /**
  105.      * @var string
  106.      *
  107.      * @ORM\Column(name="level", type="string", length=255, nullable=true)
  108.      */
  109.     private $level;
  110.     /**
  111.      * @var integer
  112.      *
  113.      * @ORM\Column(name="position", type="integer", length=8, nullable=true)
  114.      */
  115.     private $position;
  116.     /**
  117.      * @ORM\ManyToOne(targetEntity="App\Entity\Category", cascade={"all"}, inversedBy="children")
  118.      * @ORM\JoinColumn(name="category_parent_id", referencedColumnName="id", onDelete="CASCADE")
  119.      */
  120.     protected $parent;
  121.     /**
  122.      * @ORM\OneToMany(targetEntity="App\Entity\Category", mappedBy="parent", cascade={"persist"})
  123.      * @Doctrine\ORM\Mapping\OrderBy({"position" = "ASC"})
  124.      */
  125.     protected $children;
  126.     /**
  127.      * @Doctrine\ORM\Mapping\ManyToMany(targetEntity="App\Entity\Category", mappedBy="parents")
  128.      * @Doctrine\ORM\Mapping\OrderBy({"position" = "ASC"})
  129.      **/
  130.     protected $childrens;
  131.     /**
  132.      * @Doctrine\ORM\Mapping\ManyToMany(targetEntity="App\Entity\Category", inversedBy="childrens")
  133.      * @Doctrine\ORM\Mapping\JoinTable(name="category_parent_relation",
  134.      *      joinColumns={@Doctrine\ORM\Mapping\JoinColumn(name="category_id", referencedColumnName="id")},
  135.      *      inverseJoinColumns={@Doctrine\ORM\Mapping\JoinColumn(name="parent_id", referencedColumnName="id")}
  136.      *      )
  137.      **/
  138.     protected $parents;
  139.     /**
  140.      * @ORM\OneToMany(targetEntity="App\Entity\ProductCategory", mappedBy="category", cascade={"persist"})
  141.      * @Doctrine\ORM\Mapping\OrderBy({"position" = "ASC"})
  142.      */
  143.     protected $products;
  144.     /**
  145.      * @ORM\OneToMany(targetEntity="App\Entity\CompareParameter", mappedBy="category", cascade={"persist"})
  146.      */
  147.     protected $compareParameters;
  148.     /**
  149.      * @ORM\OneToMany(targetEntity="App\Entity\CategoryLangParam", mappedBy="category", cascade={"all"})
  150.      */
  151.     protected $langParams;
  152.     /**
  153.      * @Doctrine\ORM\Mapping\ManyToMany(targetEntity="App\Entity\ProductParameter")
  154.      * @Doctrine\ORM\Mapping\JoinTable(name="category_parameter_relations")
  155.      */
  156.     private $parameters;
  157.     /**
  158.      * @var string
  159.      *
  160.      * @ORM\Column(name="alt", type="string", length=255, nullable=true)
  161.      */
  162.     private $alt;
  163.     /**
  164.      * @var string
  165.      *
  166.      * @ORM\Column(name="image_custom_name", type="string", length=255, nullable=true)
  167.      */
  168.     private $imageCustomName;
  169.     /**
  170.      * Get id
  171.      *
  172.      * @return integer
  173.      */
  174.     public function getId()
  175.     {
  176.         return $this->id;
  177.     }
  178.     /**
  179.      * Set level
  180.      *
  181.      * @param string $level
  182.      *
  183.      * @return Category
  184.      */
  185.     public function setLevel($level)
  186.     {
  187.         $this->level $level;
  188.         return $this;
  189.     }
  190.     /**
  191.      * Get level
  192.      *
  193.      * @return string
  194.      */
  195.     public function getLevel()
  196.     {
  197.         return $this->level;
  198.     }
  199.     /**
  200.      *
  201.      * note This is not a mapped field of entity metadata, just a simple property.
  202.      *
  203.      * @var File $imageFile
  204.      */
  205.     protected $imageFile2;
  206.     /**
  207.      * @ORM\Column(type="string", length=255, name="image_name_2", nullable=true)
  208.      * @var string $imageName2
  209.      */
  210.     protected $imageName2;
  211.     /////
  212.     ///
  213.     ///
  214.     /**
  215.      *
  216.      * note This is not a mapped field of entity metadata, just a simple property.
  217.      *
  218.      * @var File $imageFile3
  219.      */
  220.     protected $imageFile3;
  221.     /**
  222.      * Mobile zdjęcie kategorii
  223.      * @ORM\Column(type="string", length=255, name="image_name_3", nullable=true)
  224.      * @var string $imageName3
  225.      */
  226.     protected $imageName3;
  227.     public function setImageFile3(File $image3 null)
  228.     {
  229.         $this->imageFile3 $image3;
  230.         if ($image3) {
  231.             $fileName3 md5(uniqid()).'.'.$image3->guessExtension();
  232.             // Move the file to the directory where brochures are stored
  233.             $brochuresDir getcwd().'/images/category/';
  234.             $image3->move($brochuresDir$fileName3);
  235.             // Update the 'brochure' property to store the PDF file name
  236.             // instead of its contents
  237.             $this->setImageName3($fileName3);
  238.             $this->updatedAt = new \DateTime('now');
  239.         }
  240.         return $this;
  241.     }
  242.     /**
  243.      * @return File
  244.      */
  245.     public function getImageFile3()
  246.     {
  247.         return $this->imageFile3;
  248.     }
  249.     /**
  250.      * @param string $imageName
  251.      */
  252.     public function setImageName3($imageName)
  253.     {
  254.         $this->imageName3 $imageName;
  255.     }
  256.     /**
  257.      * @return string
  258.      */
  259.     public function getImageName3()
  260.     {
  261.         return $this->imageName3;
  262.     }
  263.     ////
  264.     ///
  265.     ///
  266.     public function setImageFile2(File $image2 null)
  267.     {
  268.         $this->imageFile2 $image2;
  269.         if ($image2) {
  270.             $fileName2 md5(uniqid()).'.'.$image2->guessExtension();
  271.             // Move the file to the directory where brochures are stored
  272.             $brochuresDir getcwd().'/images/category/';
  273.             $image2->move($brochuresDir$fileName2);
  274.             // Update the 'brochure' property to store the PDF file name
  275.             // instead of its contents
  276.             $this->setImageName2($fileName2);
  277.             $this->updatedAt = new \DateTime('now');
  278.         }
  279.         return $this;
  280.     }
  281.     /**
  282.      * @return File
  283.      */
  284.     public function getImageFile2()
  285.     {
  286.         return $this->imageFile2;
  287.     }
  288.     /**
  289.      * @param string $imageName
  290.      */
  291.     public function setImageName2($imageName)
  292.     {
  293.         $this->imageName2 $imageName;
  294.     }
  295.     /**
  296.      * @return string
  297.      */
  298.     public function getImageName2()
  299.     {
  300.         return $this->imageName2;
  301.     }
  302.     //////////////
  303.     /**
  304.      *
  305.      * note This is not a mapped field of entity metadata, just a simple property.
  306.      *
  307.      * @var File $imageFile
  308.      */
  309.     protected $imageFile;
  310.     /**
  311.      * @ORM\Column(type="string", length=255, name="image_name", nullable=true)
  312.      * @var string $imageName
  313.      */
  314.     protected $imageName;
  315.     public function setImageFile(File $image null)
  316.     {
  317.         $this->imageFile $image;
  318.         if ($image) {
  319.             $fileName md5(uniqid()).'.'.$image->guessExtension();
  320.             // Move the file to the directory where brochures are stored
  321.             $brochuresDir getcwd().'/images/category/';
  322.             $image->move($brochuresDir$fileName);
  323.             // Update the 'brochure' property to store the PDF file name
  324.             // instead of its contents
  325.             $this->setImageName($fileName);
  326.             $this->updatedAt = new \DateTime('now');
  327.         }
  328.         return $this;
  329.     }
  330.     /**
  331.      * @return File
  332.      */
  333.     public function getImageFile()
  334.     {
  335.         return $this->imageFile;
  336.     }
  337.     /**
  338.      * @param string $imageName
  339.      */
  340.     public function setImageName($imageName)
  341.     {
  342.         $this->imageName $imageName;
  343.     }
  344.     /**
  345.      * @return string
  346.      */
  347.     public function getImageName()
  348.     {
  349.         return $this->imageName;
  350.     }
  351.     /**
  352.      * Constructor
  353.      */
  354.     public function __construct()
  355.     {
  356.         $this->parents = new \Doctrine\Common\Collections\ArrayCollection();
  357.         $this->childrens = new \Doctrine\Common\Collections\ArrayCollection();
  358.         $this->children = new \Doctrine\Common\Collections\ArrayCollection();
  359.         $this->products = new ArrayCollection();
  360.         $this->langParams = new ArrayCollection();
  361.         $this->compareParameters = new ArrayCollection();
  362.         $this->parameters = new ArrayCollection();
  363.     }
  364.     /**
  365.      * Add child
  366.      *
  367.      * @param \App\Entity\Category $child
  368.      *
  369.      * @return Category
  370.      */
  371.     public function addChild(\App\Entity\Category $child)
  372.     {
  373.         $this->children[] = $child;
  374.         return $this;
  375.     }
  376.     /**
  377.      * Remove child
  378.      *
  379.      * @param \App\Entity\Category $child
  380.      */
  381.     public function removeChild(\App\Entity\Category $child)
  382.     {
  383.         $this->children->removeElement($child);
  384.     }
  385.     /**
  386.      * Get children
  387.      *
  388.      * @return \Doctrine\Common\Collections\Collection
  389.      */
  390.     public function getChildren()
  391.     {
  392.         return $this->children;
  393.     }
  394.     public function getChildrenIds() {
  395.         $ids = [];
  396.         foreach ($this->getChildren() as $child) {
  397.             $ids[] = $child->getId();
  398.         }
  399.         return $ids;
  400.     }
  401.     /**
  402.      * Add product
  403.      *
  404.      * @param \App\Entity\ProductCategory $product
  405.      *
  406.      * @return Category
  407.      */
  408.     public function addProduct(\App\Entity\ProductCategory $product)
  409.     {
  410.         $this->products[] = $product;
  411.         return $this;
  412.     }
  413.     /**
  414.      * Remove product
  415.      *
  416.      * @param \App\Entity\ProductCategory $product
  417.      */
  418.     public function removeProduct(\App\Entity\ProductCategory $product)
  419.     {
  420.         $this->products->removeElement($product);
  421.     }
  422.     public function getParent(): ?self
  423.     {
  424.         return $this->parent;
  425.     }
  426.     public function setParent(?self $parent): self
  427.     {
  428.         $this->parent $parent;
  429.         return $this;
  430.     }
  431.     /**
  432.      * @return Collection|ProductCategory[]
  433.      */
  434.     public function getProducts(): Collection
  435.     {
  436.         return $this->products;
  437.     }
  438.     /**
  439.      * @return Collection|CategoryLangParam[]
  440.      */
  441.     public function getLangParams(): Collection
  442.     {
  443.         return $this->langParams;
  444.     }
  445.     public function addLangParam(LangParamRelationInterface $langParam): self
  446.     {
  447.         if (!$this->langParams->contains($langParam)) {
  448.             $this->langParams[] = $langParam;
  449.             $langParam->setCategory($this);
  450.         }
  451.         return $this;
  452.     }
  453.     public function removeLangParam(CategoryLangParam $langParam): self
  454.     {
  455.         if ($this->langParams->contains($langParam)) {
  456.             $this->langParams->removeElement($langParam);
  457.             // set the owning side to null (unless already changed)
  458.             if ($langParam->getCategory() === $this) {
  459.                 $langParam->setCategory(null);
  460.             }
  461.         }
  462.         return $this;
  463.     }
  464.     /**
  465.      * @return Collection|CompareParameter[]
  466.      */
  467.     public function getCompareParameters(): Collection
  468.     {
  469.         return $this->compareParameters;
  470.     }
  471.     public function addCompareParameter(CompareParameter $compareParameter): self
  472.     {
  473.         if (!$this->compareParameters->contains($compareParameter)) {
  474.             $this->compareParameters[] = $compareParameter;
  475.             $compareParameter->setCategory($this);
  476.         }
  477.         return $this;
  478.     }
  479.     public function removeCompareParameter(CompareParameter $compareParameter): self
  480.     {
  481.         if ($this->compareParameters->contains($compareParameter)) {
  482.             $this->compareParameters->removeElement($compareParameter);
  483.             // set the owning side to null (unless already changed)
  484.             if ($compareParameter->getCategory() === $this) {
  485.                 $compareParameter->setCategory(null);
  486.             }
  487.         }
  488.         return $this;
  489.     }
  490.     /**
  491.      * @return Collection|ProductParameter[]
  492.      */
  493.     public function getParameters(): Collection
  494.     {
  495.         return $this->parameters;
  496.     }
  497.     public function addParameter(ProductParameter $parameter): self
  498.     {
  499.         if (!$this->parameters->contains($parameter)) {
  500.             $this->parameters[] = $parameter;
  501.         }
  502.         return $this;
  503.     }
  504.     public function removeParameter(ProductParameter $parameter): self
  505.     {
  506.         if ($this->parameters->contains($parameter)) {
  507.             $this->parameters->removeElement($parameter);
  508.         }
  509.         return $this;
  510.     }
  511.     public function getFilterParameters(): ArrayCollection {
  512.         $arr = new ArrayCollection();
  513.         foreach ($this->getParameters() as $parameter) {
  514.             if ($parameter->getSimple() and $parameter->getFilter()) {
  515.                 $arr->add($parameter);
  516.             }
  517.         }
  518.         return $arr;
  519.     }
  520.     /**
  521.      * @return string
  522.      */
  523.     public function getAlt()
  524.     {
  525.         return $this->alt;
  526.     }
  527.     /**
  528.      * @param string $alt
  529.      */
  530.     public function setAlt($alt)
  531.     {
  532.         $this->alt $alt;
  533.     }
  534.     /**
  535.      * @return string
  536.      */
  537.     public function getImageCustomName()
  538.     {
  539.         return $this->imageCustomName;
  540.     }
  541.     /**
  542.      * @param string $imageCustomName
  543.      */
  544.     public function setImageCustomName($imageCustomName)
  545.     {
  546.         $this->imageCustomName $imageCustomName;
  547.     }
  548.     /**
  549.      * Add children
  550.      *
  551.      * @param \App\Entity\Category $children
  552.      *
  553.      * @return Article
  554.      */
  555.     public function addChildren(\App\Entity\Category $children)
  556.     {
  557.         $this->childrens[] = $children;
  558.         return $this;
  559.     }
  560.     /**
  561.      * Remove children
  562.      *
  563.      * @param \App\Entity\Category $children
  564.      */
  565.     public function removeChildren(\App\Entity\Category $children)
  566.     {
  567.         $this->childrens->removeElement($children);
  568.     }
  569.     /**
  570.      * Get childrens
  571.      *
  572.      * @return \Doctrine\Common\Collections\Collection
  573.      */
  574.     public function getChildrens()
  575.     {
  576.         $col = new ArrayCollection();
  577.         foreach ($this->childrens as $children) {
  578.             if ($children->getDeletedBy() == null) {
  579.                 $col->add($children);
  580.             }
  581.         }
  582.         return $col;
  583.     }
  584.     /**
  585.      * Add parent
  586.      *
  587.      * @param \App\Entity\Category $parent
  588.      *
  589.      * @return Article
  590.      */
  591.     public function addParent(\App\Entity\Category $parent)
  592.     {
  593.         $this->parents[] = $parent;
  594.         return $this;
  595.     }
  596.     /**
  597.      * Remove parent
  598.      *
  599.      * @param \App\Entity\Category $parent
  600.      */
  601.     public function removeParent(\App\Entity\Category $parent)
  602.     {
  603.         $this->parents->removeElement($parent);
  604.     }
  605.     /**
  606.      * Get parents
  607.      *
  608.      * @return \Doctrine\Common\Collections\Collection
  609.      */
  610.     public function getParents()
  611.     {
  612.         $col = new ArrayCollection();
  613.         foreach ($this->parents as $parent) {
  614.             if ($parent->getDeletedBy() == null) {
  615.                 $col->add($parent);
  616.             }
  617.         }
  618.         return $col;
  619.     }
  620.     /**
  621.      * @return int
  622.      */
  623.     public function getPosition()
  624.     {
  625.         return $this->position;
  626.     }
  627.     /**
  628.      * @param int $position
  629.      */
  630.     public function setPosition($position)
  631.     {
  632.         $this->position $position;
  633.     }
  634. }