src/Entity/Content/Block.php line 14

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. /**
  8.  * @ORM\Entity(repositoryClass="App\Repository\Content\BlockRepository")
  9.  * @ORM\Table(name="content_block")
  10.  * @ORM\HasLifecycleCallbacks()
  11.  */
  12. class Block
  13. {
  14.     /**
  15.     * @ORM\Id
  16.     * @ORM\GeneratedValue(strategy="AUTO")
  17.     * @ORM\Column(type="integer")
  18.     */
  19.     private $id;
  20.     /**
  21.      * @ORM\Column(type="uuid")
  22.      * @Assert\Uuid
  23.      */
  24.      protected $uuid;
  25.     /**
  26.      * @var \DateTime
  27.      *
  28.      * @ORM\Column(type="datetime", nullable=false)
  29.      */
  30.     private $created;
  31.     /**
  32.      * @ORM\Column(type="string", length=60, nullable=false)
  33.      */
  34.     private $blockName;
  35.     /**
  36.      * @ORM\Column(type="array", nullable=false)
  37.      */
  38.     private $data;
  39.     /**
  40.      * @ORM\Column(type="array", nullable=false)
  41.      */
  42.     private $restrictions;
  43.     /**
  44.      * @ORM\ManyToOne(targetEntity="Item", inversedBy="blocks")
  45.      * @ORM\JoinColumn(name="item_id", referencedColumnName="id")
  46.      **/
  47.     private $item;
  48.     public function __construct($data = array())
  49.     {
  50.         // UUID
  51.         if(!$this->getUuid())
  52.         {
  53.             $uuid Uuid::uuid1();
  54.             $this->setUuid($uuid->toString());
  55.         }
  56.         // Set some defaults
  57.         $this->setCreated(new \DateTime());
  58.         $this->data = array();
  59.         $this->restrictions = array();
  60.         // Setup with defaults
  61.         foreach($data AS $k => $v)
  62.         {
  63.             $setterName "set" ucfirst($k);
  64.             if(method_exists($this$setterName))
  65.                 $this->$setterName($v);
  66.         }
  67.     }
  68.     public function __toString()
  69.     {
  70.         return $this->getId();
  71.     }
  72.     public function getId()
  73.     {
  74.         return $this->id;
  75.     }
  76.     public function setUuid($uuid)
  77.     {
  78.         $this->uuid $uuid;
  79.         return $this;
  80.     }
  81.     public function getUuid()
  82.     {
  83.         return $this->uuid;
  84.     }
  85.     public function setCreated(\DateTime $created)
  86.     {
  87.         $this->created $created;
  88.     }
  89.     public function getCreated()
  90.     {
  91.         return $this->created;
  92.     }
  93.     public function getBlockName()
  94.     {
  95.         return $this->blockName;
  96.     }
  97.     public function setBlockName(string $blockName)
  98.     {
  99.         $this->blockName $blockName;
  100.     }
  101.     
  102.     public function setItem(\App\Entity\Content\Item $item null)
  103.     {
  104.         $this->item $item;
  105.         if($item)
  106.             $item->addBlock($this);
  107.     }
  108.     public function getItem()
  109.     {
  110.         return $this->item;
  111.     }
  112.     public function setData(array $data = array())
  113.     {
  114.         $this->data $data;
  115.     }
  116.     public function getData()
  117.     {
  118.         return $this->data;
  119.     }
  120.     public function setRestrictions(array $restrictions = array())
  121.     {
  122.         $this->restrictions $restrictions;
  123.     }
  124.     public function getRestrictions()
  125.     {
  126.         if(!$this->restrictions)
  127.             $this->restrictions = array();
  128.         return $this->restrictions;
  129.     }
  130. }