/**
  * Return page ID
  *
  * @param void
  * @return Page
  */
 function getPage()
 {
     return Pages::findById($this->getPageId());
 }
 /**
  * Constructor
  *
  * @param Request $request
  * @return PagesController
  */
 function __construct($request)
 {
     parent::__construct($request);
     //echo $this->logged_user->getProjectPermission('page', $this->active_project);
     if ($this->logged_user->getProjectPermission('page', $this->active_project) < PROJECT_PERMISSION_ACCESS) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $section_url = pages_module_url($this->active_project);
     $this->wireframe->addBreadCrumb(lang('Pages'), $section_url);
     if ($this->active_category->isLoaded()) {
         $this->wireframe->addBreadCrumb($this->active_category->getName(), assemble_url('project_pages', array('project_id' => $this->active_project->getId(), 'category_id' => $this->active_category->getId())));
     }
     // if
     $page_id = $this->request->get('page_id');
     if ($page_id) {
         $this->active_page = Pages::findById($page_id);
     }
     // if
     if (instance_of($this->active_page, 'Page')) {
         $parents = array();
         $parent = $this->active_page->getParent();
         while (instance_of($parent, 'ProjectObject')) {
             if (instance_of($parent, 'Page')) {
                 if (array_key_exists($parent->getId(), $parents)) {
                     break;
                     // avoid dead loops
                 }
                 // if
                 $parents[$parent->getId()] = $parent;
                 $parent = $parent->getParent();
             } elseif (instance_of($parent, 'Category')) {
                 $parents[$parent->getId()] = $parent;
                 break;
             } else {
                 break;
             }
             // if
         }
         // while
         $parents = array_reverse($parents);
         foreach ($parents as $parent) {
             if (instance_of($parent, 'Page')) {
                 $this->wireframe->addBreadCrumb($parent->getName(), $parent->getViewUrl());
             } elseif (instance_of($parent, 'Category')) {
                 $this->wireframe->addBreadCrumb($parent->getName(), assemble_url('project_pages', array('project_id' => $this->active_project->getId(), 'category_id' => $parent->getId())));
             }
             // if
         }
         // foreach
         $this->wireframe->addBreadCrumb($this->active_page->getName(), $this->active_page->getViewUrl());
     } else {
         $this->active_page = new Page();
     }
     // if
     if (Page::canAdd($this->logged_user, $this->active_project)) {
         if ($this->active_page->isLoaded()) {
             $add_page_url = pages_module_add_page_url($this->active_project, array('parent' => $this->active_page));
         } elseif ($this->active_category->isLoaded()) {
             $add_page_url = pages_module_add_page_url($this->active_project, array('parent' => $this->active_category));
         } else {
             $add_page_url = pages_module_add_page_url($this->active_project);
         }
         // if
         $this->wireframe->addPageAction(lang('New Page'), $add_page_url);
     }
     // if
     $this->smarty->assign(array('active_page' => $this->active_page, 'pages_url' => $section_url, 'add_page_url' => $add_page_url, 'page_tab' => 'pages'));
 }