getPage() публичный Метод

Returns a super fast cached Page object.
public getPage ( Node | string | integer $node ) : Node | null
$node Jarves\Model\Node | string | integer Node model, url or node id
Результат Jarves\Model\Node | null
Пример #1
0
 /**
  * @param array $options
  *
  * @return null|Model\Node
  *
  * @throws Exceptions\BundleNotFoundException
  * @throws \Exception
  */
 public function get($options)
 {
     $options['id'] = isset($options['id']) ? $options['id'] : false;
     $options['level'] = isset($options['level']) ? $options['level'] : false;
     //        $withFolders = (isset($options['folders']) && $options['folders'] == 1) ? true : false;
     $navigation = false;
     if (!$navigation && $options['id'] != 'breadcrumb' && ($options['id'] || $options['level'])) {
         if ($options['id'] + 0 > 0) {
             $navigation = $this->pageStack->getPage($options['id'] + 0);
             if (!$navigation) {
                 return null;
             }
         }
         if ($options['level'] > 1) {
             $currentPage = $this->pageStack->getCurrentPage();
             $parents = $currentPage->getParents();
             $parents[] = $currentPage;
             $currentLevel = count($parents) + 1;
             $page = $this->arrayLevel($parents, $options['level']);
             if ($page && $page->getId() > 0) {
                 $navigation = $this->pageStack->getPage($page->getId());
             } elseif ($options['level'] == $currentLevel + 1) {
                 $navigation = $this->pageStack->getCurrentPage();
             }
         }
         if ($options['level'] == 1) {
             $navigation = NodeQuery::create()->findRoot($this->pageStack->getCurrentDomain()->getId());
         }
     }
     return $navigation;
 }
Пример #2
0
 /**
  * @param Node|string|int $page Node model, url or node id. Use Jarves\Model\Node::createPage()
  * @param string|array|null $contents
  *
  * @return PageResponse
  */
 public function createFromPage($page, $contents = null)
 {
     $page = $this->pageStack->getPage($page);
     if (!$page) {
         throw new \InvalidArgumentException('Can not find page.');
     }
     $this->pageStack->setCurrentPage($page);
     $pageResponse = new PageResponse('', 200, [], $this->pageStack, $this->jarves, $this->stopwatch, $this->assetCompilerContainer, $this->eventDispatcher, $this->templating, $this->editMode);
     $this->pageStack->setPageResponse($pageResponse);
     if (null !== $contents) {
         $pageResponse->setPageContent($contents);
     }
     return $pageResponse;
 }
Пример #3
0
 /**
  * Returns the id of given path-info. Null if not existent.
  *
  * @return Node|null
  */
 public function searchPage()
 {
     $url = $this->getRequest()->getPathInfo();
     $page = null;
     $title = sprintf('Searching Page [%s]', $url);
     $this->stopwatch->start($title);
     if (!$page) {
         $domain = $this->pageStack->getCurrentDomain();
         $urls = $this->pageStack->getCachedUrlToPage($domain->getId());
         $possibleUrl = $url;
         $id = false;
         while (1) {
             if (isset($urls[$possibleUrl])) {
                 $id = $urls[$possibleUrl];
                 break;
             }
             if (false !== ($pos = strrpos($possibleUrl, '/'))) {
                 $possibleUrl = substr($possibleUrl, 0, $pos);
             } else {
                 break;
             }
         }
         if (!$id) {
             //set to startpage
             $id = $domain->getStartnodeId();
             $possibleUrl = '/';
         }
         $url = $possibleUrl;
         if ($url == '/') {
             $pageId = $this->pageStack->getCurrentDomain()->getStartnodeId();
             if (!$pageId > 0) {
                 $this->eventDispatcher->dispatch('core/domain-no-start-page');
             }
         } else {
             $pageId = $id;
         }
         /** @var \Jarves\Model\Node $page */
         $page = $this->pageStack->getPage($pageId);
     }
     $this->stopwatch->stop($title);
     return $page;
 }
