<?php
namespace Boab\CmsBundle\Entity;
use Boab\CmsBundle\Contract\ThumbnailInterface;
use Boab\CmsBundle\Contract\ThumbnailTrait;
use Doctrine\Common\Collections\Collection;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Taxonomy Term.
* @Gedmo\Tree(type="materializedPath")
* @ORM\Entity
* @ORM\HasLifecycleCallbacks()
* @ORM\Table(name="taxonomy_term")
* @ORM\Entity(repositoryClass="Boab\CmsBundle\Repository\TermRepository")
*/
class Term implements TermInterface, ThumbnailInterface
{
use ThumbnailTrait;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
* @ORM\Column(name="name", length=255, type="string")
*/
protected $name;
/**
* @var string
* @Gedmo\Slug(fields={"name"})
* @Gedmo\TreePathSource
* @ORM\Column(name="slug", length=255, type="string")
*/
protected $slug;
/**
* @var string
* @ORM\Column(name="description", length=255, type="string")
*/
protected $desc;
/**
* @var int
*
* @ORM\Column(name="weight", type="integer")
*/
protected $weight;
/**
* @Gedmo\TreePath(appendId=false, startsWithSeparator=true, endsWithSeparator=false, separator="/")
* @ORM\Column(name="path", length=10000, type="string", nullable=true)
*/
protected $path;
/**
* @var int
* @Gedmo\TreeLevel
* @ORM\Column(name="lvl", type="integer")
*/
protected $level;
/**
* @var
*
* @ORM\ManyToOne(targetEntity="Vocabulary", inversedBy="terms", fetch="EAGER")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="vid", referencedColumnName="id", onDelete="CASCADE")
* })
*/
public $vocabulary;
/**
* @var \DateTime
*
* @ORM\Column(name="createdAt", type="datetime")
*/
protected $createdAt;
/**
* @var \DateTime
*
* @ORM\Column(name="updatedAt", type="datetime", nullable=true)
*/
protected $updatedAt;
/**
* @var
* @Gedmo\TreeParent
* @ORM\ManyToOne(targetEntity="Term", inversedBy="children", fetch="EAGER")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="pid", referencedColumnName="id", nullable=true, onDelete="CASCADE")
* })
*/
protected $parent;
/**
* @ORM\OneToMany(targetEntity="Term", mappedBy="parent", fetch="EXTRA_LAZY")
* @ORM\OrderBy({"name" = "ASC"})
*/
protected $children;
/**
* @var boolean
*
* @ORM\Column(name="is_enable", type="boolean")
*/
protected $enabled;
/**
* @var \Boab\CmsBundle\Entity\TermRoute
*
* @ORM\OneToOne(targetEntity="Boab\CmsBundle\Entity\TermRoute", fetch="EAGER", cascade={"persist","remove"}, orphanRemoval=true)
* @ORM\JoinColumn(name="route_id", referencedColumnName="id", nullable=true)
*
*/
protected $route;
/**
* @ORM\OneToMany(targetEntity=Content::class, mappedBy="term", fetch="EXTRA_LAZY")
*/
protected $contents;
private $indentedName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $template;
public function __construct()
{
$this->desc = '';
$this->weight = 0;
$this->level = 0;
$this->enabled = true;
$this->createdAt = new \DateTime();
$this->children = new ArrayCollection();
}
public function __toString()
{
return $this->name;
}
/**
* Doctrine lifecycle callback.
* @ORM\PreUpdate
* @param PreUpdateEventArgs $args
*/
public function preUpdate(PreUpdateEventArgs $args)
{
if (!$args->hasChangedField('updatedAt')) {
$this->updatedAt = new \DateTime();
}
}
/**
* @param \DateTime $createdAt
*
*@return Term
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* @param string $desc
* @return Term
*/
public function setDesc($desc)
{
$this->desc = $desc ?: '';
return $this;
}
/**
* @return string
*/
public function getDesc()
{
return $this->desc;
}
/**
* @param string $id
* @return Term
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* @param string $name
* @return Term
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param \DateTime $updatedAt
*
* @return Term
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* @param Vocabulary $vocabulary
* @return Term
*/
public function setVocabulary($vocabulary)
{
$this->vocabulary = $vocabulary;
return $this;
}
/**
* @return Vocabulary
*/
public function getVocabulary()
{
return $this->vocabulary;
}
/**
* @param int $weight
* @return Term
*/
public function setWeight($weight)
{
$this->weight = $weight;
return $this;
}
/**
* @return int
*/
public function getWeight()
{
return $this->weight;
}
/**
* @param ArrayCollection $children
* @return Term
*/
public function setChildren(ArrayCollection $children)
{
$this->children = $children;
return $this;
}
/**
* @return ArrayCollection
*/
public function getChildren()
{
return $this->children;
}
/**
* @param int $level
* @return Term
*/
public function setLevel($level)
{
$this->level = $level;
return $this;
}
/**
* @return int
*/
public function getLevel()
{
return $this->level;
}
/**
* @param null|Term $parent
* @return Term
*/
public function setParent($parent)
{
$this->parent = $parent;
return $this;
}
/**
* @return null|Term
*/
public function getParent(): ?Term
{
return $this->parent;
}
/**
* @param string $path
* @return Term
*/
public function setPath($path)
{
$this->path = $path;
return $this;
}
/**
* @return string
*/
public function getPath(): string
{
return $this->path;
}
/**
* Returns the name prepended by level to show hierarchy.
*
* @param string $levelCharacter
* @param string $label
* @return string
*/
public function getHierarchyLabel($levelCharacter = '--', $label = 'name')
{
$labelFunc = 'get'.ucfirst($label);
return str_repeat($levelCharacter, $this->level) . ' ' . $this->$labelFunc();
}
/**
* @return boolean
*/
public function isEnabled():bool
{
return $this->enabled;
}
/**
* @param boolean $enabled
*
* @return Term
*/
public function setEnabled($enabled)
{
$this->enabled = (bool)$enabled;
return $this;
}
/**
* Set slug
*
* @param string $slug
*
* @return Term
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* Get slug
*
* @return string
*/
public function getSlug():string
{
return $this->slug;
}
/**
* Get enabled
*
* @return boolean
*/
public function getEnabled()
{
return $this->enabled;
}
/**
* Add child
*
* @param \Boab\CmsBundle\Entity\Term $child
*
* @return Term
*/
public function addChild(\Boab\CmsBundle\Entity\Term $child)
{
$this->children[] = $child;
return $this;
}
/**
* Remove child
*
* @param \Boab\CmsBundle\Entity\Term $child
*/
public function removeChild(\Boab\CmsBundle\Entity\Term $child)
{
$this->children->removeElement($child);
}
/**
* Set route
*
* @param \Boab\CmsBundle\Entity\TermRoute $route
*
* @return Term
*/
public function setRoute(\Boab\CmsBundle\Entity\TermRoute $route = null)
{
$this->route = $route;
return $this;
}
/**
* Get route
*
* @return \Boab\CmsBundle\Entity\TermRoute
*/
public function getRoute(): TermRoute
{
return $this->route;
}
public function getTemplate(): ?string
{
return $this->template;
}
public function setTemplate(?string $template): self
{
$this->template = $template;
return $this;
}
}