<?php
namespace 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;
use Doctrine\Common\Collections\ArrayCollection;
use Cocur\Slugify\Slugify;
/**
* @ORM\Entity(repositoryClass="App\Repository\Content\RevisionRepository")
* @ORM\Table(name="content_revision")
* @ORM\HasLifecycleCallbacks()
*/
class Revision
{
/**
* @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="integer", length=5, nullable=false)
*/
private $version;
/**
* @ORM\Column(type="array", nullable=false)
*/
private $meta;
/**
* @ORM\Column(type="array", nullable=false)
*/
private $content;
/**
* @ORM\ManyToOne(targetEntity="Item", inversedBy="revisions")
* @ORM\JoinColumn(name="item_id", referencedColumnName="id")
**/
private $item;
/**
* @ORM\ManyToOne(targetEntity="\App\Entity\Users\User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
**/
private $user;
public function __construct($data = array())
{
// UUID
if(!$this->getUuid())
{
$uuid = Uuid::uuid1();
$this->setUuid($uuid->toString());
}
// Set some defaults
$this->setCreated(new \DateTime());
$this->setVersion(1);
$this->content = array();
$this->meta = 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->getCreated()->format('jS F, Y H:i a');
}
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 setVersion(int $version)
{
$this->version = $version;
}
public function getVersion()
{
return $this->version;
}
public function setContent($content = array())
{
$this->content = $content;
}
public function getContent()
{
return $this->content;
}
public function setMeta($meta = array())
{
$this->meta = $meta;
}
public function getMeta()
{
return $this->meta;
}
public function setItem(\App\Entity\Content\Item $item = null)
{
$this->item = $item;
if($item)
$item->addRevision($this);
}
public function getItem()
{
return $this->item;
}
public function setUser(\App\Entity\Users\User $user = null)
{
$this->user = $user;
}
public function getUser()
{
return $this->user;
}
}