src/Entity/Category.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Serializer\Annotation\Groups;
  7. /**
  8.  * @ORM\Entity(repositoryClass="App\Repository\CategoryRepository")
  9.  */
  10. class Category
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue(strategy="AUTO")
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=100)
  20.      * @Groups({"searchable"})
  21.      */
  22.     private $name;
  23.     /**
  24.      * @ORM\Column(type="integer", options={"default" : 1})
  25.      */
  26.     private $placement=1;
  27.     /**
  28.      * @ORM\ManyToOne(targetEntity="App\Entity\Category", inversedBy="categories")
  29.      */
  30.     private $subCategory;
  31.     /**
  32.      * @ORM\OneToMany(targetEntity="App\Entity\Category", mappedBy="subCategory")
  33.      * @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
  34.      */
  35.     private $categories;
  36.     /**
  37.      * @ORM\ManyToOne(targetEntity="App\Entity\Image")
  38.      */
  39.     private $image;
  40.     /**
  41.      * @ORM\ManyToOne(targetEntity="App\Entity\Image")
  42.      */
  43.     private $banner;
  44.     /**
  45.      * @ORM\Column(type="string", length=255, nullable=true)
  46.      */
  47.     private $title;
  48.     /**
  49.      * @ORM\Column(type="text", nullable=true)
  50.      */
  51.     private $description;
  52.     /**
  53.      * @ORM\Column(type="string", nullable=true)
  54.      */
  55.     private $tier1MaturinFeesPc;
  56.     /**
  57.      * @ORM\Column(type="string", nullable=true)
  58.      */
  59.     private $tier2MaturinFeesPc;
  60.     /**
  61.      * @ORM\Column(type="string", nullable=true)
  62.      */
  63.     private $tier2MaturinFeesMinprice;
  64.     /**
  65.      * @ORM\Column(type="string", nullable=true)
  66.      */
  67.     private $tier2MaturinFeesMaxprice;
  68.     /**
  69.      * @ORM\Column(type="string", nullable=true)
  70.      */
  71.     private $packingFeesAmount;
  72.     /**
  73.      * @ORM\Column(type="string", nullable=true)
  74.      */
  75.     private $packingSuppliesFeesAmount;
  76.     /**
  77.      * @ORM\Column(type="string", length=200, nullable=true)
  78.      */
  79.     private $metaDescription;
  80.     /**
  81.      * @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="categories")
  82.      * @ORM\OrderBy({"qtyReadyToShip" = "DESC"})
  83.      */
  84.     private $products;
  85.     /**
  86.      * @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="subCategory")
  87.      * @ORM\OrderBy({"qtyReadyToShip" = "DESC"})
  88.      */
  89.     private $productsSub;
  90.     /**
  91.      * @ORM\Column(type="boolean")
  92.      */
  93.     private $isDisplayedForBuyer=false;
  94.     public function __construct()
  95.     {
  96.         $this->categories = new ArrayCollection();
  97.         $this->products = new ArrayCollection();
  98.         $this->productsSub= new ArrayCollection();
  99.     }
  100.     public function __toString(){
  101.         if(!empty($this->name))
  102.             return $this->name;
  103.         else
  104.             return '';
  105.     }
  106.     /*************************
  107.      * All the properties set
  108.      *************************/
  109.     public function getId(){
  110.         return $this->id;
  111.     }
  112.     public function setName($name){
  113.         $this->name $name;
  114.     }
  115.     public function getName(){
  116.         return $this->name;
  117.     }
  118.     public function getFullUrlPath(){
  119.         $tree = array();
  120.         $tree[] = $this->getUrlName();
  121.         $c $this->getSubCategory();
  122.         while(!empty($c)){
  123.             $tree[] = $c->getUrlName();
  124.             $c $c->getSubCategory();
  125.         }
  126.         $url '/'.implode('/'array_reverse($tree));
  127.         return $url;
  128.     }
  129.     public function getUrlName(){
  130.         $unwanted_array = array(    'Š'=>'S''š'=>'s''Ž'=>'Z''ž'=>'z''À'=>'A''Á'=>'A''Â'=>'A''Ã'=>'A''Ä'=>'A''Å'=>'A''Æ'=>'A''Ç'=>'C''È'=>'E''É'=>'E',
  131.             'Ê'=>'E''Ë'=>'E''Ì'=>'I''Í'=>'I''Î'=>'I''Ï'=>'I''Ñ'=>'N''Ò'=>'O''Ó'=>'O''Ô'=>'O''Õ'=>'O''Ö'=>'O''Ø'=>'O''Ù'=>'U',
  132.             'Ú'=>'U''Û'=>'U''Ü'=>'U''Ý'=>'Y''Þ'=>'B''ß'=>'Ss''à'=>'a''á'=>'a''â'=>'a''ã'=>'a''ä'=>'a''å'=>'a''æ'=>'a''ç'=>'c',
  133.             'è'=>'e''é'=>'e''ê'=>'e''ë'=>'e''ì'=>'i''í'=>'i''î'=>'i''ï'=>'i''ð'=>'o''ñ'=>'n''ò'=>'o''ó'=>'o''ô'=>'o''õ'=>'o',
  134.             'ö'=>'o''ø'=>'o''ù'=>'u''ú'=>'u''û'=>'u''ý'=>'y''þ'=>'b''ÿ'=>'y'","=>"",  "'" => "" );
  135.         $str strtr$this->name$unwanted_array );
  136.         return urlencode(str_replace(' ''-'strtolower($str)));
  137.     }
  138.     public function setPlacement($placement){
  139.         $this->placement $placement;
  140.     }
  141.     public function getPlacement(){
  142.         return $this->placement;
  143.     }
  144.     /*
  145.      * This is mostly from the Select of the forms
  146.      */
  147.     public function setSubFromObj($master){
  148.         if(!empty($master))
  149.             $this->sub $master->getId();
  150.         else
  151.             $this->sub 0;
  152.     }
  153.     public function hasSubFromObj(){
  154.         return false;
  155.     }
  156.     public function getSubCategory(): ?Category
  157.     {
  158.         return $this->subCategory;
  159.     }
  160.     public function setSubCategory(?self $subCategory): self
  161.     {
  162.         $this->subCategory $subCategory;
  163.         return $this;
  164.     }
  165.     public function getAllSubCategories()
  166.     {
  167.         //Start with those here
  168.         $categories $this->recursiveCategories($this->getCategories(), array());
  169.         return $categories;
  170.     }
  171.     public function recursiveCategories($categories$results = array()){
  172.         foreach($categories as $c){
  173.             $results[]=$c;
  174.             if(!empty($c->getCategories()) && count($c->getCategories()) > 0){
  175.                 $categories $this->recursiveCategories($c->getCategories(), $results);
  176.             }
  177.         }
  178.         return $results;
  179.     }
  180.     /**
  181.      * @return Collection|self[]
  182.      */
  183.     public function getCategories(): Collection
  184.     {
  185.         return $this->categories;
  186.     }
  187.     public function addCategory(self $category): self
  188.     {
  189.         if (!$this->categories->contains($category)) {
  190.             $this->categories[] = $category;
  191.             $category->setSubCategory($this);
  192.         }
  193.         return $this;
  194.     }
  195.     public function removeCategory(self $category): self
  196.     {
  197.         if ($this->categories->contains($category)) {
  198.             $this->categories->removeElement($category);
  199.             // set the owning side to null (unless already changed)
  200.             if ($category->getSubCategory() === $this) {
  201.                 $category->setSubCategory(null);
  202.             }
  203.         }
  204.         return $this;
  205.     }
  206.     public function getImage(): ?Image
  207.     {
  208.         return $this->image;
  209.     }
  210.     public function setImage(?Image $image): self
  211.     {
  212.         //Fix a bug in the form when not selecting a image for now
  213.         //This need to be fixed elsewhere
  214.         //@TODO
  215.         if(!empty($image))
  216.             $this->image $image;
  217.         return $this;
  218.     }
  219.     public function getBanner(): ?Image
  220.     {
  221.         return $this->banner;
  222.     }
  223.     public function setBanner(?Image $banner): self
  224.     {
  225.         //Fix a bug in the form when not selecting a image for now
  226.         //This need to be fixed elsewhere
  227.         //@TODO
  228.         if(!empty($banner))
  229.             $this->banner $banner;
  230.         return $this;
  231.     }
  232.     public function getTitle(): ?string
  233.     {
  234.         return $this->title;
  235.     }
  236.     public function setTitle(?string $title): self
  237.     {
  238.         $this->title $title;
  239.         return $this;
  240.     }
  241.     public function getDescription(): ?string
  242.     {
  243.         return $this->description;
  244.     }
  245.     public function setDescription(?string $description): self
  246.     {
  247.         $this->description $description;
  248.         return $this;
  249.     }
  250.     public function getMetaDescription(): ?string
  251.     {
  252.         return $this->metaDescription;
  253.     }
  254.     public function setMetaDescription(?string $metaDescription): self
  255.     {
  256.         $this->metaDescription $metaDescription;
  257.         return $this;
  258.     }
  259.     public function getProductsSub(): Collection
  260.     {
  261.         return $this->productsSub;
  262.     }
  263.     public function addProductsSub(Product $product): self
  264.     {
  265.         if (!$this->productsSub->contains($product)) {
  266.             $this->productsSub[] = $product;
  267.             $product->setCategory($this);
  268.         }
  269.         return $this;
  270.     }
  271.     public function removeProductsSub(Product $product): self
  272.     {
  273.         if ($this->productsSub->contains($product)) {
  274.             $this->productsSub->removeElement($product);
  275.             // set the owning side to null (unless already changed)
  276.             if ($product->getCategory() === $this) {
  277.                 $product->setCategory(null);
  278.             }
  279.         }
  280.         return $this;
  281.     }
  282.     /**
  283.      * @return Collection|Badge[]
  284.      */
  285.     public function getProducts(): Collection
  286.     {
  287.         return $this->products;
  288.     }
  289.     public function addProduct(Product $product): self
  290.     {
  291.         if (!$this->products->contains($product)) {
  292.             $this->products[] = $product;
  293.             $product->setCategory($this);
  294.         }
  295.         return $this;
  296.     }
  297.     public function removeProduct(Product $product): self
  298.     {
  299.         if ($this->products->contains($product)) {
  300.             $this->products->removeElement($product);
  301.             // set the owning side to null (unless already changed)
  302.             if ($product->getCategory() === $this) {
  303.                 $product->setCategory(null);
  304.             }
  305.         }
  306.         return $this;
  307.     }
  308.     public function getHasProducts(): bool
  309.     {
  310.         if($this->getAllProducts()->count() > 0){
  311.             return true;
  312.         }else{
  313.             $cats $this->getCategories();
  314.             foreach($cats as $c){
  315.                 if($c->getHasProducts())
  316.                     return true;
  317.             }
  318.         }
  319.         return false;
  320.     }
  321.     public function getIsValid(): bool
  322.     {
  323.         return $this->isValid();
  324.     }
  325.     public function getIsDisplayedForBuyer(): ?bool
  326.     {
  327.         return $this->isDisplayedForBuyer;
  328.     }
  329.     public function setIsDisplayedForBuyer(bool $isDisplayedForBuyer): self
  330.     {
  331.         $this->isDisplayedForBuyer $isDisplayedForBuyer;
  332.         return $this;
  333.     }
  334.     /*
  335.      * Used in the UI for building the menu
  336.      */
  337.     public function isValid()
  338.     {
  339.         return $this->getIsDisplayedForBuyer();
  340.     }
  341.     public function getAllProducts()
  342.     {
  343.         $cats $this->getAllSubCategories();
  344.         $clean = array();
  345.         $clean array_merge($this->getProducts()->toArray(), $this->getProductsSub()->toArray());
  346.         foreach($cats as $c){
  347.             $clean array_merge($clean$c->getProducts()->toArray(), $c->getProductsSub()->toArray());
  348.         }
  349.         //return new ArrayCollection(array_merge($this->getProducts()->toArray(), $this->getProductsSub()->toArray()));
  350.         return new ArrayCollection($clean);
  351.     }
  352.     public function getTier1MaturinFeesPc(): ?string
  353.     {
  354.         return $this->tier1MaturinFeesPc;
  355.     }
  356.     public function setTier1MaturinFeesPc(?string $tier1MaturinFeesPc): self
  357.     {
  358.         $this->tier1MaturinFeesPc $tier1MaturinFeesPc;
  359.         return $this;
  360.     }
  361.     public function getTier2MaturinFeesPc(): ?string
  362.     {
  363.         return $this->tier2MaturinFeesPc;
  364.     }
  365.     public function setTier2MaturinFeesPc(?string $tier2MaturinFeesPc): self
  366.     {
  367.         $this->tier2MaturinFeesPc $tier2MaturinFeesPc;
  368.         return $this;
  369.     }
  370.     public function getTier2MaturinFeesMinprice(): ?string
  371.     {
  372.         return $this->tier2MaturinFeesMinprice;
  373.     }
  374.     public function setTier2MaturinFeesMinprice(?string $tier2MaturinFeesMinprice): self
  375.     {
  376.         $this->tier2MaturinFeesMinprice $tier2MaturinFeesMinprice;
  377.         return $this;
  378.     }
  379.     public function getTier2MaturinFeesMaxprice(): ?string
  380.     {
  381.         return $this->tier2MaturinFeesMaxprice;
  382.     }
  383.     public function setTier2MaturinFeesMaxprice(?string $tier2MaturinFeesMaxprice): self
  384.     {
  385.         $this->tier2MaturinFeesMaxprice $tier2MaturinFeesMaxprice;
  386.         return $this;
  387.     }
  388.     public function getPackingFeesAmount(): ?string
  389.     {
  390.         return $this->packingFeesAmount;
  391.     }
  392.     public function setPackingFeesAmount(?string $packingFeesAmount): self
  393.     {
  394.         $this->packingFeesAmount $packingFeesAmount;
  395.         return $this;
  396.     }
  397.     public function getPackingSuppliesFeesAmount(): ?string
  398.     {
  399.         return $this->packingSuppliesFeesAmount;
  400.     }
  401.     public function setPackingSuppliesFeesAmount(?string $packingSuppliesFeesAmount): self
  402.     {
  403.         $this->packingSuppliesFeesAmount $packingSuppliesFeesAmount;
  404.         return $this;
  405.     }
  406. }