<?php
namespace App\Entity\Gos;
use App\Entity\Gos\Tmpl\Template;
use App\Entity\Gos\Uniqskills\Cooperator;
use App\Entity\Gos\Uniqskills\Author;
use App\Entity\Gos\Uniqskills\Course;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\HttpFoundation\File\File;
/**
* @ORM\Entity(repositoryClass="App\Repository\CategoriesRepository")
* @ORM\HasLifecycleCallbacks()
* @Vich\Uploadable
*/
class Category
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isActive;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $shortBody;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $body;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $testimonialsCustom;
/**
* @var ArrayCollection
*
* @ORM\ManyToOne(targetEntity="App\Entity\Gos\Category", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $parent;
/**
* @var Category
*
* @ORM\OneToMany(targetEntity="App\Entity\Gos\Category", mappedBy="parent")
* @ORM\OrderBy({"position" = "ASC"})
*/
private $children;
/**
* @ORM\Column(type="string", length=64)
*/
private $categoryName;
/**
* @ORM\Column(type="string", length=64)
*/
private $categorySlug;
/**
* @ORM\Column(name="position", type="string", length=255, nullable=true)
*/
private $position;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Gos\Tmpl\Template", mappedBy="category", cascade={"persist", "remove"})
*/
private $template;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Gos\PortalSettings", inversedBy="categories")
* @ORM\JoinColumn()
*/
private $portalSettings;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Gos\ProductAssociation", inversedBy="recommendedByCategory")
*/
private $recommendedProductAssociation;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Gos\ProductAssociation", mappedBy="categoryMaster")
*/
private $productAssociationMaster;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Gos\ProductAssociation", mappedBy="categories")
*/
private $productAssociations;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Gos\Uniqskills\Course", mappedBy="category")
*/
private $courses;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Gos\Uniqskills\Course", mappedBy="additionalCategories")
*/
private $additionalCourses;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Gos\Language", inversedBy="categories", fetch="EAGER")
*/
private $language;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Gos\MetaTags", mappedBy="category")
*/
private $metaTags;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Gos\Uniqskills\Author", mappedBy="categories")
*/
private $author;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Gos\Uniqskills\Author", mappedBy="categoriesProgramCouncil")
*/
private $programCouncil;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Gos\Uniqskills\Cooperator", mappedBy="categories")
* @ORM\JoinTable()
*/
private $cooperators;
/**
* @ORM\OneToMany(targetEntity="StaticPage", mappedBy="category")
*/
private $staticPages;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="product_image", fileNameProperty="imageName")
*
* @var File
*/
private $imageFile;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @var string
*/
private $imageName;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
* @Vich\UploadableField(mapping="banner_image", fileNameProperty="bannerName")
* @var File
*/
private $bannerFile;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @var string
*/
private $bannerName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $bannerLink;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $bannerHtml;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $defaultForUS;
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
*
* @return Category
*/
public function setImageFile(File $image = null)
{
$this->imageFile = $image;
if ($image) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new \DateTime('now');
}
return $this;
}
/**
* @return File|null
*/
public function getImageFile()
{
return $this->imageFile;
}
/**
* @param string $imageName
*
* @return Category
*/
public function setImageName($imageName)
{
$this->imageName = $imageName;
return $this;
}
/**
* @return string|null
*/
public function getImageName()
{
return $this->imageName;
}
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
* @return Category
*/
public function setBannerFile(File $image = null): self
{
$this->bannerFile = $image;
if ($image) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new \DateTime('now');
}
return $this;
}
/**
* @return File|null
*/
public function getBannerFile(): ?File
{
return $this->bannerFile;
}
/**
* @param string $bannerName
* @return Category
*/
public function setBannerName($bannerName): self
{
$this->bannerName = $bannerName;
return $this;
}
/**
* @return string|null
*/
public function getBannerName(): ?string
{
return $this->bannerName;
}
public function getNotEmptyAndActiveChildren($portalSettingsId, $userCourseIdArray)
{
$children = array();
/** @var Category $child */
foreach ($this->children as $child)
{
/** @var Category $child */
if (
$child->getIsActive()
&& !empty($child->getPortalSettings())
&& $child->getPortalSettings()->getId() == $portalSettingsId
&& count($child->getAllActiveCourses($portalSettingsId, $userCourseIdArray)) != 0
)
{
$children[] = $child;
}
}
return new \Doctrine\Common\Collections\ArrayCollection($children);
}
public function getAllActiveCourses($portalSettingsId, $userCourseIdArray)
{
$courses = array();
$courses = $this->listActiveCategories($portalSettingsId, $this->courses, $courses, $userCourseIdArray);
$courses = $this->listActiveCategories($portalSettingsId, $this->additionalCourses, $courses, $userCourseIdArray);
return new \Doctrine\Common\Collections\ArrayCollection($courses);
}
private function listActiveCategories($portalSettingsId, $courses, $return, $userCourseIdArray)
{
if (!is_array($userCourseIdArray))
$userCourseIdArray = array();
$dateNow = new \DateTime();
$dateNow = $dateNow->format('Y-m-d');
foreach ($courses as $course)
{
/** @var Course $course */
if (
(
(
$course->getIsActive()
&& $course->getOriginalCourse() === null
&& !empty($course->getPortalSettings())
&& $course->getPortalSettings()->getId() == $portalSettingsId
&& (
$course->getHideAfter() == null
|| $course->getHideAfter()->format("Y-m-d") > $dateNow
)
|| (
!$course->getIsActive()
&& in_array($course->getId(), $userCourseIdArray)
)
)
)
)
$return[] = $course;
}
return $return;
}
public function __construct()
{
$this->children = new ArrayCollection();
$this->courses = new ArrayCollection();
$this->additionalCourses = new ArrayCollection();
$this->productAssociationMaster = new ArrayCollection();
$this->productAssociations = new ArrayCollection();
$this->cooperators = new ArrayCollection();
$this->author = new ArrayCollection();
$this->programCouncil = new ArrayCollection();
$this->staticPages = new ArrayCollection();
}
public function __toString()
{
return (string)$this->categoryName;
}
public function getId()
{
return $this->id;
}
public function getCategoryName()
{
return $this->categoryName;
}
public function setCategoryName(string $categoryName): self
{
$this->categoryName = $categoryName;
return $this;
}
public function getCategorySlug()
{
return $this->categorySlug;
}
public function setCategorySlug(string $categorySlug): self
{
$this->categorySlug = $categorySlug;
return $this;
}
/**
* @return Collection|Category[]
*/
public function getChildren(): Collection
{
return $this->children;
}
public function setChildren($children) { //this will be an array collection so please pay attention
$this->children = $children;
return $this;
}
public function addChild(Category $child): self
{
if (!$this->children->contains($child)) {
$this->children[] = $child;
$child->setParent($this);
}
return $this;
}
public function removeChild(Category $child)
{
if ($this->children->contains($child))
{
$this->children->removeElement($child);
if ($child->getParent() === $this)
{
$child->setParent(null);
}
}
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
public function getTemplate(): ?Template
{
return $this->template;
}
public function setTemplate(?Template $template): self
{
$this->template = $template;
// set (or unset) the owning side of the relation if necessary
$newCategory = $template === null ? null : $this;
if ($newCategory !== $template->getCategory())
{
$template->setCategory($newCategory);
}
return $this;
}
public function getPosition(): ?string
{
return $this->position;
}
public function setPosition(?string $position): self
{
$this->position = $position;
return $this;
}
public function getRecommendedProductAssociation(): ?ProductAssociation
{
return $this->recommendedProductAssociation;
}
public function setRecommendedProductAssociation(?ProductAssociation $recommendedProductAssociation): self
{
$this->recommendedProductAssociation = $recommendedProductAssociation;
return $this;
}
public function getPortalSettings(): ?PortalSettings
{
return $this->portalSettings;
}
public function setPortalSettings(?PortalSettings $portalSettings): self
{
$this->portalSettings = $portalSettings;
return $this;
}
/**
* @return Collection|Course[]
*/
public function getCourses(): Collection
{
return $this->courses;
}
public function addCourse(Course $course): self
{
if (!$this->courses->contains($course)) {
$this->courses[] = $course;
$course->setCategory($this);
}
return $this;
}
public function removeCourse(Course $course): self
{
if ($this->courses->contains($course)) {
$this->courses->removeElement($course);
// set the owning side to null (unless already changed)
if ($course->getCategory() === $this) {
$course->setCategory(null);
}
}
return $this;
}
/**
* @return Collection|Course[]
*/
public function getAdditionalCourses(): Collection
{
return $this->additionalCourses;
}
public function addAdditionalCourse(Course $additionalCourse): self
{
if (!$this->additionalCourses->contains($additionalCourse)) {
$this->additionalCourses[] = $additionalCourse;
$additionalCourse->addAdditionalCategory($this);
}
return $this;
}
public function removeAdditionalCourse(Course $additionalCourse): self
{
if ($this->additionalCourses->contains($additionalCourse)) {
$this->additionalCourses->removeElement($additionalCourse);
$additionalCourse->removeAdditionalCategory($this);
}
return $this;
}
public function getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(?bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getLanguage(): ?Language
{
return $this->language;
}
public function setLanguage(?Language $language): self
{
$this->language = $language;
return $this;
}
public function getMetaTags(): ?MetaTags
{
return $this->metaTags;
}
public function setMetaTags(?MetaTags $metaTags): self
{
$this->metaTags = $metaTags;
// set (or unset) the owning side of the relation if necessary
$newCategory = $metaTags === null ? null : $this;
if ($newCategory !== $metaTags->getCategory()) {
$metaTags->setCategory($newCategory);
}
return $this;
}
/**
* @return Collection|ProductAssociation[]
*/
public function getProductAssociationMaster(): Collection
{
return $this->productAssociationMaster;
}
public function addProductAssociationMaster(ProductAssociation $productAssociationMaster): self
{
if (!$this->productAssociationMaster->contains($productAssociationMaster)) {
$this->productAssociationMaster[] = $productAssociationMaster;
$productAssociationMaster->setCategoryMaster($this);
}
return $this;
}
public function removeProductAssociationMaster(ProductAssociation $productAssociationMaster): self
{
if ($this->productAssociationMaster->contains($productAssociationMaster)) {
$this->productAssociationMaster->removeElement($productAssociationMaster);
// set the owning side to null (unless already changed)
if ($productAssociationMaster->getCategoryMaster() === $this) {
$productAssociationMaster->setCategoryMaster(null);
}
}
return $this;
}
/**
* @return Collection|ProductAssociation[]
*/
public function getProductAssociations(): Collection
{
return $this->productAssociations;
}
public function addProductAssociation(ProductAssociation $productAssociation): self
{
if (!$this->productAssociations->contains($productAssociation)) {
$this->productAssociations[] = $productAssociation;
}
return $this;
}
public function removeProductAssociation(ProductAssociation $productAssociation): self
{
if ($this->productAssociations->contains($productAssociation)) {
$this->productAssociations->removeElement($productAssociation);
}
return $this;
}
/**
* @return Collection|Author[]
*/
public function getAuthor(): Collection
{
return $this->author;
}
public function addAuthor(Author $author): self
{
if (!$this->author->contains($author)) {
$this->author[] = $author;
$author->addCategory($this);
}
return $this;
}
public function removeAuthor(Author $author): self
{
if ($this->author->contains($author)) {
$this->author->removeElement($author);
$author->removeCategory($this);
}
return $this;
}
/**
* @return Collection|Author[]
*/
public function getProgramCouncil(): Collection
{
return $this->programCouncil;
}
public function addProgramCouncil(Author $programCouncil): self
{
if (!$this->programCouncil->contains($programCouncil)) {
$this->programCouncil[] = $programCouncil;
$programCouncil->addCategoriesProgramCouncil($this);
}
return $this;
}
public function removeProgramCouncil(Author $programCouncil): self
{
if ($this->programCouncil->contains($programCouncil)) {
$this->programCouncil->removeElement($programCouncil);
$programCouncil->removeCategoriesProgramCouncil($this);
}
return $this;
}
/**
* @return Collection|Cooperator[]
*/
public function getCooperators(): Collection
{
return $this->cooperators;
}
public function addCooperator(Cooperator $cooperator): self
{
if (!$this->cooperators->contains($cooperator)) {
$this->cooperators[] = $cooperator;
}
return $this;
}
public function removeCooperator(Cooperator $cooperator): self
{
if ($this->cooperators->contains($cooperator)) {
$this->cooperators->removeElement($cooperator);
}
return $this;
}
/**
* @return Collection|StaticPage[]
*/
public function getStaticPages(): Collection
{
return $this->staticPages;
}
public function addStaticPage(StaticPage $staticPage): self
{
if (!$this->staticPages->contains($staticPage)) {
$this->staticPages[] = $staticPage;
$staticPage->setCategory($this);
}
return $this;
}
public function removeStaticPage(StaticPage $staticPage): self
{
if ($this->staticPages->contains($staticPage)) {
$this->staticPages->removeElement($staticPage);
// set the owning side to null (unless already changed)
if ($staticPage->getCategory() === $this) {
$staticPage->setCategory(null);
}
}
return $this;
}
public function getShortBody(): ?string
{
return $this->shortBody;
}
public function setShortBody(?string $shortBody): self
{
$this->shortBody = $shortBody;
return $this;
}
public function getBody(): ?string
{
return $this->body;
}
public function setBody(?string $body): self
{
$this->body = $body;
return $this;
}
public function getTestimonialsCustom(): ?string
{
return $this->testimonialsCustom;
}
public function setTestimonialsCustom(?string $testimonialsCustom): self
{
$this->testimonialsCustom = $testimonialsCustom;
return $this;
}
public function getBannerLink(): ?string
{
return $this->bannerLink;
}
public function setBannerLink(?string $bannerLink): self
{
$this->bannerLink = $bannerLink;
return $this;
}
public function getBannerHtml(): ?string
{
return $this->bannerHtml;
}
public function setBannerHtml(?string $bannerHtml): self
{
$this->bannerHtml = $bannerHtml;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getDefaultForUS(): ?bool
{
return $this->defaultForUS;
}
public function setDefaultForUS(?bool $defaultForUS): self
{
$this->defaultForUS = $defaultForUS;
return $this;
}
}