Пример #1
0
 /**
  * Return the total number of items in the query result
  *
  * @return  int
  */
 public function count()
 {
     if ($this->count === null) {
         $this->count = $this->query->count();
     }
     return $this->count;
 }
Пример #2
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);
 }
Пример #3
0
 /**
  * Apply the given page limit and number on the given query and setup a paginator for it
  *
  * The $itemsPerPage and $pageNumber parameters are only applied if not available in the current request.
  * The paginator is set on the `paginator' view property only if the current view has not been requested as compact.
  *
  * @param   QueryInterface  $query          The query to create a paginator for
  * @param   int             $itemsPerPage   Default number of items per page
  * @param   int             $pageNumber     Default page number
  *
  * @return  $this
  */
 protected function setupPaginationControl(QueryInterface $query, $itemsPerPage = 25, $pageNumber = 0)
 {
     $request = $this->getRequest();
     $limit = $request->getParam('limit', $itemsPerPage);
     $page = $request->getParam('page', $pageNumber);
     $query->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
     if (!$this->view->compact) {
         $paginator = new Paginator();
         $paginator->setQuery($query);
         $this->view->paginator = $paginator;
     }
     return $this;
 }
Пример #4
0
 /**
  * Return the current position of this query's iterator
  *
  * @return  int
  */
 public function getIteratorPosition()
 {
     return $this->query->getIteratorPosition();
 }
Пример #5
0
 /**
  * Count all results of this query
  *
  * @return  int
  */
 public function count()
 {
     return $this->query->count();
 }