<?php
namespace Boab\CmsBundle\Entity;
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 vocabulary.
* @ORM\Entity
* @ORM\HasLifecycleCallbacks()
* @ORM\Table(name="taxonomy_vocabulary")
*/
class Vocabulary
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", precision=0, scale=0, nullable=false, unique=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="human_label", length=255, type="string")
*/
protected $label;
/**
* @var string
*
* @ORM\Column(name="name", length=255, type="string", unique=true)
*/
protected $name;
/**
* @var string
*
* @ORM\Column(name="description", length=255, type="string")
*/
protected $desc;
/**
* @var boolean
*
* @ORM\Column(name="is_orderable", type="boolean")
*/
protected $orderable;
/**
* @var boolean
*
* @ORM\Column(name="weight", type="integer")
*/
protected $weight;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\OneToMany(targetEntity="Term", mappedBy="vocabulary", fetch="EXTRA_LAZY")
*/
protected $terms;
/**
* @var \DateTime
*
* @ORM\Column(name="createdAt", type="datetime")
*/
protected $createdAt;
/**
* @var \DateTime
*
* @ORM\Column(name="updatedAt", type="datetime", nullable=true)
*/
protected $updatedAt;
/**
* @param array $data
*/
public function __construct(array $data = null)
{
$this->desc = '';
$this->weight = 0;
$this->orderable = true;
$this->createdAt = new \DateTime();
$this->terms = new ArrayCollection();
}
/**
* Convert object to string.
*
* @return string
*/
public function __toString()
{
return $this->getLabel();
}
/**
* 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 Vocabulary
*/
public function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* @param string $desc
* @return Vocabulary
*/
public function setDesc($desc)
{
$this->desc = $desc ?: '';
return $this;
}
/**
* @return string
*/
public function getDesc()
{
return $this->desc;
}
/**
* @param string $id
* @return Vocabulary
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* @param string $name
* @return Vocabulary
*/
public function setName($name = null)
{
$name = $name ?: $this->label;
if (preg_match('@[^a-z0-9_]+@', $name)) {
$name = preg_replace('@[^a-z0-9_]+@', '_', strtolower($name));
}
$this->name = $name;
if (empty($this->label)) {
$this->label = $name;
}
return $this;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $label
* @return Vocabulary
*/
public function setLabel($label)
{
$this->label = $label;
if (empty($this->name)) {
$this->setName();
}
return $this;
}
/**
* @return string
*/
public function getLabel()
{
return $this->label;
}
/**
* @param ArrayCollection $terms
* @return Vocabulary
*/
public function setTerms(ArrayCollection $terms = null)
{
$this->terms = $terms;
return $this;
}
/**
* @return ArrayCollection
*/
public function getTerms()
{
return $this->terms;
}
/**
* @param \DateTime $updatedAt
*
*@return Vocabulary
*/
public function setUpdatedAt(\DateTime $updatedAt = null)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* @param int $weight
* @return Vocabulary
*/
public function setWeight($weight)
{
$this->weight = $weight;
return $this;
}
/**
* @return int
*/
public function getWeight()
{
return $this->weight;
}
/**
* @return string
*/
public function isOrderable()
{
return $this->orderable;
}
/**
* @param string $orderable
*
* @return Vocabulary
*/
public function setOrderable($orderable)
{
$this->orderable = (bool)$orderable;
return $this;
}
public function getOrderable(): ?bool
{
return $this->orderable;
}
public function addTerm(Term $term): self
{
if (!$this->terms->contains($term)) {
$this->terms[] = $term;
$term->setVocabulary($this);
}
return $this;
}
public function removeTerm(Term $term): self
{
if ($this->terms->removeElement($term)) {
// set the owning side to null (unless already changed)
if ($term->getVocabulary() === $this) {
$term->setVocabulary(null);
}
}
return $this;
}
}