lib/boab/cms-bundle/src/Entity/Term.php line 21

Open in your IDE?
  1. <?php
  2. namespace Boab\CmsBundle\Entity;
  3. use Boab\CmsBundle\Contract\ThumbnailInterface;
  4. use Boab\CmsBundle\Contract\ThumbnailTrait;
  5. use Doctrine\Common\Collections\Collection;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Doctrine\ORM\Event\PreUpdateEventArgs;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. /**
  11.  * Taxonomy Term.
  12.   * @Gedmo\Tree(type="materializedPath") 
  13.  * @ORM\Entity 
  14.  * @ORM\HasLifecycleCallbacks()
  15.  * @ORM\Table(name="taxonomy_term")
  16.  * @ORM\Entity(repositoryClass="Boab\CmsBundle\Repository\TermRepository") 
  17.  */
  18. class Term implements TermInterfaceThumbnailInterface
  19. {
  20.    
  21.     use ThumbnailTrait;
  22.    /**
  23.      * @var integer
  24.      *
  25.      * @ORM\Column(name="id", type="integer")
  26.      * @ORM\Id
  27.      * @ORM\GeneratedValue(strategy="AUTO")
  28.      */
  29.     protected $id;
  30.     /**
  31.      * @var string
  32.      * @ORM\Column(name="name", length=255, type="string")
  33.      */
  34.     protected $name;
  35.     /**
  36.      * @var string
  37.      * @Gedmo\Slug(fields={"name"})  
  38.      * @Gedmo\TreePathSource             
  39.      * @ORM\Column(name="slug", length=255, type="string")
  40.      */
  41.     protected $slug;    
  42.     /**
  43.      * @var string
  44.      * @ORM\Column(name="description", length=255, type="string")
  45.      */
  46.     protected $desc;
  47.     /**
  48.      * @var int
  49.      *
  50.      * @ORM\Column(name="weight", type="integer")
  51.      */
  52.     protected $weight;
  53.     /**
  54.      * @Gedmo\TreePath(appendId=false, startsWithSeparator=true, endsWithSeparator=false, separator="/")
  55.      * @ORM\Column(name="path", length=10000, type="string", nullable=true)
  56.      */
  57.     protected $path;
  58.     /**
  59.      * @var int
  60.      * @Gedmo\TreeLevel
  61.      * @ORM\Column(name="lvl", type="integer")
  62.      */
  63.     protected $level;
  64.     /**
  65.      * @var
  66.      *
  67.      * @ORM\ManyToOne(targetEntity="Vocabulary", inversedBy="terms", fetch="EAGER")
  68.      * @ORM\JoinColumns({
  69.      *   @ORM\JoinColumn(name="vid", referencedColumnName="id", onDelete="CASCADE")
  70.      * })
  71.      */
  72.     public $vocabulary;
  73.     /**
  74.      * @var \DateTime
  75.      *
  76.      * @ORM\Column(name="createdAt", type="datetime")
  77.      */
  78.     protected $createdAt;
  79.     /**
  80.      * @var \DateTime
  81.      *
  82.      * @ORM\Column(name="updatedAt", type="datetime", nullable=true)
  83.      */
  84.     protected $updatedAt;
  85.     /**
  86.      * @var
  87.      * @Gedmo\TreeParent
  88.      * @ORM\ManyToOne(targetEntity="Term", inversedBy="children", fetch="EAGER")
  89.      * @ORM\JoinColumns({
  90.      *   @ORM\JoinColumn(name="pid", referencedColumnName="id", nullable=true, onDelete="CASCADE")
  91.      * })
  92.      */
  93.     protected $parent;
  94.     /**
  95.      * @ORM\OneToMany(targetEntity="Term", mappedBy="parent", fetch="EXTRA_LAZY")
  96.      * @ORM\OrderBy({"name" = "ASC"})
  97.      */
  98.     protected $children;
  99.     /**
  100.      * @var boolean
  101.      *
  102.      * @ORM\Column(name="is_enable", type="boolean")
  103.      */
  104.     protected $enabled;
  105.     /**
  106.      * @var \Boab\CmsBundle\Entity\TermRoute
  107.      *
  108.      * @ORM\OneToOne(targetEntity="Boab\CmsBundle\Entity\TermRoute", fetch="EAGER", cascade={"persist","remove"}, orphanRemoval=true)
  109.      * @ORM\JoinColumn(name="route_id", referencedColumnName="id", nullable=true)
  110.      * 
  111.      */
  112.     protected $route;   
  113.     
  114.     /**
  115.      * @ORM\OneToMany(targetEntity=Content::class, mappedBy="term", fetch="EXTRA_LAZY")
  116.      */
  117.     protected $contents;    
  118.     private $indentedName;
  119.     /**
  120.      * @ORM\Column(type="string", length=255, nullable=true)
  121.      */
  122.     private $template;
  123.     public function __construct()
  124.     {
  125.         $this->desc      '';
  126.         $this->weight    0;
  127.         $this->level     0;
  128.         $this->enabled   true;
  129.         $this->createdAt = new \DateTime();
  130.         $this->children  = new ArrayCollection();
  131.     }
  132.     public function __toString()
  133.     {
  134.         return $this->name;
  135.     }
  136.     /**
  137.      * Doctrine lifecycle callback.
  138.      * @ORM\PreUpdate     
  139.      * @param PreUpdateEventArgs $args
  140.      */
  141.     public function preUpdate(PreUpdateEventArgs $args)
  142.     {
  143.         if (!$args->hasChangedField('updatedAt')) {
  144.             $this->updatedAt = new \DateTime();
  145.         }
  146.     }
  147.     /**
  148.      * @param \DateTime $createdAt
  149.      *
  150. *@return Term
  151.      */
  152.     public function setCreatedAt($createdAt)
  153.     {
  154.         $this->createdAt $createdAt;
  155.         return $this;
  156.     }
  157.     /**
  158.      * @return \DateTime
  159.      */
  160.     public function getCreatedAt()
  161.     {
  162.         return $this->createdAt;
  163.     }
  164.     /**
  165.      * @param string $desc
  166.      * @return Term
  167.      */
  168.     public function setDesc($desc)
  169.     {
  170.         $this->desc $desc ?: '';
  171.         return $this;
  172.     }
  173.     /**
  174.      * @return string
  175.      */
  176.     public function getDesc()
  177.     {
  178.         return $this->desc;
  179.     }
  180.     /**
  181.      * @param string $id
  182.      * @return Term
  183.      */
  184.     public function setId($id)
  185.     {
  186.         $this->id $id;
  187.         return $this;
  188.     }
  189.     /**
  190.      * @return string
  191.      */
  192.     public function getId()
  193.     {
  194.         return $this->id;
  195.     }
  196.     /**
  197.      * @param string $name
  198.      * @return Term
  199.      */
  200.     public function setName($name)
  201.     {
  202.         $this->name $name;
  203.         return $this;
  204.     }
  205.     /**
  206.      * @return string
  207.      */
  208.     public function getName(): string
  209.     {
  210.         return $this->name;
  211.     }
  212.     /**
  213.      * @param \DateTime $updatedAt
  214.      *
  215.      * @return Term
  216.      */
  217.     public function setUpdatedAt($updatedAt)
  218.     {
  219.         $this->updatedAt $updatedAt;
  220.         return $this;
  221.     }
  222.     /**
  223.      * @return \DateTime
  224.      */
  225.     public function getUpdatedAt()
  226.     {
  227.         return $this->updatedAt;
  228.     }
  229.     /**
  230.      * @param Vocabulary $vocabulary
  231.      * @return Term
  232.      */
  233.     public function setVocabulary($vocabulary)
  234.     {
  235.         $this->vocabulary $vocabulary;
  236.         return $this;
  237.     }
  238.     /**
  239.      * @return Vocabulary
  240.      */
  241.     public function getVocabulary()
  242.     {
  243.         return $this->vocabulary;
  244.     }
  245.     /**
  246.      * @param int $weight
  247.      * @return Term
  248.      */
  249.     public function setWeight($weight)
  250.     {
  251.         $this->weight $weight;
  252.         return $this;
  253.     }
  254.     /**
  255.      * @return int
  256.      */
  257.     public function getWeight()
  258.     {
  259.         return $this->weight;
  260.     }
  261.     /**
  262.      * @param ArrayCollection $children
  263.      * @return Term
  264.      */
  265.     public function setChildren(ArrayCollection $children)
  266.     {
  267.         $this->children $children;
  268.         return $this;
  269.     }
  270.     /**
  271.      * @return ArrayCollection
  272.      */
  273.     public function getChildren()
  274.     {
  275.         return $this->children;
  276.     }
  277.     /**
  278.      * @param int $level
  279.      * @return Term
  280.      */
  281.     public function setLevel($level)
  282.     {
  283.         $this->level $level;
  284.         return $this;
  285.     }
  286.     /**
  287.      * @return int
  288.      */
  289.     public function getLevel()
  290.     {
  291.         return $this->level;
  292.     }
  293.     /**
  294.      * @param null|Term $parent
  295.      * @return Term
  296.      */
  297.     public function setParent($parent)
  298.     {
  299.         $this->parent $parent;
  300.         return $this;
  301.     }
  302.     /**
  303.      * @return null|Term
  304.      */
  305.     public function getParent(): ?Term
  306.     {
  307.         return $this->parent;
  308.     }
  309.     /**
  310.      * @param string $path
  311.      * @return Term
  312.      */
  313.     public function setPath($path)
  314.     {
  315.         $this->path $path;
  316.         return $this;
  317.     }
  318.     /**
  319.      * @return string
  320.      */
  321.     public function getPath(): string
  322.     {
  323.         return $this->path;
  324.     }
  325.     /**
  326.      * Returns the name prepended by level to show hierarchy.
  327.      *
  328.      * @param string $levelCharacter
  329.      * @param string $label
  330.      * @return string
  331.      */
  332.     public function getHierarchyLabel($levelCharacter '--'$label 'name')
  333.     {
  334.         $labelFunc 'get'.ucfirst($label);
  335.         return str_repeat($levelCharacter$this->level) . ' ' $this->$labelFunc();
  336.     }
  337.     /**
  338.      * @return boolean
  339.      */
  340.     public function isEnabled():bool
  341.     {
  342.         return $this->enabled;
  343.     }
  344.     /**
  345.      * @param boolean $enabled
  346.      *
  347.      * @return Term
  348.      */
  349.     public function setEnabled($enabled)
  350.     {
  351.         $this->enabled = (bool)$enabled;
  352.         return $this;
  353.     }
  354.     /**
  355.      * Set slug
  356.      *
  357.      * @param string $slug
  358.      *
  359.      * @return Term
  360.      */
  361.     public function setSlug($slug)
  362.     {
  363.         $this->slug $slug;
  364.         return $this;
  365.     }
  366.     /**
  367.      * Get slug
  368.      *
  369.      * @return string
  370.      */
  371.     public function getSlug():string
  372.     {
  373.         return $this->slug;
  374.     }
  375.     /**
  376.      * Get enabled
  377.      *
  378.      * @return boolean
  379.      */
  380.     public function getEnabled()
  381.     {
  382.         return $this->enabled;
  383.     }
  384.     /**
  385.      * Add child
  386.      *
  387.      * @param \Boab\CmsBundle\Entity\Term $child
  388.      *
  389.      * @return Term
  390.      */
  391.     public function addChild(\Boab\CmsBundle\Entity\Term $child)
  392.     {
  393.         $this->children[] = $child;
  394.         return $this;
  395.     }
  396.     /**
  397.      * Remove child
  398.      *
  399.      * @param \Boab\CmsBundle\Entity\Term $child
  400.      */
  401.     public function removeChild(\Boab\CmsBundle\Entity\Term $child)
  402.     {
  403.         $this->children->removeElement($child);
  404.     }
  405.     /**
  406.      * Set route
  407.      *
  408.      * @param \Boab\CmsBundle\Entity\TermRoute $route
  409.      *
  410.      * @return Term
  411.      */
  412.     public function setRoute(\Boab\CmsBundle\Entity\TermRoute $route null)
  413.     {
  414.         $this->route $route;
  415.         return $this;
  416.     }
  417.     /**
  418.      * Get route
  419.      *
  420.      * @return \Boab\CmsBundle\Entity\TermRoute
  421.      */
  422.     public function getRoute(): TermRoute
  423.     {
  424.         return $this->route;
  425.     }
  426.     public function getTemplate(): ?string
  427.     {
  428.         return $this->template;
  429.     }
  430.     public function setTemplate(?string $template): self
  431.     {
  432.         $this->template $template;
  433.         return $this;
  434.     }
  435. }