vendor/kunstmaan/node-bundle/Entity/NodeVersion.php line 295

Open in your IDE?
  1. <?php
  2. namespace Kunstmaan\NodeBundle\Entity;
  3. use DateTime;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Kunstmaan\AdminBundle\Entity\AbstractEntity;
  7. use Kunstmaan\NodeBundle\Repository\NodeVersionRepository;
  8. use Kunstmaan\UtilitiesBundle\Helper\ClassLookup;
  9. /**
  10.  * @ORM\Entity(repositoryClass="Kunstmaan\NodeBundle\Repository\NodeVersionRepository")
  11.  * @ORM\Table(name="kuma_node_versions", indexes={@ORM\Index(name="idx_node_version_lookup", columns={"ref_id", "ref_entity_name"})})
  12.  * @ORM\HasLifecycleCallbacks()
  13.  * @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT")
  14.  */
  15. #[ORM\Entity(repositoryClassNodeVersionRepository::class)]
  16. #[ORM\Table(name'kuma_node_versions')]
  17. #[ORM\Index(name'idx_node_version_lookup'columns: ['ref_id''ref_entity_name'])]
  18. #[ORM\HasLifecycleCallbacks]
  19. #[ORM\ChangeTrackingPolicy('DEFERRED_EXPLICIT')]
  20. class NodeVersion extends AbstractEntity
  21. {
  22.     const DRAFT_VERSION 'draft';
  23.     const PUBLIC_VERSION 'public';
  24.     /**
  25.      * @var NodeTranslation
  26.      *
  27.      * @ORM\ManyToOne(targetEntity="NodeTranslation", inversedBy="nodeVersions")
  28.      * @ORM\JoinColumn(name="node_translation_id", referencedColumnName="id")
  29.      */
  30.     #[ORM\ManyToOne(targetEntityNodeTranslation::class, inversedBy'nodeVersions')]
  31.     #[ORM\JoinColumn(name'node_translation_id'referencedColumnName'id')]
  32.     protected $nodeTranslation;
  33.     /**
  34.      * @var string
  35.      *
  36.      * @ORM\Column(type="string")
  37.      */
  38.     #[ORM\Column(name'type'type'string')]
  39.     protected $type;
  40.     /**
  41.      * @var string
  42.      *
  43.      * @ORM\Column(type="string")
  44.      */
  45.     #[ORM\Column(name'owner'type'string')]
  46.     protected $owner;
  47.     /**
  48.      * @var \DateTime
  49.      *
  50.      * @ORM\Column(type="datetime")
  51.      */
  52.     #[ORM\Column(name'created'type'datetime')]
  53.     protected $created;
  54.     /**
  55.      * @var \DateTime
  56.      *
  57.      * @ORM\Column(type="datetime")
  58.      */
  59.     #[ORM\Column(name'updated'type'datetime')]
  60.     protected $updated;
  61.     /**
  62.      * @var int
  63.      *
  64.      * @ORM\Column(type="bigint", name="ref_id")
  65.      */
  66.     #[ORM\Column(name'ref_id'type'bigint')]
  67.     protected $refId;
  68.     /**
  69.      * @var string
  70.      *
  71.      * @ORM\Column(type="string", name="ref_entity_name")
  72.      */
  73.     #[ORM\Column(name'ref_entity_name'type'string')]
  74.     protected $refEntityName;
  75.     /**
  76.      * The nodeVersion this nodeVersion originated from
  77.      *
  78.      * @var NodeVersion
  79.      *
  80.      * @ORM\ManyToOne(targetEntity="NodeVersion")
  81.      * @ORM\JoinColumn(name="origin_id", referencedColumnName="id")
  82.      */
  83.     #[ORM\ManyToOne(targetEntityNodeVersion::class)]
  84.     #[ORM\JoinColumn(name'origin_id'referencedColumnName'id')]
  85.     protected $origin;
  86.     public function __construct()
  87.     {
  88.         $this->setCreated(new \DateTime());
  89.         $this->setUpdated(new \DateTime());
  90.     }
  91.     /**
  92.      * Set nodeTranslation
  93.      *
  94.      * @return NodeVersion
  95.      */
  96.     public function setNodeTranslation(NodeTranslation $nodeTranslation)
  97.     {
  98.         $this->nodeTranslation $nodeTranslation;
  99.         return $this;
  100.     }
  101.     /**
  102.      * Get NodeTranslation
  103.      *
  104.      * @return NodeTranslation
  105.      */
  106.     public function getNodeTranslation()
  107.     {
  108.         return $this->nodeTranslation;
  109.     }
  110.     /**
  111.      * Get type
  112.      *
  113.      * @return string
  114.      */
  115.     public function getType()
  116.     {
  117.         return $this->type;
  118.     }
  119.     public function isDraft()
  120.     {
  121.         return self::DRAFT_VERSION === $this->type;
  122.     }
  123.     public function isPublic()
  124.     {
  125.         return self::PUBLIC_VERSION === $this->type;
  126.     }
  127.     /**
  128.      * Set type
  129.      *
  130.      * @param string $type
  131.      *
  132.      * @return NodeVersion
  133.      */
  134.     public function setType($type)
  135.     {
  136.         $this->type $type;
  137.         return $this;
  138.     }
  139.     /**
  140.      * Set owner
  141.      *
  142.      * @param string $owner
  143.      *
  144.      * @return NodeVersion
  145.      */
  146.     public function setOwner($owner)
  147.     {
  148.         $this->owner $owner;
  149.         return $this;
  150.     }
  151.     /**
  152.      * Get owner
  153.      *
  154.      * @return string
  155.      */
  156.     public function getOwner()
  157.     {
  158.         return $this->owner;
  159.     }
  160.     /**
  161.      * Set created
  162.      *
  163.      * @return NodeVersion
  164.      */
  165.     public function setCreated(\DateTime $created)
  166.     {
  167.         $this->created $created;
  168.         return $this;
  169.     }
  170.     /**
  171.      * Get created
  172.      *
  173.      * @return \DateTime
  174.      */
  175.     public function getCreated()
  176.     {
  177.         return $this->created;
  178.     }
  179.     /**
  180.      * Set updated
  181.      *
  182.      * @return NodeVersion
  183.      */
  184.     public function setUpdated(\DateTime $updated)
  185.     {
  186.         $this->updated $updated;
  187.         return $this;
  188.     }
  189.     /**
  190.      * Get updated
  191.      *
  192.      * @return \DateTime
  193.      */
  194.     public function getUpdated()
  195.     {
  196.         return $this->updated;
  197.     }
  198.     /**
  199.      * Get refId
  200.      *
  201.      * @return int
  202.      */
  203.     public function getRefId()
  204.     {
  205.         return $this->refId;
  206.     }
  207.     /**
  208.      * Set refId
  209.      *
  210.      * @param int $refId
  211.      *
  212.      * @return NodeVersion
  213.      */
  214.     protected function setRefId($refId)
  215.     {
  216.         $this->refId $refId;
  217.         return $this;
  218.     }
  219.     /**
  220.      * Set reference entity name
  221.      *
  222.      * @param string $refEntityName
  223.      *
  224.      * @return NodeVersion
  225.      */
  226.     protected function setRefEntityName($refEntityName)
  227.     {
  228.         $this->refEntityName $refEntityName;
  229.         return $this;
  230.     }
  231.     /**
  232.      * Get reference entity name
  233.      *
  234.      * @return string
  235.      */
  236.     public function getRefEntityName()
  237.     {
  238.         return $this->refEntityName;
  239.     }
  240.     public function getDefaultAdminType()
  241.     {
  242.         return null;
  243.     }
  244.     /**
  245.      * @return NodeVersion
  246.      */
  247.     public function setRef(HasNodeInterface $entity)
  248.     {
  249.         $this->setRefId($entity->getId());
  250.         $this->setRefEntityName(ClassLookup::getClass($entity));
  251.         return $this;
  252.     }
  253.     /**
  254.      * @return HasNodeInterface
  255.      */
  256.     public function getRef(EntityManagerInterface $em)
  257.     {
  258.         return $em->getRepository($this->getRefEntityName())->find($this->getRefId());
  259.     }
  260.     /**
  261.      * @param NodeVersion $origin
  262.      *
  263.      * @return NodeVersion
  264.      */
  265.     public function setOrigin($origin)
  266.     {
  267.         $this->origin $origin;
  268.         return $this;
  269.     }
  270.     /**
  271.      * @return NodeVersion
  272.      */
  273.     public function getOrigin()
  274.     {
  275.         return $this->origin;
  276.     }
  277. }