src/Entity/Content/Revision.php line 16

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. use Cocur\Slugify\Slugify;
  9. /**
  10.  * @ORM\Entity(repositoryClass="App\Repository\Content\RevisionRepository")
  11.  * @ORM\Table(name="content_revision")
  12.  * @ORM\HasLifecycleCallbacks()
  13.  */
  14. class Revision
  15. {
  16.     /**
  17.     * @ORM\Id
  18.     * @ORM\GeneratedValue(strategy="AUTO")
  19.     * @ORM\Column(type="integer")
  20.     */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(type="uuid")
  24.      * @Assert\Uuid
  25.      */
  26.      protected $uuid;
  27.     /**
  28.      * @var \DateTime
  29.      *
  30.      * @ORM\Column(type="datetime", nullable=false)
  31.      */
  32.     private $created;
  33.     /**
  34.      * @ORM\Column(type="integer", length=5, nullable=false)
  35.      */
  36.     private $version;
  37.     /**
  38.      * @ORM\Column(type="array", nullable=false)
  39.      */
  40.     private $meta;
  41.     /**
  42.      * @ORM\Column(type="array", nullable=false)
  43.      */
  44.     private $content;
  45.     /**
  46.      * @ORM\ManyToOne(targetEntity="Item", inversedBy="revisions")
  47.      * @ORM\JoinColumn(name="item_id", referencedColumnName="id")
  48.      **/
  49.     private $item;
  50.     /**
  51.      * @ORM\ManyToOne(targetEntity="\App\Entity\Users\User")
  52.      * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
  53.      **/
  54.     private $user;
  55.     public function __construct($data = array())
  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->setVersion(1);
  66.         $this->content = array();
  67.         $this->meta = array();
  68.         // Setup with defaults
  69.         foreach($data AS $k => $v)
  70.         {
  71.             $setterName "set" ucfirst($k);
  72.             if(method_exists($this$setterName))
  73.                 $this->$setterName($v);
  74.         }
  75.     }
  76.     public function __toString()
  77.     {
  78.         return $this->getCreated()->format('jS F, Y H:i a');
  79.     }
  80.     public function getId()
  81.     {
  82.         return $this->id;
  83.     }
  84.     public function setUuid($uuid)
  85.     {
  86.         $this->uuid $uuid;
  87.         return $this;
  88.     }
  89.     public function getUuid()
  90.     {
  91.         return $this->uuid;
  92.     }
  93.     public function setCreated(\DateTime $created)
  94.     {
  95.         $this->created $created;
  96.     }
  97.     public function getCreated()
  98.     {
  99.         return $this->created;
  100.     }
  101.     public function setVersion(int $version)
  102.     {
  103.         $this->version $version;
  104.     }
  105.     public function getVersion()
  106.     {
  107.         return $this->version;
  108.     }
  109.     public function setContent($content = array())
  110.     {
  111.         $this->content $content;
  112.     }
  113.     public function getContent()
  114.     {
  115.         return $this->content;
  116.     }
  117.     public function setMeta($meta = array())
  118.     {
  119.         $this->meta $meta;
  120.     }
  121.     public function getMeta()
  122.     {
  123.         return $this->meta;
  124.     }
  125.     public function setItem(\App\Entity\Content\Item $item null)
  126.     {
  127.         $this->item $item;
  128.         if($item)
  129.             $item->addRevision($this);
  130.     }
  131.     public function getItem()
  132.     {
  133.         return $this->item;
  134.     }
  135.     public function setUser(\App\Entity\Users\User $user null)
  136.     {
  137.         $this->user $user;
  138.     }
  139.     public function getUser()
  140.     {
  141.         return $this->user;
  142.     }
  143. }