/** * Render content from database layout. * * @param string $pageType Page type. * @param string $layout Use layout to render. * * @throws \Engine\Exception * @return mixed */ public function renderContent($pageType, $layout = null) { $content = ''; $page = Page::findFirst(['conditions' => 'type=:type:', 'bind' => ["type" => $pageType], 'bindTypes' => ["type" => Column::BIND_PARAM_STR]]); if (!$page) { throw new Exception("Page with type '{$pageType}' not found."); } $widgets = $page->getWidgets(); /** * Plain render widgets. */ if (!$layout) { foreach ($widgets as $widget) { $content .= $this->renderWidgetId($widget->widget_id, $widget->getParams()); } return $content; } // Resort content by sides. $content = []; foreach ($widgets as $widget) { $content[$widget->layout][] = $this->renderWidgetId($widget->widget_id, $widget->getParams()); } /** @var \Phalcon\Mvc\View $view */ $view = $this->getDI()->get('view'); $view->disableLevel(View::LEVEL_LAYOUT); $view->disableLevel(View::LEVEL_MAIN_LAYOUT); $view->content = $content; $view->page = $page; $view->pick($layout); $view->getRender(null, null); return $view->getContent(); }
/** * Edit menu item. * * @param int $id Menu item identity. * * @return void|ResponseInterface * * @Route("/edit-item/{id:[0-9]+}", methods={"GET", "POST"}, name="admin-menus-edit-item") */ public function editItemAction($id) { $item = MenuItem::findFirst($id); $form = new EditItem($item); $this->view->form = $form; $data = ['menu_id' => $this->request->get('menu_id'), 'parent_id' => $this->request->get('parent_id'), 'url_type' => $item->page_id == null ? 0 : 1]; if ($item->page_id) { $page = Page::findFirst($item->page_id); if ($page) { $data['page_id'] = $page->id; $data['page'] = $page->title; } } $form->setValues($data); if (!$this->request->isPost() || !$form->isValid()) { return; } $item = $form->getEntity(); // Clear url type. if ($form->getValue('url_type') == 0) { $item->pageId = null; } else { $item->url = null; } $item->save(); $this->_clearMenuCache(); $this->resolveModal(['reload' => true]); }
/** * Render some content from database layout. * * @param null|string $url Url definition of page. * @param null|string $controller Related controller name. * @param null|string $type Page type. * * @return mixed */ public function renderContent($url = null, $controller = null, $type = null) { $page = null; if ($url !== null) { $page = Page::find(['conditions' => 'url=:url1: OR url=:url2: OR id = :url3:', 'bind' => ["url1" => $url, "url2" => '/' . $url, "url3" => $url], 'bindTypes' => ["url1" => Column::BIND_PARAM_STR, "url2" => Column::BIND_PARAM_STR, "url3" => Column::BIND_PARAM_INT]])->getFirst(); } elseif ($controller !== null) { $page = Page::find(['conditions' => 'controller=:controller:', 'bind' => ["controller" => $controller], 'bindTypes' => ["controller" => Column::BIND_PARAM_STR]])->getFirst(); } elseif ($type !== null) { $page = Page::find(['conditions' => 'type=:type:', 'bind' => ["type" => $type], 'bindTypes' => ["type" => Column::BIND_PARAM_STR]])->getFirst(); } if (!$page || !$page->isAllowed()) { return $this->dispatcher->forward(['controller' => 'Error', 'action' => 'show404']); } // Resort content by sides. $content = []; $renderer = Renderer::getInstance($this->getDI()); foreach ($page->getWidgets() as $widget) { $content[$widget->layout][] = $renderer->renderWidgetId($widget->widget_id, $widget->getParams()); } $this->view->content = $content; $this->view->page = $page; $this->view->pick('layouts/page'); }
/** * Suggest page. * * @return void * * @Route("/suggest", methods={"GET"}, name="admin-pages-suggest") */ public function suggestAction() { $this->view->disable(); $query = $this->request->get('query'); if (empty($query)) { $this->response->setContent('[]')->send(); return; } $results = Page::find(["conditions" => "title LIKE ?1", "bind" => [1 => '%' . $query . '%']]); $data = []; foreach ($results as $result) { $data[] = ['id' => $result->id, 'label' => $result->title]; } $this->response->setContent(json_encode($data))->send(); }