Пример #4
0
 /**
  * @ApiDoc(
  *  section="Administration",
  *  description="Returns a renderer content element as preview for Jarves page editor"
  * )
  *
  * @Rest\QueryParam(name="template", requirements=".+", strict=true,
  *      description="The template/view to be used for this content")
  *
  * @Rest\QueryParam(name="type", requirements=".+", strict=true, description="The content type")
  *
  * @Rest\QueryParam(name="nodeId", requirements="[0-9]+",
  *      description="The node id in which context this content should be rendered")
  * @Rest\QueryParam(name="domainId", requirements="[0-9]+",
  *      description="The domain id in which context this content should be rendered")
  * @Rest\RequestParam(name="content", requirements=".*", description="The actual content")
  *
  * @Rest\Post("/admin/content/preview")
  *
  * @param ParamFetcher $paramFetcher
  *
  * @return array
  */
 public function getContentPreviewAction(ParamFetcher $paramFetcher)
 {
     $template = $paramFetcher->get('template');
     $type = $paramFetcher->get('type');
     $content = $paramFetcher->get('content');
     $nodeId = $paramFetcher->get('nodeId');
     $domainId = $paramFetcher->get('domainId');
     //todo, check if $template is defined as content template
     $contentObject = new Content();
     $contentObject->setType($type);
     $contentObject->setTemplate($template);
     $contentObject->setContent($content);
     if ($domainId) {
         $domain = $this->pageStack->getDomain($domainId);
         $this->pageStack->setCurrentDomain($domain);
     }
     if ($nodeId) {
         $page = $this->pageStack->getPage($nodeId);
         $this->pageStack->setCurrentPage($page);
     }
     return $this->contentRender->renderContent($contentObject, ['preview' => true]);
 }
Пример #5
0
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
         //we need to reset all routes. They will anyway replaced by FrontendRouter::loadRoutes,
         //but to prevent caching conflicts, when a user removes a plugin for example
         //from a page, we need to know that without using actual caching.
         $this->routes = new RouteCollection();
         $this->urlMatcher->__construct($this->routes, $this->requestContext);
         //prepare for new master request: clear the PageResponse object
         $this->pageStack->setCurrentPage(null);
         $this->pageStack->setCurrentDomain(null);
         $this->pageStack->setPageResponse($this->pageResponseFactory->create());
         $this->frontendRouter->setRequest($request);
         $editorNodeId = (int) $this->pageStack->getRequest()->get('_jarves_editor_node');
         $editorDomainId = (int) $this->pageStack->getRequest()->get('_jarves_editor_domain');
         $domain = null;
         if ($editorDomainId) {
             $domain = $this->pageStack->getDomain($editorDomainId);
             if (!$domain) {
                 //we haven't found any domain that is responsible for this request
                 return;
             }
             $this->pageStack->setCurrentDomain($domain);
         }
         if ($editorNodeId) {
             //handle jarves content editor stuff
             //access is later checked
             if (!$editorNodeId && $domain) {
                 $editorNodeId = $domain->getStartnodeId();
             }
             $page = $this->pageStack->getPage($editorNodeId);
             if (!$page || !$page->isRenderable()) {
                 //we haven't found any page that is responsible for this request
                 return;
             }
             if (!$domain) {
                 $domain = $this->pageStack->getDomain($page->getDomainId());
             }
             $this->pageStack->setCurrentPage($page);
             $this->pageStack->setCurrentDomain($domain);
             $request->attributes->set('_controller', 'jarves.page_controller:handleAction');
         } else {
             //regular frontend route search
             //search domain
             if (!$domain) {
                 $domain = $this->frontendRouter->searchDomain();
                 if (!$domain) {
                     //we haven't found any domain that is responsible for this request
                     return;
                 }
                 $this->pageStack->setCurrentDomain($domain);
             }
             //search page
             $page = $this->frontendRouter->searchPage();
             if (!$page || !$page->isRenderable()) {
                 //we haven't found any page that is responsible for this request
                 return;
             }
             $this->pageStack->setCurrentPage($page);
             if ($response = $this->frontendRouter->loadRoutes($this->routes, $page)) {
                 //loadRoutes return in case of redirects and permissions a redirect or 404 response.
                 $event->setResponse($response);
                 return;
             }
             try {
                 //check routes in $this->route
                 parent::onKernelRequest($event);
             } catch (MethodNotAllowedException $e) {
             } catch (NotFoundHttpException $e) {
             }
         }
     }
 }