<?php
namespace Cms\ModuleBundle\Entity;
use App\Entity\Content\Common\DiscriminatorInterface;
use App\Entity\Content\Common\DiscriminatorTrait;
use Cms\ContainerBundle\Entity\Container;
use Cms\CoreBundle\Model\Interfaces\Lockable\LockableInterface;
use Cms\CoreBundle\Model\Interfaces\Lockable\LockableTrait;
use Cms\Modules\PageBundle\Entity\Page\PageProxy;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* Class Proxy
* @package Cms\ModuleBundle\Entity
*
* @ORM\MappedSuperclass
*/
abstract class Proxy extends ModuleEntity implements LockableInterface, DiscriminatorInterface
{
const DISCR = null;
const DISCRS = [
PageProxy::DISCR => PageProxy::class,
];
const ROUTING_SLUG = null;
use LockableTrait;
use DiscriminatorTrait;
/**
* @var Container
*
* @ORM\ManyToOne(targetEntity = "Cms\ContainerBundle\Entity\Container")
* @ORM\JoinColumn(name = "container", referencedColumnName = "id", onDelete = "CASCADE")
*/
protected $container = null;
/**
* @var ArrayCollection|History[]
*/
protected $histories;
/**
* @var History
*/
protected $history = null;
/**
* @var ArrayCollection|Draft[]
*/
protected $drafts;
/**
* @var Draft
*/
protected $draft;
/**
* @var bool
*
* @ORM\Column(
* type = "boolean",
* nullable = false,
* options = {
* "default" = false
* }
* )
*/
protected $placeholder = false;
/**
* Proxy constructor.
*/
public function __construct()
{
parent::__construct();
$this->histories = new ArrayCollection();
$this->drafts = new ArrayCollection();
}
/**
* @return bool
*/
public function isJumpable()
{
return ( ! $this->isPlaceholder());
}
/**
* @return Container
* @deprected
*/
public function getContainer()
{
return $this->container;
}
/**
* @return Container|null
*/
public function getDepartment(): ?Container
{
return $this->getContainer();
}
/**
* @return ArrayCollection|History[]
*/
public function getHistories()
{
return $this->histories;
}
/**
* @return History
*/
public function getHistory()
{
return $this->history;
}
/**
* @return ArrayCollection|Draft[]
*/
public function getDrafts()
{
return $this->drafts;
}
/**
* @return Draft
*/
public function getDraft()
{
return $this->draft;
}
/**
* @param Container $value
* @return $this
*/
public function setContainer(Container $value)
{
$this->container = $value;
return $this;
}
/**
* @param History|null $value
* @return $this
*/
public function setHistory(History $value = null)
{
$this->history = $value;
return $this;
}
/**
* @param Draft|null $value
* @return $this
*/
public function setDraft(Draft $value = null)
{
$this->draft = $value;
return $this;
}
/**
* @return bool
*/
public function isPlaceholder()
{
return ($this->placeholder === true);
}
/**
* @param bool $value
* @return $this
*/
public function setPlaceholder($value)
{
$this->placeholder = ($value === true);
return $this;
}
/**
* {@inheritdoc}
*/
public function getLockName()
{
$data = $this->getData();
switch (true) {
case $data->has('title'):
return $data->get('title');
case $data->has('name'):
return $data->get('name');
}
throw new \Exception();
}
}