<?php
namespace Boab\CmsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Cmf\Bundle\RoutingBundle\Model\Route as BaseRoute;
/**
* @ORM\Entity (repositoryClass="Boab\CmsBundle\Repository\RouteRepository")
* @ORM\Table(name="route")
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="route_type", type="string")
* @ORM\DiscriminatorMap({
"list"="ListRoute",
"post"="PostRoute",
"page"="PageRoute",
"taxon"="TermRoute",
"url"="UrlRoute"
})
*/
abstract class Route extends BaseRoute implements RouteInterface
{
const VISIBILITY_OFF = 0;
const VISIBILITY_ON = 1;
const ROUTE_PREFIX = 'route_';
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", precision=0, scale=0, nullable=false, unique=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=255, precision=0, scale=0, nullable=false, unique=false)
*/
protected $title;
/**
* @var string
*
* @ORM\Column(name="slug", type="string", length=255, precision=0, scale=0, nullable=false, unique=false)
*/
protected $slug;
/**
* @var string
*
* @ORM\Column(name="path", type="string", length=255, precision=0, scale=0, nullable=false, unique=false)
*/
protected $path;
/**
* @var integer
*
* @ORM\Column(name="position", type="integer", precision=0, scale=0, nullable=true, unique=false)
*/
protected $position;
/**
* @var \DateTime
*
* @ORM\Column(name="date_created", type="datetime", precision=0, scale=0, nullable=false, unique=false)
*/
protected $dateCreated;
/**
* @var integer
*
* @ORM\Column(name="visibility", type="boolean")
*/
protected $visibility;
/**
* @var integer
*
* @ORM\Column(name="parent_id", type="integer", precision=0, scale=0, nullable=true, unique=false)
*/
protected $parentId;
/**
* @var string
*
* @ORM\Column(name="route_name", type="string", length=255, precision=0, scale=0, nullable=true, unique=true)
*/
protected $routeName;
/**
* @var string
*
* @ORM\Column(name="template", type="string", length=255, precision=0, scale=0, nullable=true, unique=false)
*/
protected $template;
/**
* @var integer
*
* @ORM\Column(name="layout_type", type="integer", length=2, precision=0, scale=0, nullable=true, unique=false)
*/
protected $layoutType;
/**
* use for parent child heirracy
*/
protected $children = [] ;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* @param string $title
* @return Menu
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle(): ?string
{
return $this->title;
}
/**
* Set path
*
* @param string $path
* @return Menu
*/
public function setPath($path)
{
$this->path = $path;
return $this;
}
/**
* Get path
*
* @return string
*/
public function getPath()
{
return $this->path;
}
/**
* Set slug
*
* @param string $slug
* @return Menu
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* Get slug
*
* @return string
*/
public function getSlug()
{
return $this->slug;
}
/**
* Set position
*
* @param integer $position
* @return Menu
*/
public function setPosition($position)
{
$this->position = $position;
return $this;
}
/**
* Get position
*
* @return integer
*/
public function getPosition()
{
return $this->position;
}
/**
* Set dateCreated
*
* @param \DateTime $dateCreated
* @return Menu
*/
public function setDateCreated($dateCreated)
{
$this->dateCreated = $dateCreated;
return $this;
}
/**
* Get dateCreated
*
* @return \DateTime
*/
public function getDateCreated()
{
return $this->dateCreated;
}
/**
* Set visibility
*
* @param integer $visibility
* @return Menu
*/
public function setVisibility($visibility)
{
$this->visibility = $visibility;
return $this;
}
/**
* Get visibility
*
* @return integer
*/
public function getVisibility()
{
return $this->visibility;
}
public function isVisible()
{
return (bool)$this->getVisibility();
}
/**
* Set routeName
*
* @param string $routeName
* @return Menu
*/
public function setRouteName($routeName)
{
$this->routeName = $routeName;
return $this;
}
/**
* Get routeName
*
* @return string
*/
public function getRouteName():string
{
return (!$this->routeName) ? sprintf('%s%s',self::ROUTE_PREFIX, $this->getId()) : $this->routeName;
}
/**
* Set template
*
* @param string $template
*
* @return UrlRoute
*/
public function setTemplate($template)
{
$this->template = $template;
return $this;
}
/**
* Get template
*
* @return string
*/
public function getTemplate()
{
return $this->template;
}
/**
* Set parentId
*
* @param integer $parentId
*
* @return Route
*/
public function setParentId($parent)
{
$this->parentId = is_object($parent) ? $parent->getId() : $parent;
return $this;
}
/**
* Get parentId
*
* @return integer
*/
public function getParentId()
{
return $this->parentId;
}
/**
* Set layoutType
*
* @param integer $layoutType
*
* @return Route
*/
public function setLayoutType($layoutType)
{
$this->layoutType = $layoutType;
return $this;
}
/**
* Get layoutType
*
* @return integer
*/
public function getLayoutType():string
{
return $this->layoutType;
}
public function setDefaults( array $defauts=[])
{
$defauts = [
'_title' => $this->getTitle(),
'_template'=> $this->getTemplate(),
'_controller'=>$this->getController(),
];
parent::setDefaults($defauts);
}
public function getRouteKey():?string
{
return $this->getRouteName();
}
public function hasParent()
{
return $this->parentId == null;
}
public function isParent()
{
return 0 == $this->getParentId();
}
public function hasParentSelected()
{
return (bool)$this->getParentId();
}
public function setChildren($children)
{
$this->children = $children;
}
public function getChildren()
{
return $this->children;
}
}