lib/boab/cms-bundle/src/Entity/Page.php line 16

Open in your IDE?
  1. <?php
  2. namespace Boab\CmsBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Boab\CmsBundle\Entity\ParentableInterface;
  5. use Boab\CmsBundle\Entity\Content;
  6. use Boab\CmsBundle\Entity\StaffProfileTrait;
  7. use Symfony\Cmf\Component\Routing\RouteReferrersInterface;
  8. use Symfony\Component\Routing\Route;
  9. /**
  10.  * Page
  11.  * @ORM\Table(name="page")
  12.  * @ORM\Entity(repositoryClass="Boab\CmsBundle\Repository\ContentRepository")
  13.  */
  14. class Page extends Content implements PageInterfaceParentableInterface
  15. {
  16.     use StaffProfileTrait;
  17.     /**
  18.      * @var integer
  19.      *
  20.      * @ORM\Column(name="parent_id", type="string", length=40, precision=0, scale=0, nullable=true, unique=false)
  21.      */
  22.     protected $parentId;
  23.     /**
  24.      * @var \Boab\CmsBundle\Entity\PageRoute
  25.      *
  26.      * @ORM\OneToOne(targetEntity="Boab\CmsBundle\Entity\PageRoute", fetch="EAGER", cascade={"persist","remove"}, orphanRemoval=true)
  27.      * @ORM\JoinColumn(name="route_id", referencedColumnName="id", nullable=true)
  28.      *
  29.      */
  30.     protected $route;
  31.     /**
  32.      * Set parentId
  33.      *
  34.      * @param integer $parentId
  35.      *
  36.      * @return Page
  37.      */
  38.     public function setParentId($parentId)
  39.     {
  40.         $this->parentId $parentId;
  41.         return $this;
  42.     }
  43.     /**
  44.      * Get parentId
  45.      *
  46.      * @return integer
  47.      */
  48.     public function getParentId()
  49.     {
  50.         if($this->parentId instanceof PageInterface){
  51.             return $this->parentId->getId();
  52.         }
  53.         return $this->parentId;
  54.     }
  55.     /**
  56.      * Set route
  57.      *
  58.      * @param \Boab\CmsBundle\Entity\PageRoute $route
  59.      *
  60.      * @return Page
  61.      */
  62.     public function setRoute(\Boab\CmsBundle\Entity\PageRoute $route null)
  63.     {
  64.         $this->route $route;
  65.         return $this;
  66.     }
  67.     /**
  68.      * Get route
  69.      *
  70.      * @return \Boab\CmsBundle\Entity\PageRoute
  71.      */
  72.     public function getRoute(): ?PageRoute
  73.     {
  74.         return $this->route;
  75.     }
  76.     public function hasParent()
  77.     {
  78.         return $this->parentId == null;
  79.     }
  80.     public function hasRoute()
  81.     {
  82.         return $this->route == null false true;
  83.     }
  84.     public function getRouteName()
  85.     {
  86.         if(!$this->hasRoute()){
  87.             return;
  88.         }
  89.         return $this->getRoute()->getRouteName();
  90.     }
  91. }