コード例 #1
0
 /**
  * @dataProvider getRangeData
  */
 public function testGetItemRanges($numItems, $itemsPerPage, $currentPage, $expectedFirst, $expectedLast)
 {
     $paginator = new Paginator($numItems, $itemsPerPage, $currentPage);
     $this->assertEquals($numItems, $paginator->getTotalItems());
     $this->assertEquals($expectedFirst, $paginator->getCurrentPageFirstItem());
     $this->assertEquals($expectedLast, $paginator->getCurrentPageLastItem());
 }
コード例 #2
0
 public function listAction(Application $app, Request $request)
 {
     $order_by = $request->get('order_by') ?: 'name';
     $order_dir = $request->get('order_dir') == 'DESC' ? 'DESC' : 'ASC';
     $limit = (int) ($request->get('limit') ?: 50);
     $page = (int) ($request->get('page') ?: 1);
     $offset = ($page - 1) * $limit;
     $criteria = array();
     if (!$app['security']->isGranted('ROLE_ADMIN')) {
         $criteria['isEnabled'] = true;
     }
     $users = $this->userManager->findBy($criteria, array('limit' => array($offset, $limit), 'order_by' => array($order_by, $order_dir)));
     $numResults = $this->userManager->findCount($criteria);
     $paginator = new Paginator($numResults, $limit, $page, $app['url_generator']->generate('user.list') . '?page=(:num)&limit=' . $limit . '&order_by=' . $order_by . '&order_dir=' . $order_dir);
     foreach ($users as $user) {
         $user->imageUrl = $this->getGravatarUrl($user->getEmail(), 40);
     }
     return $app['twig']->render($this->getTemplate('list'), array('layout_template' => $this->getTemplate('layout'), 'users' => $users, 'paginator' => $paginator, 'numResults' => $paginator->getTotalItems(), 'nextUrl' => $paginator->getNextUrl(), 'prevUrl' => $paginator->getPrevUrl(), 'firstResult' => $paginator->getCurrentPageFirstItem(), 'lastResult' => $paginator->getCurrentPageLastItem()));
 }
コード例 #3
0
 public function pagination()
 {
     $totalItems = 100000;
     $itemsPerPage = 50;
     $currentPage = 1900;
     $urlPattern = '/foo/page/(:num)';
     $paginator = new Paginator($totalItems, $itemsPerPage, $currentPage, $urlPattern);
     $paginator->setMaxPagesToShow(7);
     echo $paginator;
 }