lib/boab/cms-bundle/src/Entity/Vocabulary.php line 18

Open in your IDE?
  1. <?php
  2. namespace Boab\CmsBundle\Entity;
  3. use Doctrine\Common\Collections\Collection;
  4. use Gedmo\Mapping\Annotation as Gedmo;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Doctrine\ORM\Event\PreUpdateEventArgs;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. /**
  9.  * Taxonomy vocabulary.
  10.  * @ORM\Entity 
  11.  * @ORM\HasLifecycleCallbacks() 
  12.  * @ORM\Table(name="taxonomy_vocabulary")
  13.  */
  14. class Vocabulary
  15. {
  16.    /**
  17.      * @var integer
  18.      *
  19.      * @ORM\Column(name="id", type="integer", precision=0, scale=0, nullable=false, unique=false)
  20.      * @ORM\Id
  21.      * @ORM\GeneratedValue(strategy="AUTO")
  22.      */
  23.     protected $id;
  24.     /**
  25.      * @var string
  26.      *
  27.      * @ORM\Column(name="human_label", length=255, type="string")
  28.      */
  29.     protected $label;
  30.     /**
  31.      * @var string
  32.      *
  33.      * @ORM\Column(name="name", length=255, type="string", unique=true)
  34.      */
  35.     protected $name;
  36.     /**
  37.      * @var string
  38.      *
  39.      * @ORM\Column(name="description", length=255, type="string")
  40.      */
  41.     protected $desc;
  42.     /**
  43.      * @var boolean
  44.      *
  45.      * @ORM\Column(name="is_orderable", type="boolean")
  46.      */
  47.     protected $orderable;
  48.     /**
  49.      * @var boolean
  50.      *
  51.      * @ORM\Column(name="weight", type="integer")
  52.      */
  53.     protected $weight;
  54.    /**
  55.      * @var \Doctrine\Common\Collections\Collection
  56.      *
  57.      * @ORM\OneToMany(targetEntity="Term", mappedBy="vocabulary", fetch="EXTRA_LAZY")
  58.      */
  59.     protected $terms;
  60.     /**
  61.      * @var \DateTime
  62.      *
  63.      * @ORM\Column(name="createdAt", type="datetime")
  64.      */
  65.     protected $createdAt;
  66.     /**
  67.      * @var \DateTime
  68.      *
  69.      * @ORM\Column(name="updatedAt", type="datetime", nullable=true)
  70.      */
  71.     protected $updatedAt;
  72.     /**
  73.      * @param array $data
  74.      */
  75.     public function __construct(array $data null)
  76.     {
  77.         $this->desc      '';
  78.         $this->weight    0;
  79.         $this->orderable true;
  80.         $this->createdAt = new \DateTime();
  81.         $this->terms = new ArrayCollection();
  82.     }
  83.     /**
  84.      * Convert object to string.
  85.      *
  86.      * @return string
  87.      */
  88.     public function __toString()
  89.     {
  90.         return $this->getLabel();
  91.     }
  92.     /**
  93.      * Doctrine lifecycle callback.
  94.      * @ORM\PreUpdate
  95.      * @param PreUpdateEventArgs $args
  96.      */
  97.     public function preUpdate(PreUpdateEventArgs $args)
  98.     {
  99.         if (!$args->hasChangedField('updatedAt')) {
  100.             $this->updatedAt = new \DateTime();
  101.         }
  102.     }
  103.     /**
  104.      * @param \DateTime $createdAt
  105.      *
  106. *@return Vocabulary
  107.      */
  108.     public function setCreatedAt(\DateTime $createdAt)
  109.     {
  110.         $this->createdAt $createdAt;
  111.         return $this;
  112.     }
  113.     /**
  114.      * @return \DateTime
  115.      */
  116.     public function getCreatedAt()
  117.     {
  118.         return $this->createdAt;
  119.     }
  120.     /**
  121.      * @param string $desc
  122.      * @return Vocabulary
  123.      */
  124.     public function setDesc($desc)
  125.     {
  126.         $this->desc $desc ?: '';
  127.         return $this;
  128.     }
  129.     /**
  130.      * @return string
  131.      */
  132.     public function getDesc()
  133.     {
  134.         return $this->desc;
  135.     }
  136.     /**
  137.      * @param string $id
  138.      * @return Vocabulary
  139.      */
  140.     public function setId($id)
  141.     {
  142.         $this->id $id;
  143.         return $this;
  144.     }
  145.     /**
  146.      * @return string
  147.      */
  148.     public function getId()
  149.     {
  150.         return $this->id;
  151.     }
  152.     /**
  153.      * @param string $name
  154.      * @return Vocabulary
  155.      */
  156.     public function setName($name null)
  157.     {
  158.         $name $name ?: $this->label;
  159.         if (preg_match('@[^a-z0-9_]+@'$name)) {
  160.             $name preg_replace('@[^a-z0-9_]+@''_'strtolower($name));
  161.         }
  162.         $this->name $name;
  163.         if (empty($this->label)) {
  164.             $this->label $name;
  165.         }
  166.         return $this;
  167.     }
  168.     /**
  169.      * @return string
  170.      */
  171.     public function getName()
  172.     {
  173.         return $this->name;
  174.     }
  175.     /**
  176.      * @param string $label
  177.      * @return Vocabulary
  178.      */
  179.     public function setLabel($label)
  180.     {
  181.         $this->label $label;
  182.         if (empty($this->name)) {
  183.             $this->setName();
  184.         }
  185.         return $this;
  186.     }
  187.     /**
  188.      * @return string
  189.      */
  190.     public function getLabel()
  191.     {
  192.         return $this->label;
  193.     }
  194.     /**
  195.      * @param ArrayCollection $terms
  196.      * @return Vocabulary
  197.      */
  198.     public function setTerms(ArrayCollection $terms null)
  199.     {
  200.         $this->terms $terms;
  201.         return $this;
  202.     }
  203.     /**
  204.      * @return ArrayCollection
  205.      */
  206.     public function getTerms()
  207.     {
  208.         return $this->terms;
  209.     }
  210.     /**
  211.      * @param \DateTime $updatedAt
  212.      *
  213. *@return Vocabulary
  214.      */
  215.     public function setUpdatedAt(\DateTime $updatedAt null)
  216.     {
  217.         $this->updatedAt $updatedAt;
  218.         return $this;
  219.     }
  220.     /**
  221.      * @return \DateTime
  222.      */
  223.     public function getUpdatedAt()
  224.     {
  225.         return $this->updatedAt;
  226.     }
  227.     /**
  228.      * @param int $weight
  229.      * @return Vocabulary
  230.      */
  231.     public function setWeight($weight)
  232.     {
  233.         $this->weight $weight;
  234.         return $this;
  235.     }
  236.     /**
  237.      * @return int
  238.      */
  239.     public function getWeight()
  240.     {
  241.         return $this->weight;
  242.     }
  243.     /**
  244.      * @return string
  245.      */
  246.     public function isOrderable()
  247.     {
  248.         return $this->orderable;
  249.     }
  250.     /**
  251.      * @param string $orderable
  252.      *
  253.      * @return Vocabulary
  254.      */
  255.     public function setOrderable($orderable)
  256.     {
  257.         $this->orderable = (bool)$orderable;
  258.         return $this;
  259.     }
  260.     public function getOrderable(): ?bool
  261.     {
  262.         return $this->orderable;
  263.     }
  264.     public function addTerm(Term $term): self
  265.     {
  266.         if (!$this->terms->contains($term)) {
  267.             $this->terms[] = $term;
  268.             $term->setVocabulary($this);
  269.         }
  270.         return $this;
  271.     }
  272.     public function removeTerm(Term $term): self
  273.     {
  274.         if ($this->terms->removeElement($term)) {
  275.             // set the owning side to null (unless already changed)
  276.             if ($term->getVocabulary() === $this) {
  277.                 $term->setVocabulary(null);
  278.             }
  279.         }
  280.         return $this;
  281.     }
  282. }