src/Entity/Gos/Category.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Gos;
  3. use App\Entity\Gos\Tmpl\Template;
  4. use App\Entity\Gos\Uniqskills\Cooperator;
  5. use App\Entity\Gos\Uniqskills\Author;
  6. use App\Entity\Gos\Uniqskills\Course;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  11. use Symfony\Component\HttpFoundation\File\File;
  12. /**
  13.  * @ORM\Entity(repositoryClass="App\Repository\CategoriesRepository")
  14.  * @ORM\HasLifecycleCallbacks()
  15.  * @Vich\Uploadable
  16.  */
  17. class Category
  18. {
  19.     /**
  20.      * @ORM\Id()
  21.      * @ORM\GeneratedValue()
  22.      * @ORM\Column(type="integer")
  23.      */
  24.     private $id;
  25.     /**
  26.      * @ORM\Column(type="boolean", nullable=true)
  27.      */
  28.     private $isActive;
  29.     /**
  30.      * @ORM\Column(type="text", nullable=true)
  31.      */
  32.     private $shortBody;
  33.     /**
  34.      * @ORM\Column(type="text", nullable=true)
  35.      */
  36.     private $body;
  37.     /**
  38.      * @ORM\Column(type="text", nullable=true)
  39.      */
  40.     private $testimonialsCustom;
  41.     /**
  42.      * @var ArrayCollection
  43.      *
  44.      * @ORM\ManyToOne(targetEntity="App\Entity\Gos\Category", inversedBy="children")
  45.      * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
  46.      */
  47.     private $parent;
  48.     /**
  49.      * @var Category
  50.      *
  51.      * @ORM\OneToMany(targetEntity="App\Entity\Gos\Category", mappedBy="parent")
  52.      * @ORM\OrderBy({"position" = "ASC"})
  53.      */
  54.     private $children;
  55.     /**
  56.      * @ORM\Column(type="string", length=64)
  57.      */
  58.     private $categoryName;
  59.     /**
  60.      * @ORM\Column(type="string", length=64)
  61.      */
  62.     private $categorySlug;
  63.     /**
  64.      * @ORM\Column(name="position", type="string", length=255, nullable=true)
  65.      */
  66.     private $position;
  67.     /**
  68.      * @ORM\OneToOne(targetEntity="App\Entity\Gos\Tmpl\Template", mappedBy="category", cascade={"persist", "remove"})
  69.      */
  70.     private $template;
  71.     /**
  72.      * @ORM\ManyToOne(targetEntity="App\Entity\Gos\PortalSettings", inversedBy="categories")
  73.      * @ORM\JoinColumn()
  74.      */
  75.     private $portalSettings;
  76.     /**
  77.      * @ORM\OneToOne(targetEntity="App\Entity\Gos\ProductAssociation", inversedBy="recommendedByCategory")
  78.      */
  79.     private $recommendedProductAssociation;
  80.     /**
  81.      * @ORM\OneToMany(targetEntity="App\Entity\Gos\ProductAssociation", mappedBy="categoryMaster")
  82.      */
  83.     private $productAssociationMaster;
  84.     /**
  85.      * @ORM\ManyToMany(targetEntity="App\Entity\Gos\ProductAssociation", mappedBy="categories")
  86.      */
  87.     private $productAssociations;
  88.     /**
  89.      * @ORM\OneToMany(targetEntity="App\Entity\Gos\Uniqskills\Course", mappedBy="category")
  90.      */
  91.     private $courses;
  92.     /**
  93.      * @ORM\ManyToMany(targetEntity="App\Entity\Gos\Uniqskills\Course", mappedBy="additionalCategories")
  94.      */
  95.     private $additionalCourses;
  96.     /**
  97.      * @ORM\ManyToOne(targetEntity="App\Entity\Gos\Language", inversedBy="categories",  fetch="EAGER")
  98.      */
  99.     private $language;
  100.     /**
  101.      * @ORM\OneToOne(targetEntity="App\Entity\Gos\MetaTags", mappedBy="category")
  102.      */
  103.     private $metaTags;
  104.     /**
  105.      * @ORM\ManyToMany(targetEntity="App\Entity\Gos\Uniqskills\Author", mappedBy="categories")
  106.      */
  107.     private $author;
  108.     /**
  109.      * @ORM\ManyToMany(targetEntity="App\Entity\Gos\Uniqskills\Author", mappedBy="categoriesProgramCouncil")
  110.      */
  111.     private $programCouncil;
  112.     /**
  113.      * @ORM\ManyToMany(targetEntity="App\Entity\Gos\Uniqskills\Cooperator", mappedBy="categories")
  114.      * @ORM\JoinTable()
  115.      */
  116.     private $cooperators;
  117.     /**
  118.      * @ORM\OneToMany(targetEntity="StaticPage", mappedBy="category")
  119.      */
  120.     private $staticPages;
  121.     /**
  122.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  123.      *
  124.      * @Vich\UploadableField(mapping="product_image", fileNameProperty="imageName")
  125.      *
  126.      * @var File
  127.      */
  128.     private $imageFile;
  129.     /**
  130.      * @ORM\Column(type="string", length=255, nullable=true)
  131.      *
  132.      * @var string
  133.      */
  134.     private $imageName;
  135.     /**
  136.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  137.      * @Vich\UploadableField(mapping="banner_image", fileNameProperty="bannerName")
  138.      * @var File
  139.      */
  140.     private $bannerFile;
  141.     /**
  142.      * @ORM\Column(type="string", length=255, nullable=true)
  143.      * @var string
  144.      */
  145.     private $bannerName;
  146.     /**
  147.      * @ORM\Column(type="string", length=255, nullable=true)
  148.      */
  149.     private $bannerLink;
  150.     /**
  151.      * @ORM\Column(type="text", nullable=true)
  152.      */
  153.     private $bannerHtml;
  154.     /**
  155.      * @ORM\Column(type="datetime", nullable=true)
  156.      */
  157.     private $updatedAt;
  158.     /**
  159.      * @ORM\Column(type="boolean", nullable=true)
  160.      */
  161.     private $defaultForUS;
  162.     /**
  163.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  164.      * of 'UploadedFile' is injected into this setter to trigger the  update. If this
  165.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  166.      * must be able to accept an instance of 'File' as the bundle will inject one here
  167.      * during Doctrine hydration.
  168.      *
  169.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
  170.      *
  171.      * @return Category
  172.      */
  173.     public function setImageFile(File $image null)
  174.     {
  175.         $this->imageFile $image;
  176.         if ($image) {
  177.             // It is required that at least one field changes if you are using doctrine
  178.             // otherwise the event listeners won't be called and the file is lost
  179.             $this->updatedAt = new \DateTime('now');
  180.         }
  181.         return $this;
  182.     }
  183.     /**
  184.      * @return File|null
  185.      */
  186.     public function getImageFile()
  187.     {
  188.         return $this->imageFile;
  189.     }
  190.     /**
  191.      * @param string $imageName
  192.      *
  193.      * @return Category
  194.      */
  195.     public function setImageName($imageName)
  196.     {
  197.         $this->imageName $imageName;
  198.         return $this;
  199.     }
  200.     /**
  201.      * @return string|null
  202.      */
  203.     public function getImageName()
  204.     {
  205.         return $this->imageName;
  206.     }
  207.     /**
  208.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  209.      * of 'UploadedFile' is injected into this setter to trigger the  update. If this
  210.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  211.      * must be able to accept an instance of 'File' as the bundle will inject one here
  212.      * during Doctrine hydration.
  213.      *
  214.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
  215.      * @return Category
  216.      */
  217.     public function setBannerFile(File $image null): self
  218.     {
  219.         $this->bannerFile $image;
  220.         if ($image) {
  221.             // It is required that at least one field changes if you are using doctrine
  222.             // otherwise the event listeners won't be called and the file is lost
  223.             $this->updatedAt = new \DateTime('now');
  224.         }
  225.         return $this;
  226.     }
  227.     /**
  228.      * @return File|null
  229.      */
  230.     public function getBannerFile(): ?File
  231.     {
  232.         return $this->bannerFile;
  233.     }
  234.     /**
  235.      * @param string $bannerName
  236.      * @return Category
  237.      */
  238.     public function setBannerName($bannerName): self
  239.     {
  240.         $this->bannerName $bannerName;
  241.         return $this;
  242.     }
  243.     /**
  244.      * @return string|null
  245.      */
  246.     public function getBannerName(): ?string
  247.     {
  248.         return $this->bannerName;
  249.     }
  250.     public function getNotEmptyAndActiveChildren($portalSettingsId$userCourseIdArray)
  251.     {
  252.         $children = array();
  253.         /** @var Category $child */
  254.         foreach ($this->children as $child)
  255.         {
  256.             /** @var Category $child */
  257.             if (
  258.                 $child->getIsActive()
  259.                 && !empty($child->getPortalSettings())
  260.                 && $child->getPortalSettings()->getId() == $portalSettingsId
  261.                 && count($child->getAllActiveCourses($portalSettingsId$userCourseIdArray)) != 0
  262.             )
  263.             {
  264.                 $children[] = $child;
  265.             }
  266.         }
  267.         return new \Doctrine\Common\Collections\ArrayCollection($children);
  268.     }
  269.     public function getAllActiveCourses($portalSettingsId$userCourseIdArray)
  270.     {
  271.         $courses = array();
  272.         $courses $this->listActiveCategories($portalSettingsId$this->courses$courses$userCourseIdArray);
  273.         $courses $this->listActiveCategories($portalSettingsId$this->additionalCourses$courses$userCourseIdArray);
  274.         return new \Doctrine\Common\Collections\ArrayCollection($courses);
  275.     }
  276.     private function listActiveCategories($portalSettingsId$courses$return$userCourseIdArray)
  277.     {
  278.         if (!is_array($userCourseIdArray))
  279.             $userCourseIdArray = array();
  280.         $dateNow = new \DateTime();
  281.         $dateNow $dateNow->format('Y-m-d');
  282.         foreach ($courses as $course)
  283.         {
  284.             /** @var Course $course */
  285.             if (
  286.             (
  287.             (
  288.                 $course->getIsActive()
  289.                 && $course->getOriginalCourse() === null
  290.                 && !empty($course->getPortalSettings())
  291.                 && $course->getPortalSettings()->getId() == $portalSettingsId
  292.                 && (
  293.                     $course->getHideAfter() == null
  294.                     || $course->getHideAfter()->format("Y-m-d") > $dateNow
  295.                 )
  296.                 || (
  297.                     !$course->getIsActive()
  298.                     && in_array($course->getId(), $userCourseIdArray)
  299.                 )
  300.             )
  301.             )
  302.             )
  303.                 $return[] = $course;
  304.         }
  305.         return $return;
  306.     }
  307.     public function __construct()
  308.     {
  309.         $this->children                 = new ArrayCollection();
  310.         $this->courses                  = new ArrayCollection();
  311.         $this->additionalCourses        = new ArrayCollection();
  312.         $this->productAssociationMaster = new ArrayCollection();
  313.         $this->productAssociations      = new ArrayCollection();
  314.         $this->cooperators              = new ArrayCollection();
  315.         $this->author                   = new ArrayCollection();
  316.         $this->programCouncil           = new ArrayCollection();
  317.         $this->staticPages              = new ArrayCollection();
  318.     }
  319.     public function __toString()
  320.     {
  321.         return (string)$this->categoryName;
  322.     }
  323.     public function getId()
  324.     {
  325.         return $this->id;
  326.     }
  327.     public function getCategoryName()
  328.     {
  329.         return $this->categoryName;
  330.     }
  331.     public function setCategoryName(string $categoryName): self
  332.     {
  333.         $this->categoryName $categoryName;
  334.         return $this;
  335.     }
  336.     public function getCategorySlug()
  337.     {
  338.         return $this->categorySlug;
  339.     }
  340.     public function setCategorySlug(string $categorySlug): self
  341.     {
  342.         $this->categorySlug $categorySlug;
  343.         return $this;
  344.     }
  345.     /**
  346.      * @return Collection|Category[]
  347.      */
  348.     public function getChildren(): Collection
  349.     {
  350.         return $this->children;
  351.     }
  352.     public function setChildren($children) { //this will be an array collection so please pay attention
  353.         $this->children $children;
  354.         return $this;
  355.     }
  356.     public function addChild(Category $child): self
  357.     {
  358.         if (!$this->children->contains($child)) {
  359.             $this->children[] = $child;
  360.             $child->setParent($this);
  361.         }
  362.         return $this;
  363.     }
  364.     public function removeChild(Category $child)
  365.     {
  366.         if ($this->children->contains($child))
  367.         {
  368.             $this->children->removeElement($child);
  369.             if ($child->getParent() === $this)
  370.             {
  371.                 $child->setParent(null);
  372.             }
  373.         }
  374.         return $this;
  375.     }
  376.     public function getParent(): ?self
  377.     {
  378.         return $this->parent;
  379.     }
  380.     public function setParent(?self $parent): self
  381.     {
  382.         $this->parent $parent;
  383.         return $this;
  384.     }
  385.     public function getTemplate(): ?Template
  386.     {
  387.         return $this->template;
  388.     }
  389.     public function setTemplate(?Template $template): self
  390.     {
  391.         $this->template $template;
  392.         // set (or unset) the owning side of the relation if necessary
  393.         $newCategory $template === null null $this;
  394.         if ($newCategory !== $template->getCategory())
  395.         {
  396.             $template->setCategory($newCategory);
  397.         }
  398.         return $this;
  399.     }
  400.     public function getPosition(): ?string
  401.     {
  402.         return $this->position;
  403.     }
  404.     public function setPosition(?string $position): self
  405.     {
  406.         $this->position $position;
  407.         return $this;
  408.     }
  409.     public function getRecommendedProductAssociation(): ?ProductAssociation
  410.     {
  411.         return $this->recommendedProductAssociation;
  412.     }
  413.     public function setRecommendedProductAssociation(?ProductAssociation $recommendedProductAssociation): self
  414.     {
  415.         $this->recommendedProductAssociation $recommendedProductAssociation;
  416.         return $this;
  417.     }
  418.     public function getPortalSettings(): ?PortalSettings
  419.     {
  420.         return $this->portalSettings;
  421.     }
  422.     public function setPortalSettings(?PortalSettings $portalSettings): self
  423.     {
  424.         $this->portalSettings $portalSettings;
  425.         return $this;
  426.     }
  427.     /**
  428.      * @return Collection|Course[]
  429.      */
  430.     public function getCourses(): Collection
  431.     {
  432.         return $this->courses;
  433.     }
  434.     public function addCourse(Course $course): self
  435.     {
  436.         if (!$this->courses->contains($course)) {
  437.             $this->courses[] = $course;
  438.             $course->setCategory($this);
  439.         }
  440.         return $this;
  441.     }
  442.     public function removeCourse(Course $course): self
  443.     {
  444.         if ($this->courses->contains($course)) {
  445.             $this->courses->removeElement($course);
  446.             // set the owning side to null (unless already changed)
  447.             if ($course->getCategory() === $this) {
  448.                 $course->setCategory(null);
  449.             }
  450.         }
  451.         return $this;
  452.     }
  453.     /**
  454.      * @return Collection|Course[]
  455.      */
  456.     public function getAdditionalCourses(): Collection
  457.     {
  458.         return $this->additionalCourses;
  459.     }
  460.     public function addAdditionalCourse(Course $additionalCourse): self
  461.     {
  462.         if (!$this->additionalCourses->contains($additionalCourse)) {
  463.             $this->additionalCourses[] = $additionalCourse;
  464.             $additionalCourse->addAdditionalCategory($this);
  465.         }
  466.         return $this;
  467.     }
  468.     public function removeAdditionalCourse(Course $additionalCourse): self
  469.     {
  470.         if ($this->additionalCourses->contains($additionalCourse)) {
  471.             $this->additionalCourses->removeElement($additionalCourse);
  472.             $additionalCourse->removeAdditionalCategory($this);
  473.         }
  474.         return $this;
  475.     }
  476.     public function getIsActive(): ?bool
  477.     {
  478.         return $this->isActive;
  479.     }
  480.     public function setIsActive(?bool $isActive): self
  481.     {
  482.         $this->isActive $isActive;
  483.         return $this;
  484.     }
  485.     public function getLanguage(): ?Language
  486.     {
  487.         return $this->language;
  488.     }
  489.     public function setLanguage(?Language $language): self
  490.     {
  491.         $this->language $language;
  492.         return $this;
  493.     }
  494.     public function getMetaTags(): ?MetaTags
  495.     {
  496.         return $this->metaTags;
  497.     }
  498.     public function setMetaTags(?MetaTags $metaTags): self
  499.     {
  500.         $this->metaTags $metaTags;
  501.         // set (or unset) the owning side of the relation if necessary
  502.         $newCategory $metaTags === null null $this;
  503.         if ($newCategory !== $metaTags->getCategory()) {
  504.             $metaTags->setCategory($newCategory);
  505.         }
  506.         return $this;
  507.     }
  508.     /**
  509.      * @return Collection|ProductAssociation[]
  510.      */
  511.     public function getProductAssociationMaster(): Collection
  512.     {
  513.         return $this->productAssociationMaster;
  514.     }
  515.     public function addProductAssociationMaster(ProductAssociation $productAssociationMaster): self
  516.     {
  517.         if (!$this->productAssociationMaster->contains($productAssociationMaster)) {
  518.             $this->productAssociationMaster[] = $productAssociationMaster;
  519.             $productAssociationMaster->setCategoryMaster($this);
  520.         }
  521.         return $this;
  522.     }
  523.     public function removeProductAssociationMaster(ProductAssociation $productAssociationMaster): self
  524.     {
  525.         if ($this->productAssociationMaster->contains($productAssociationMaster)) {
  526.             $this->productAssociationMaster->removeElement($productAssociationMaster);
  527.             // set the owning side to null (unless already changed)
  528.             if ($productAssociationMaster->getCategoryMaster() === $this) {
  529.                 $productAssociationMaster->setCategoryMaster(null);
  530.             }
  531.         }
  532.         return $this;
  533.     }
  534.     /**
  535.      * @return Collection|ProductAssociation[]
  536.      */
  537.     public function getProductAssociations(): Collection
  538.     {
  539.         return $this->productAssociations;
  540.     }
  541.     public function addProductAssociation(ProductAssociation $productAssociation): self
  542.     {
  543.         if (!$this->productAssociations->contains($productAssociation)) {
  544.             $this->productAssociations[] = $productAssociation;
  545.         }
  546.         return $this;
  547.     }
  548.     public function removeProductAssociation(ProductAssociation $productAssociation): self
  549.     {
  550.         if ($this->productAssociations->contains($productAssociation)) {
  551.             $this->productAssociations->removeElement($productAssociation);
  552.         }
  553.         return $this;
  554.     }
  555.     /**
  556.      * @return Collection|Author[]
  557.      */
  558.     public function getAuthor(): Collection
  559.     {
  560.         return $this->author;
  561.     }
  562.     public function addAuthor(Author $author): self
  563.     {
  564.         if (!$this->author->contains($author)) {
  565.             $this->author[] = $author;
  566.             $author->addCategory($this);
  567.         }
  568.         return $this;
  569.     }
  570.     public function removeAuthor(Author $author): self
  571.     {
  572.         if ($this->author->contains($author)) {
  573.             $this->author->removeElement($author);
  574.             $author->removeCategory($this);
  575.         }
  576.         return $this;
  577.     }
  578.     /**
  579.      * @return Collection|Author[]
  580.      */
  581.     public function getProgramCouncil(): Collection
  582.     {
  583.         return $this->programCouncil;
  584.     }
  585.     public function addProgramCouncil(Author $programCouncil): self
  586.     {
  587.         if (!$this->programCouncil->contains($programCouncil)) {
  588.             $this->programCouncil[] = $programCouncil;
  589.             $programCouncil->addCategoriesProgramCouncil($this);
  590.         }
  591.         return $this;
  592.     }
  593.     public function removeProgramCouncil(Author $programCouncil): self
  594.     {
  595.         if ($this->programCouncil->contains($programCouncil)) {
  596.             $this->programCouncil->removeElement($programCouncil);
  597.             $programCouncil->removeCategoriesProgramCouncil($this);
  598.         }
  599.         return $this;
  600.     }
  601.     /**
  602.      * @return Collection|Cooperator[]
  603.      */
  604.     public function getCooperators(): Collection
  605.     {
  606.         return $this->cooperators;
  607.     }
  608.     public function addCooperator(Cooperator $cooperator): self
  609.     {
  610.         if (!$this->cooperators->contains($cooperator)) {
  611.             $this->cooperators[] = $cooperator;
  612.         }
  613.         return $this;
  614.     }
  615.     public function removeCooperator(Cooperator $cooperator): self
  616.     {
  617.         if ($this->cooperators->contains($cooperator)) {
  618.             $this->cooperators->removeElement($cooperator);
  619.         }
  620.         return $this;
  621.     }
  622.     /**
  623.      * @return Collection|StaticPage[]
  624.      */
  625.     public function getStaticPages(): Collection
  626.     {
  627.         return $this->staticPages;
  628.     }
  629.     public function addStaticPage(StaticPage $staticPage): self
  630.     {
  631.         if (!$this->staticPages->contains($staticPage)) {
  632.             $this->staticPages[] = $staticPage;
  633.             $staticPage->setCategory($this);
  634.         }
  635.         return $this;
  636.     }
  637.     public function removeStaticPage(StaticPage $staticPage): self
  638.     {
  639.         if ($this->staticPages->contains($staticPage)) {
  640.             $this->staticPages->removeElement($staticPage);
  641.             // set the owning side to null (unless already changed)
  642.             if ($staticPage->getCategory() === $this) {
  643.                 $staticPage->setCategory(null);
  644.             }
  645.         }
  646.         return $this;
  647.     }
  648.     public function getShortBody(): ?string
  649.     {
  650.         return $this->shortBody;
  651.     }
  652.     public function setShortBody(?string $shortBody): self
  653.     {
  654.         $this->shortBody $shortBody;
  655.         return $this;
  656.     }
  657.     public function getBody(): ?string
  658.     {
  659.         return $this->body;
  660.     }
  661.     public function setBody(?string $body): self
  662.     {
  663.         $this->body $body;
  664.         return $this;
  665.     }
  666.     public function getTestimonialsCustom(): ?string
  667.     {
  668.         return $this->testimonialsCustom;
  669.     }
  670.     public function setTestimonialsCustom(?string $testimonialsCustom): self
  671.     {
  672.         $this->testimonialsCustom $testimonialsCustom;
  673.         return $this;
  674.     }
  675.     public function getBannerLink(): ?string
  676.     {
  677.         return $this->bannerLink;
  678.     }
  679.     public function setBannerLink(?string $bannerLink): self
  680.     {
  681.         $this->bannerLink $bannerLink;
  682.         return $this;
  683.     }
  684.     public function getBannerHtml(): ?string
  685.     {
  686.         return $this->bannerHtml;
  687.     }
  688.     public function setBannerHtml(?string $bannerHtml): self
  689.     {
  690.         $this->bannerHtml $bannerHtml;
  691.         return $this;
  692.     }
  693.     public function getUpdatedAt(): ?\DateTimeInterface
  694.     {
  695.         return $this->updatedAt;
  696.     }
  697.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  698.     {
  699.         $this->updatedAt $updatedAt;
  700.         return $this;
  701.     }
  702.     public function getDefaultForUS(): ?bool
  703.     {
  704.         return $this->defaultForUS;
  705.     }
  706.     public function setDefaultForUS(?bool $defaultForUS): self
  707.     {
  708.         $this->defaultForUS $defaultForUS;
  709.         return $this;
  710.     }
  711. }