/**
  * Paginates the results using a pagination instance.
  *
  * @access  public
  * @param   \mako\pagination\Pagination  $pagination  Pagination instance
  * @return  \mako\database\query\Query
  */
 public function paginate(Pagination $pagination)
 {
     return $this->limit($pagination->limit())->offset($pagination->offset());
 }
Ejemplo n.º 2
0
 public function testRenderPage10()
 {
     $request = $this->getRequest();
     $request->shouldReceive('get')->once()->andReturn(['page' => 10]);
     $urlBuilder = $this->getURLBuilder();
     $urlBuilder->shouldReceive('current')->once()->with(['page' => 1])->andReturn('http://example.org/?page=1');
     $urlBuilder->shouldReceive('current')->once()->with(['page' => 6])->andReturn('http://example.org/?page=6');
     $urlBuilder->shouldReceive('current')->once()->with(['page' => 7])->andReturn('http://example.org/?page=7');
     $urlBuilder->shouldReceive('current')->once()->with(['page' => 8])->andReturn('http://example.org/?page=8');
     $urlBuilder->shouldReceive('current')->twice()->with(['page' => 9])->andReturn('http://example.org/?page=9');
     $urlBuilder->shouldReceive('current')->once()->with(['page' => 10])->andReturn('http://example.org/?page=10');
     $viewFactory = $this->getViewFactory();
     $paginationArray = ['items' => 200, 'items_per_page' => 20, 'number_of_pages' => 10, 'first' => 'http://example.org/?page=1', 'previous' => 'http://example.org/?page=9', 'pages' => [0 => ['url' => 'http://example.org/?page=6', 'number' => 6, 'is_current' => false], 1 => ['url' => 'http://example.org/?page=7', 'number' => 7, 'is_current' => false], 2 => ['url' => 'http://example.org/?page=8', 'number' => 8, 'is_current' => false], 3 => ['url' => 'http://example.org/?page=9', 'number' => 9, 'is_current' => false], 4 => ['url' => 'http://example.org/?page=10', 'number' => 10, 'is_current' => true]]];
     $view = $this->getView();
     $view->shouldReceive('render')->once()->andReturn('pagination');
     $viewFactory->shouldReceive('create')->once()->with('partials.pagination', $paginationArray)->andReturn($view);
     $pagination = new Pagination(200, 20, 10);
     $pagination->setRequest($request);
     $pagination->setURLBuilder($urlBuilder);
     $pagination->setViewFactory($viewFactory);
     $pagination->render('partials.pagination');
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function create($items, $itemsPerPage = null, array $options = []) : PaginationInterface
 {
     $itemsPerPage = $itemsPerPage ?? $this->options['items_per_page'];
     $options = $options + $this->options;
     $currentPage = max((int) $this->request->get($options['page_key'], 1), 1);
     $pagination = new Pagination($items, $itemsPerPage, $currentPage, $options);
     $pagination->setRequest($this->request);
     $pagination->setURLBuilder($this->urlBuilder);
     $pagination->setViewFactory($this->viewFactory);
     return $pagination;
 }