/** * Main action which does all the fun * * @param integer $currentPage * @return void */ public function indexAction($currentPage = 1) { // set current page $this->currentPage = (int) $currentPage; if ($this->currentPage < 1) { $this->currentPage = 1; } elseif ($this->currentPage > $this->numberOfPages) { $this->currentPage = $this->numberOfPages; } // modify query $itemsPerPage = (int) $this->configuration['itemsPerPage']; $query = $this->objects->getQuery(); // limit should only be used if needed // and pagination only if results > itemsPerPage if ($itemsPerPage > $query->getLimit() && $itemsPerPage < $this->objects->count()) { $query->setLimit($itemsPerPage); } if ($this->currentPage > 1) { $query->setOffset((int) ($itemsPerPage * ($this->currentPage - 1))); } $modifiedObjects = $query->execute(); $this->view->assign('contentArguments', array($this->widgetConfiguration['as'] => $modifiedObjects)); $this->view->assign('configuration', $this->configuration); $this->view->assign('pagination', $this->buildPagination()); if (!empty($this->templatePath)) { $this->view->setTemplatePathAndFilename($this->templatePath); } }
/** * Main action which does all the fun * * @param integer $currentPage * @return void */ public function indexAction($currentPage = 1) { // set current page $this->currentPage = (int) $currentPage; if ($this->currentPage < 1) { $this->currentPage = 1; } elseif ($this->currentPage > $this->numberOfPages) { $this->currentPage = $this->numberOfPages; } // modify query $itemsPerPage = (int) $this->configuration['itemsPerPage']; if (is_a($this->objects, 'Tx_Extbase_Persistence_QueryResultInterface')) { $query = $this->objects->getQuery(); // limit should only be used if needed and pagination only if results > itemsPerPage if ($itemsPerPage < $this->objects->count()) { $query->setLimit($itemsPerPage); } if ($this->currentPage > 1) { $query->setOffset((int) ($itemsPerPage * ($this->currentPage - 1))); } $modifiedObjects = $query->execute(); } else { if (empty($this->objects)) { return NULL; } $offset = 0; if ($this->currentPage > 1) { $offset = (int) ($itemsPerPage * ($this->currentPage - 1)); } $modifiedObjects = array_slice($this->objects, $offset, (int) $itemsPerPage); } $this->view->assign('contentArguments', array($this->widgetConfiguration['as'] => $modifiedObjects)); $this->view->assign('configuration', $this->configuration); $this->view->assign('pagination', $this->buildPagination()); }