<?phpnamespace App\Entity\Content;use Symfony\Component\Validator\Constraints AS Constraints;use Symfony\Component\Validator\Constraints AS Assert;use Doctrine\ORM\Mapping AS ORM;use Ramsey\Uuid\Uuid;/** * @ORM\Entity(repositoryClass="App\Repository\Content\BlockRepository") * @ORM\Table(name="content_block") * @ORM\HasLifecycleCallbacks() */class Block{ /** * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="uuid") * @Assert\Uuid */ protected $uuid; /** * @var \DateTime * * @ORM\Column(type="datetime", nullable=false) */ private $created; /** * @ORM\Column(type="string", length=60, nullable=false) */ private $blockName; /** * @ORM\Column(type="array", nullable=false) */ private $data; /** * @ORM\Column(type="array", nullable=false) */ private $restrictions; /** * @ORM\ManyToOne(targetEntity="Item", inversedBy="blocks") * @ORM\JoinColumn(name="item_id", referencedColumnName="id") **/ private $item; public function __construct($data = array()) { // UUID if(!$this->getUuid()) { $uuid = Uuid::uuid1(); $this->setUuid($uuid->toString()); } // Set some defaults $this->setCreated(new \DateTime()); $this->data = array(); $this->restrictions = array(); // Setup with defaults foreach($data AS $k => $v) { $setterName = "set" . ucfirst($k); if(method_exists($this, $setterName)) $this->$setterName($v); } } public function __toString() { return $this->getId(); } public function getId() { return $this->id; } public function setUuid($uuid) { $this->uuid = $uuid; return $this; } public function getUuid() { return $this->uuid; } public function setCreated(\DateTime $created) { $this->created = $created; } public function getCreated() { return $this->created; } public function getBlockName() { return $this->blockName; } public function setBlockName(string $blockName) { $this->blockName = $blockName; } public function setItem(\App\Entity\Content\Item $item = null) { $this->item = $item; if($item) $item->addBlock($this); } public function getItem() { return $this->item; } public function setData(array $data = array()) { $this->data = $data; } public function getData() { return $this->data; } public function setRestrictions(array $restrictions = array()) { $this->restrictions = $restrictions; } public function getRestrictions() { if(!$this->restrictions) $this->restrictions = array(); return $this->restrictions; }}