src/Entity/Content/Type.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Content;
  3. use Symfony\Component\Validator\Constraints AS Constraints;
  4. use Symfony\Component\Validator\Constraints AS Assert;
  5. use Doctrine\ORM\Mapping AS ORM;
  6. use Ramsey\Uuid\Uuid;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. /**
  9.  * @ORM\Entity(repositoryClass="App\Repository\Content\TypeRepository")
  10.  * @ORM\Table(name="content_type")
  11.  * @ORM\HasLifecycleCallbacks()
  12.  */
  13. class Type
  14. {
  15.     /**
  16.     * @ORM\Id
  17.     * @ORM\GeneratedValue(strategy="AUTO")
  18.     * @ORM\Column(type="integer")
  19.     */
  20.     private $id;
  21.     /**
  22.      * @ORM\Column(type="uuid")
  23.      * @Assert\Uuid
  24.      */
  25.      protected $uuid;
  26.     /**
  27.      * @var \DateTime
  28.      *
  29.      * @ORM\Column(type="datetime", nullable=false)
  30.      */
  31.     private $created;
  32.     /**
  33.      * @ORM\Column(type="string", length=60, nullable=false)
  34.      */
  35.     private $name;
  36.     /**
  37.      * @ORM\Column(type="string", length=200, nullable=false)
  38.      */
  39.     private $slug;
  40.     
  41.     /**
  42.      * @ORM\Column(type="boolean", nullable=true)
  43.      */
  44.     private $isMultiLingual;
  45.     /**
  46.      * @ORM\OneToMany(targetEntity="Item", mappedBy="type", cascade={"all"})
  47.      **/
  48.     private $items;
  49.     
  50.     /**
  51.      * @ORM\ManyToOne(targetEntity="Item")
  52.      * @ORM\JoinColumn(name="forceparent_id", referencedColumnName="id")
  53.      **/
  54.     private $forcedParent;
  55.     public function __construct()
  56.     {
  57.         // UUID
  58.         if(!$this->getUuid())
  59.         {
  60.             $uuid Uuid::uuid1();
  61.             $this->setUuid($uuid->toString());
  62.         }
  63.         // Set some defaults
  64.         $this->setCreated(new \DateTime());
  65.         $this->items = new ArrayCollection();
  66.         
  67.         if($this->getIsMultiLingual())
  68.             $this->setIsMultiLingual(false);
  69.     }
  70.     public function __toString()
  71.     {
  72.         return $this->getName();
  73.     }
  74.     public function getId()
  75.     {
  76.         return $this->id;
  77.     }
  78.     public function setUuid($uuid)
  79.     {
  80.         $this->uuid $uuid;
  81.         return $this;
  82.     }
  83.     public function getUuid()
  84.     {
  85.         return $this->uuid;
  86.     }
  87.     public function setCreated(\DateTime $created)
  88.     {
  89.         $this->created $created;
  90.     }
  91.     public function getCreated()
  92.     {
  93.         return $this->created;
  94.     }
  95.     public function getName()
  96.     {
  97.         return $this->name;
  98.     }
  99.     public function setName(string $name)
  100.     {
  101.         $this->name $name;
  102.     }
  103.     public function getSlug()
  104.     {
  105.         return $this->slug;
  106.     }
  107.     public function setSlug(string $slug)
  108.     {
  109.         $this->slug $slug;
  110.     }
  111.     public function getIsMultiLingual()
  112.     {
  113.         return $this->isMultiLingual;
  114.     }
  115.     public function setIsMultiLingual($isMultiLingual)
  116.     {
  117.         $this->isMultiLingual $isMultiLingual;
  118.     }
  119.     public function getForcedParent()
  120.     {
  121.         return $this->forcedParent;
  122.     }
  123.     public function setForcedParent(\App\Entity\Content\Item $forcedParent null)
  124.     {
  125.         $this->forcedParent $forcedParent;
  126.     }
  127.     public function addItem(\App\Entity\Content\Item $item)
  128.     {
  129.         if(in_array($item$this->items->toArray()))
  130.             return true;
  131.         $this->items[] = $item;
  132.         $item->setType($this);
  133.         return $this;
  134.     }
  135.     public function removeItem(\App\Entity\Content\Item $item)
  136.     {
  137.         $this->items->removeElement($item);
  138.         $item->setType(null);
  139.     }
  140.     public function getItems()
  141.     {
  142.         return $this->items;
  143.     }
  144. }