/**
  * Displays the gallery.
  *
  * @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view
  * @param \Symfony\Component\HttpFoundation\Request $request
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function displayGalleryAction(ContentView $view, Request $request)
 {
     $languages = $this->configResolver->getParameter('languages');
     $location = $view->getLocation();
     $query = new Query();
     $query->query = $this->childrenCriteria->generateChildCriterion($location, $languages);
     $pager = new Pagerfanta(new ContentSearchAdapter($query, $this->searchService));
     $pager->setMaxPerPage($this->galleryImagesLimit);
     $pager->setCurrentPage($request->get('page', 1));
     $view->addParameters(['location' => $location, 'content' => $this->contentService->loadContentByContentInfo($view->getLocation()->getContentInfo()), 'images' => $pager]);
     return $view;
 }
 /**
  * Returns array of child content objects from given $locationId.
  *
  * @param int $locationId
  * @param int $limit
  *
  * @return array
  */
 private function fetchItems($locationId, $limit)
 {
     $languages = $this->configResolver->getParameter('languages');
     $query = new Query();
     $location = $this->locationService->loadLocation($locationId);
     $query->query = $this->childrenCriteria->generateChildCriterion($location, $languages);
     $query->performCount = false;
     $query->limit = $limit;
     $query->sortClauses = [new SortClause\DatePublished(Query::SORT_DESC)];
     $results = $this->searchService->findContent($query);
     $items = [];
     foreach ($results->searchHits as $item) {
         $items[] = $item->valueObject;
     }
     return $items;
 }
 /**
  * Displays blog post content with random selected blog posts.
  *
  * @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view
  *
  * @return \eZ\Publish\Core\MVC\Symfony\View\ContentView
  */
 public function showBlogPostAction(ContentView $view)
 {
     $languages = $this->configResolver->getParameter('languages');
     $location = $this->locationService->loadLocation($view->getLocation()->parentLocationId);
     $query = new Query();
     $query->query = $this->childrenCriteria->generateChildCriterion($location, $languages);
     $query->performCount = false;
     $query->sortClauses = [new SortClause\DatePublished(Query::SORT_DESC)];
     $results = $this->searchService->findContent($query);
     $randomPosts = [];
     foreach ($results->searchHits as $item) {
         $randomPosts[] = $item->valueObject;
     }
     shuffle($randomPosts);
     $view->addParameters(['location' => $location, 'content' => $this->contentService->loadContentByContentInfo($view->getLocation()->getContentInfo()), 'randomPosts' => array_slice($randomPosts, 0, $this->randomPostsLimit, true)]);
     return $view;
 }