Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
 public function getPaginator()
 {
     $paginator = new Paginator();
     $paginator->setQuery($this);
     return $paginator;
 }