<?php
namespace Boab\CmsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Boab\CmsBundle\Entity\ParentableInterface;
use Boab\CmsBundle\Entity\Content;
use Boab\CmsBundle\Entity\StaffProfileTrait;
use Symfony\Cmf\Component\Routing\RouteReferrersInterface;
/**
* Page
* @ORM\Table(name="page")
* @ORM\Entity(repositoryClass="Boab\CmsBundle\Repository\ContentRepository")
*/
class Page extends Content implements PageInterface, ParentableInterface, RouteReferrersInterface
{
use StaffProfileTrait;
/**
* @var integer
*
* @ORM\Column(name="parent_id", type="string", length=40, precision=0, scale=0, nullable=true, unique=false)
*/
protected $parentId;
/**
* @var \Boab\CmsBundle\Entity\PageRoute
*
* @ORM\OneToOne(targetEntity="Boab\CmsBundle\Entity\PageRoute", fetch="EAGER", cascade={"persist","remove"}, orphanRemoval=true)
* @ORM\JoinColumn(name="route_id", referencedColumnName="id", nullable=true)
*
*/
protected $route;
/**
* Set parentId
*
* @param integer $parentId
*
* @return Page
*/
public function setParentId($parentId)
{
$this->parentId = $parentId;
return $this;
}
/**
* Get parentId
*
* @return integer
*/
public function getParentId()
{
if($this->parentId instanceof PageInterface){
return $this->parentId->getId();
}
return $this->parentId;
}
/**
* Set route
*
* @param \Boab\CmsBundle\Entity\PageRoute $route
*
* @return Page
*/
public function setRoute(\Boab\CmsBundle\Entity\PageRoute $route = null)
{
$this->route = $route;
return $this;
}
/**
* Get route
*
* @return \Boab\CmsBundle\Entity\PageRoute
*/
public function getRoute()
{
return $this->route;
}
public function addRoute($route)
{
}
public function removeRoute($route)
{
}
public function getRoutes():array
{
return [$this->getRoute()];
}
public function hasParent()
{
return $this->parentId == null;
}
public function hasRoute()
{
return $this->route == null ? false : true;
}
public function getRouteName()
{
if(!$this->hasRoute()){
return;
}
return $this->getRoute()->getRouteName();
}
}