public function pages_list($request) { // Delete page if ($request->get('delete')) { $page = \Page::find_by_id(intval($request->get('delete'))); if ($page && $page->delete()) { $this->view->assign('message', $this->lang->translate('form.deleted')); } } // Filter $filter = []; if ($request->get('author')) { $author = \User::find($request->get('author')); if ($author) { $filter['conditions'] = ['author_id = ?', $author->id]; } } $filter['order'] = 'id DESC'; if ($request->order) { $filter['order'] = $request->order; } /** @var Listing $paginator */ $paginator = NCService::load('Paginator.Listing', [$request->page, \Page::count('all')]); $filter = array_merge($filter, $paginator->limit()); // Filter users $pages = \Page::all($filter); $pages = array_map(function ($i) { return $i->to_array(); }, $pages); return $this->view->render('pages/list.twig', ['title' => $this->lang->translate('page.list'), 'pages_list' => $pages, 'listing' => $paginator->pages(), 'page' => $paginator->cur_page]); }
static function globalize($module, $theme, $translate) { /* * Add all pages to context */ $pages = function () { return array_map(function ($p) { $page = $p->to_array(); $page['url'] = '/page/' . $page['id'] . '-' . $page['slug'] . '.html'; return $page; }, \Page::all()); }; /* * Short description filter */ $theme->twig->addFilter(new \Twig_SimpleFilter('short', function ($value) { $short_tag = '<!-- split -->'; if (strpos($value, $short_tag) > 0) { return reset(explode($short_tag, $value, 2)); } return $value; })); return ['_pages' => lazy_arr('pages', ['$list' => $pages])]; }