Exemplo n.º 1
0
 public function testGetPrevUrl()
 {
     $this->paginator->setCurrentPage(2);
     $this->paginator->setUrlPattern('/example/page(:num)');
     $this->assertEquals('/example/page1', $this->paginator->getPrevUrl());
     // Returns null if on the first page.
     $this->paginator->setCurrentPage(1);
     $this->assertNull($this->paginator->getPrevUrl());
 }
Exemplo n.º 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()));
 }