Skip to content

Instantly share code, notes, and snippets.

@janit
Last active February 28, 2016 09:51
Show Gist options
  • Save janit/2a7e882be4d00967b139 to your computer and use it in GitHub Desktop.
Save janit/2a7e882be4d00967b139 to your computer and use it in GitHub Desktop.
<?php
/**
* Displays the list of blog_post.
*
* @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function listBlogPostsAction(ContentView $view, Request $request)
{
$location = $view->getLocation();
$languages = $this->configResolver->getParameter('languages');
$query = new Query();
$query->query = $this->childrenCriteria->generateChildCriterion($location, $languages);
$query->sortClauses = [
new SortClause\Field('blog_post', 'publication_date', Query::SORT_DESC, $languages[0]),
];
$pager = new Pagerfanta(
new ContentSearchAdapter($query, $this->searchService)
);
$pager->setMaxPerPage($this->blogPostLimit);
$pager->setCurrentPage($request->get('page', 1));
$view->addParameters([
'location' => $location,
'content' => $this->contentService->loadContentByContentInfo($view->getLocation()->getContentInfo()),
'blogPosts' => $pager,
]);
return $view;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment