* @author Timo Hund */ class ResultPaginateController extends AbstractPaginateWidgetController { /** * @var SearchResultSet */ protected $resultSet; /** * @return void */ public function initializeAction() { parent::initializeAction(); $this->resultSet = $this->widgetConfiguration['resultSet']; $this->configuration['itemsPerPage'] = $this->getItemsPerPage(); $this->numberOfPages = (int)ceil($this->resultSet->getAllResultCount() / $this->configuration['itemsPerPage']); } /** * Determines the number of results per page. When nothing is configured 10 will be returned. * * @return int */ protected function getItemsPerPage() { $perPage = (int)$this->resultSet->getUsedSearch()->getQuery()->getRows(); return $perPage > 0 ? $perPage : 10; } /** * @param \WapplerSystems\Meilisearch\Mvc\Controller\SolrControllerContext $controllerContext * @return \WapplerSystems\Meilisearch\Mvc\Controller\SolrControllerContext */ protected function setActiveSearchResultSet($controllerContext) { $controllerContext->setSearchResultSet($this->resultSet); return $controllerContext; } /** * @return void */ public function indexAction() { // set current page $this->currentPage = $this->resultSet->getUsedPage(); if ($this->currentPage < 1) { $this->currentPage = 1; } $this->view->assign('contentArguments', [$this->widgetConfiguration['as'] => $this->resultSet->getSearchResults(), 'pagination' => $this->buildPagination()]); $this->view->assign('configuration', $this->configuration); $this->view->assign('resultSet', $this->resultSet); if (!empty($this->templatePath)) { $this->view->setTemplatePathAndFilename($this->templatePath); } } }