public function testRender()
 {
     $pagerfanta = $this->getMockBuilder('Pagerfanta\\Pagerfanta')->disableOriginalConstructor()->getMock();
     $pagerfanta->expects($this->any())->method('getCurrentPage')->will($this->returnValue(10));
     $pagerfanta->expects($this->any())->method('getNbPages')->will($this->returnValue(100));
     $view = new TwitterBootstrapView();
     $this->assertTrue(is_string($ups = $view->render($pagerfanta, function ($page) {
         return $page;
     })));
 }
Example #2
0
 /**
  * Get results from paginator and get paginator view.
  *
  */
 protected function paginator($queryBuilder)
 {
     // Paginator
     $adapter = new DoctrineORMAdapter($queryBuilder);
     $pagerfanta = new Pagerfanta($adapter);
     $currentPage = $this->getRequest()->get('page', 1);
     $pagerfanta->setCurrentPage($currentPage);
     $entities = $pagerfanta->getCurrentPageResults();
     // Paginator - route generator
     $me = $this;
     $routeGenerator = function ($page) use($me) {
         return $me->generateUrl('user', array('page' => $page));
     };
     // Paginator - view
     $translator = $this->get('translator');
     $view = new TwitterBootstrapView();
     $pagerHtml = $view->render($pagerfanta, $routeGenerator, array('proximity' => 3, 'prev_message' => $translator->trans('views.index.pagprev', array(), 'JordiLlonchCrudGeneratorBundle'), 'next_message' => $translator->trans('views.index.pagnext', array(), 'JordiLlonchCrudGeneratorBundle')));
     return array($entities, $pagerHtml);
 }
 public function register(Application $app)
 {
     $app['pagerfanta.pager_factory'] = $app->share(function ($app) {
         return new PagerfantaFactory();
     });
     $app['pagerfanta.view.default_options'] = array('routeName' => null, 'routeParams' => array(), 'pageParameter' => '[page]', 'proximity' => 3, 'next_message' => '»', 'prev_message' => '«', 'default_view' => 'default');
     $app['pagerfanta.view_factory'] = $app->share(function ($app) {
         $defaultView = new DefaultView();
         $twitterBoostrapView = new TwitterBootstrapView();
         $factoryView = new ViewFactory();
         $factoryView->add(array($defaultView->getName() => $defaultView, $twitterBoostrapView->getName() => $twitterBoostrapView));
         return $factoryView;
     });
     if (isset($app['twig'])) {
         $app->extend('twig', function ($twig, $app) {
             $twig->addExtension(new PagerfantaExtension($app));
             return $twig;
         });
     }
 }
Example #4
0
 /**
  * Get results from paginator and get paginator view.
  *
  */
 protected function paginator($queryBuilder, Request $request)
 {
     // Paginator
     $adapter = new DoctrineORMAdapter($queryBuilder);
     $pagerfanta = new Pagerfanta($adapter);
     $currentPage = $request->get('page', 1);
     $pagerfanta->setCurrentPage($currentPage);
     $entities = $pagerfanta->getCurrentPageResults();
     // Paginator - route generator
     $me = $this;
     $routeGenerator = function ($page) use($me) {
         return $me->generateUrl('exam_list', array('page' => $page));
     };
     // Paginator - view
     $translator = $this->get('translator');
     $view = new TwitterBootstrapView();
     $pagerHtml = $view->render($pagerfanta, $routeGenerator, array('proximity' => 3, 'prev_message' => '← Previous', 'next_message' => 'Next →'));
     return array($entities, $pagerHtml);
 }
Example #5
0
 function listAction(Application $app, $page = 1)
 {
     /*
     $source = new Entity('Entity\Pages');
     $grid = new Grid();
     
     // Attach the source to the grid
     $grid->setSource($source);
     
     // Return the response of the grid to the template
     //return $grid->getGridResponse('MyProjectMyBundle::myGrid.html.twig');
     */
     $em = $app['orm.em'];
     $dql = 'SELECT a FROM Entity\\Pages a';
     $query = $em->createQuery($dql)->setFirstResult(0)->setMaxResults(100);
     //or using the repository
     //
     //$query = $em->getRepository('Entity\Pages')->getLatestPages();
     $adapter = new DoctrineORMAdapter($query);
     $pagerfanta = new Pagerfanta($adapter);
     $routeGenerator = function ($page) use($app) {
         return $app['url_generator']->generate('list', array('page' => $page));
     };
     $page = intval($app['request']->get('page'));
     $pagerfanta->setMaxPerPage(2);
     // 10 by default
     $pagerfanta->setCurrentPage($page);
     //$view = new DefaultView();
     $view = new TwitterBootstrapView();
     $pagination = $view->render($pagerfanta, $routeGenerator, array('proximity' => 3));
     $actions = Display::url(Display::return_icon('add.png', get_lang('Add'), array(), ICON_SIZE_MEDIUM), $app['url_generator']->generate('add'));
     //$paginator = new Paginator($query, $fetchJoinCollection = true);
     return $app['template']->render_template('pages/listing.tpl', array('pages' => $pagerfanta, 'pagination' => $pagination, 'actions' => $actions));
 }
Example #6
0
 /**
  * Get results from paginator and get paginator view.
  *
  */
 protected function paginator($queryBuilder)
 {
     // Paginator
     /*$em = $this->getDoctrine()->getManager();
     
             $repository = $em->getRepository('PortalBundle:Announce');
     
             $query = $repository->createQueryBuilder('u')
                 ->where('u.userId = :id')
                 ->setParameter('id', $this->getUser()->getId())
                 ->getQuery();
     
             $adapter = new DoctrineORMAdapter( $query );*/
     $adapter = new DoctrineORMAdapter($queryBuilder);
     $pagerfanta = new Pagerfanta($adapter);
     $currentPage = $this->getRequest()->get('page', 1);
     $pagerfanta->setCurrentPage($currentPage);
     $entities = $pagerfanta->getCurrentPageResults();
     // Paginator - route generator
     $me = $this;
     $routeGenerator = function ($page) use($me) {
         return $me->generateUrl('announce', array('page' => $page));
     };
     // Paginator - view
     $translator = $this->get('translator');
     $view = new TwitterBootstrapView();
     $pagerHtml = $view->render($pagerfanta, $routeGenerator, array('proximity' => 3, 'prev_message' => $translator->trans('views.index.pagprev', array(), 'JordiLlonchCrudGeneratorBundle'), 'next_message' => $translator->trans('views.index.pagnext', array(), 'JordiLlonchCrudGeneratorBundle')));
     return array($entities, $pagerHtml);
 }