Exemplo n.º 1
0
 /**
  * Render this paginator
  */
 public function render()
 {
     if ($this->query === null) {
         throw new ProgrammingError('Need a query to create the paginator widget for');
     }
     $itemCountPerPage = $this->query->getLimit();
     if (!$itemCountPerPage) {
         return '';
         // No pagination required
     }
     $totalItemCount = count($this->query);
     $pageCount = (int) ceil($totalItemCount / $itemCountPerPage);
     $currentPage = $this->query->hasOffset() ? $this->query->getOffset() / $itemCountPerPage + 1 : 1;
     $pagesInRange = $this->getPages($pageCount, $currentPage);
     $variables = array('totalItemCount' => $totalItemCount, 'pageCount' => $pageCount, 'itemCountPerPage' => $itemCountPerPage, 'first' => 1, 'current' => $currentPage, 'last' => $pageCount, 'pagesInRange' => $pagesInRange, 'firstPageInRange' => min($pagesInRange), 'lastPageInRange' => max($pagesInRange));
     if ($currentPage > 1) {
         $variables['previous'] = $currentPage - 1;
     }
     if ($currentPage < $pageCount) {
         $variables['next'] = $currentPage + 1;
     }
     if (is_array($this->viewScript)) {
         if ($this->viewScript[1] !== null) {
             return $this->view()->partial($this->viewScript[0], $this->viewScript[1], $variables);
         }
         return $this->view()->partial($this->viewScript[0], $variables);
     }
     return $this->view()->partial($this->viewScript, $variables);
 }
 protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
 {
     $limit = $this->params->get('limit', $limit);
     $page = $this->params->get('page', $offset);
     $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
     return $paginatable;
 }