function it_should_override_default_sorts_with_requested_sorts(AbstractQuery $query, IndexDefinitionInterface $indexDefinition, Request $request, TemplateDefinitionInterface $templateDefinition, ColumnInterface $sortColumn, SlidingPagination $pagination)
 {
     $request->get('direction', Argument::any())->willReturn('asc');
     $request->get('sort', Argument::any())->willReturn('another_field');
     $request->get('page', Argument::any())->willReturn(1);
     $indexDefinition->getDefaultSortColumn()->willReturn($sortColumn);
     $indexDefinition->getDefaultSortDirection()->willReturn(IndexDefinitionInterface::SORT_ASC);
     $sortColumn->getField()->willReturn('sortable_field');
     $indexDefinition->hasColumnWithField('another_field')->willReturn(true);
     $templateDefinition->getPagination()->shouldBeCalled();
     $templateDefinition->getSortable()->shouldBeCalled();
     $pagination->setParam('sort', Argument::any())->shouldBeCalledTimes(2);
     $pagination->setParam('direction', Argument::any())->shouldBeCalledTimes(2);
     $this->getGrid($query, $indexDefinition, $request)->shouldReturnAnInstanceOf('Knp\\Component\\Pager\\Pagination\\PaginationInterface');
 }
 /**
  * Get Paginator
  * 
  * @param integer $limit ( limit per page )
  * @param array $options
  * @return \Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination
  */
 protected function getPaginator($limit = 30, $options = array())
 {
     $page = $this->get('request')->query->get('page', 1);
     $cnt = 0;
     if ($this->get('request')->query->has('page')) {
         $page = $this->get('request')->query->get('page');
         $this->get('session')->set('_pager_' . $this->get('request')->get('_route'), $page);
     } elseif ($this->get('session')->has('_pager_' . $this->get('request')->get('_route'))) {
         $page = $this->get('session')->get('_pager_' . $this->get('request')->get('_route'));
     }
     if (isset($options['total_item_count']) and (int) $options['total_item_count']) {
         $cnt = $options['total_item_count'];
     }
     $this->paginator = $this->get('knp_paginator');
     if (is_array($this->query) or $this->query instanceof QueryBuilder) {
         $pagination = $this->paginator->paginate($this->query, $page, $limit, $options);
     } elseif ($this->query instanceof NativeQuery) {
         $rsm = new ResultSetMapping();
         $rsm->addScalarResult('cnt', 'cnt');
         $q = strstr($this->query->getSQL(), " FROM ");
         $q = "SELECT COUNT(*) cnt " . $q;
         $cntQuery = $this->em->createNativeQuery($q, $rsm)->setParameters($this->query->getParameters());
         try {
             $cnt = $cntQuery->getSingleScalarResult();
         } catch (\Doctrine\Orm\NoResultException $e) {
             $cnt = 0;
         }
         $sql = $this->query->getSQL();
         $pagination = $this->paginator->paginate(array());
         $sort_name = $pagination->getPaginatorOption('sortFieldParameterName');
         $sort_direction_name = $pagination->getPaginatorOption('sortDirectionParameterName');
         if ($this->get('request')->query->has($sort_name) and $this->get('request')->query->has($sort_direction_name)) {
             $sql .= ' ORDER BY ' . $this->get('request')->query->get($sort_name) . ' ' . $this->get('request')->query->get($sort_direction_name);
         } elseif (isset($options['default_sort']) and $options['default_sort']) {
             $sql .= ' ORDER BY ';
             foreach ($options['default_sort'] as $field => $type) {
                 $sql .= $field . ' ' . $type . ',';
             }
             $sql = trim($sql, ',');
         }
         if (!isset($options['not_use_limit_offset'])) {
             $offset = $limit * ($page - 1);
             $this->query->setSQL($sql . ' LIMIT ' . $limit . ' OFFSET ' . $offset);
         }
         $pagination->setCurrentPageNumber($page);
         $pagination->setItemNumberPerPage($limit);
         $pagination->setTotalItemCount($cnt);
         $pagination->setItems($this->query->getResult());
     }
     $pagination->setTemplate($this->container->getParameter('zk2_admin_panel.pagination_template'));
     $pagination->setSortableTemplate($this->container->getParameter('zk2_admin_panel.sortable_template'));
     return compact('pagination');
 }
 public function pagination(PaginationEvent $event)
 {
     $pagination = new SlidingPagination($this->engine, $this->routerHelper, $this->translator, $this->params);
     $pagination->setUsedRoute($this->route);
     $pagination->setAlias($event->options['alias']);
     $pagination->setTemplate($this->options['defaultPaginationTemplate']);
     $pagination->setSortableTemplate($this->options['defaultSortableTemplate']);
     $pagination->setPageRange($this->options['defaultPageRange']);
     $event->setPagination($pagination);
     $event->stopPropagation();
 }
 public function pagination(PaginationEvent $event)
 {
     $pagination = new SlidingPagination($this->params);
     $pagination->setUsedRoute($this->route);
     $pagination->setTemplate($this->options['defaultPaginationTemplate']);
     $pagination->setSortableTemplate($this->options['defaultSortableTemplate']);
     $pagination->setFiltrationTemplate($this->options['defaultFiltrationTemplate']);
     $pagination->setPageRange($this->options['defaultPageRange']);
     $event->setPagination($pagination);
     $event->stopPropagation();
 }
Exemplo n.º 5
0
 protected function list_common_procedures(Album $album)
 {
     $query_builder = $this->em->getRepository('RodgerGalleryBundle:Image')->createQueryBuilder('i')->where('i.album = :album')->orderBy('i.uploadedAt', 'desc')->setParameter('album', $album->getId());
     $paginator = $this->get('knp_paginator');
     /** @var \Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination $pagination */
     $pagination = $paginator->paginate($query_builder, $this->getRequest()->get('page', 1), 20);
     $this->pagination = $pagination;
     $ids = array();
     foreach ($this->pagination->getItems() as $img) {
         $ids[] = $img->getId();
     }
     $this->validating_object = new ValidateHelpers\BulkImages($query_builder->andWhere($query_builder->expr()->in('i.id', count($ids) ? $ids : array(0))), $this->em, $this->container);
     $this->bulk_form = $this->createForm(new Forms\BulkImages(), $this->validating_object);
 }
 /**
  * Get Paginator
  * 
  * @param integer $limit ( limit per page )
  * @return \Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination
  */
 protected function getPaginator($limit = 30, $options = array())
 {
     $page = 1;
     if ($this->get('request')->query->has('page')) {
         $page = $this->get('request')->query->get('page');
         $this->get('session')->set('_pager_' . $this->get('request')->get('_route'), $page);
     } elseif ($this->get('session')->has('_pager_' . $this->get('request')->get('_route'))) {
         $page = $this->get('session')->get('_pager_' . $this->get('request')->get('_route'));
     }
     $this->paginator = $this->get('knp_paginator');
     $pagination = $this->paginator->paginate($this->query, $this->get('request')->query->get('page', $page), $limit, $options);
     $pagination->setTemplate('ZkInterfaceBundle:AdminInterface:pagination.html.twig');
     $pagination->setSortableTemplate('ZkInterfaceBundle:AdminInterface:sortable.html.twig');
     return compact('pagination');
 }
Exemplo n.º 7
0
 public function pagination(PaginationEvent $event)
 {
     // default sort field and order
     $eventOptions = $event->options;
     if (isset($eventOptions['defaultSortFieldName']) && !isset($this->params[$eventOptions['sortFieldParameterName']])) {
         $this->params[$eventOptions['sortFieldParameterName']] = $eventOptions['defaultSortFieldName'];
     }
     if (isset($eventOptions['defaultSortDirection']) && !isset($this->params[$eventOptions['sortDirectionParameterName']])) {
         $this->params[$eventOptions['sortDirectionParameterName']] = $eventOptions['defaultSortDirection'];
     }
     $pagination = new SlidingPagination($this->params);
     $pagination->setUsedRoute($this->route);
     $pagination->setTemplate($this->options['defaultPaginationTemplate']);
     $pagination->setSortableTemplate($this->options['defaultSortableTemplate']);
     $pagination->setFiltrationTemplate($this->options['defaultFiltrationTemplate']);
     $pagination->setPageRange($this->options['defaultPageRange']);
     $event->setPagination($pagination);
     $event->stopPropagation();
 }
Exemplo n.º 8
0
 /**
  * @param array  $data
  * @param array  $items
  * @param string $route
  *
  * @return SlidingPagination
  */
 public static function build(array $data, array $items, $route)
 {
     $pagination = new SlidingPagination($data['params']);
     $pagination->setItems($items);
     $pagination->setCurrentPageNumber($data['current_page_number']);
     $pagination->setItemNumberPerPage($data['num_items_per_page']);
     $pagination->setTotalItemCount($data['total_count']);
     $pagination->setPaginatorOptions($data['paginator_options']);
     $pagination->setCustomParameters($data['custom_parameters']);
     $pagination->setUsedRoute($route);
     $pagination->setPageRange($data['page_range']);
     $pagination->setTemplate($data['template']);
     $pagination->setSortableTemplate($data['sortable_template']);
     $pagination->setFiltrationTemplate($data['filtration_template']);
     return $pagination;
 }
Exemplo n.º 9
0
 /**
  * Create a filter url for the field named $title
  * and identified by $key which consists of
  * alias and field. $options holds all link
  * parameters like "alt, class" and so on.
  *
  * $key example: "article.title"
  *
  * @param SlidingPagination $pagination
  * @param array             $fields
  * @param array             $options
  * @param array             $params
  *
  * @return array
  */
 public function filter(SlidingPagination $pagination, array $fields, $options = array(), $params = array())
 {
     $options = array_merge(array('absolute' => defined('Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface::ABSOLUTE_PATH') ? UrlGeneratorInterface::ABSOLUTE_PATH : false, 'translationParameters' => array(), 'translationDomain' => null, 'button' => 'Filter'), $options);
     $params = array_merge($pagination->getParams(), $params);
     $params[$pagination->getPaginatorOption('pageParameterName')] = 1;
     // reset to 1 on filter
     $filterFieldName = $pagination->getPaginatorOption('filterFieldParameterName');
     $filterValueName = $pagination->getPaginatorOption('filterValueParameterName');
     $selectedField = isset($params[$filterFieldName]) ? $params[$filterFieldName] : null;
     $selectedValue = isset($params[$filterValueName]) ? $params[$filterValueName] : null;
     $action = $this->router->generate($pagination->getRoute(), $params, $options['absolute']);
     foreach ($fields as $field => $title) {
         $fields[$field] = $this->translator->trans($title, $options['translationParameters'], $options['translationDomain']);
     }
     $options['button'] = $this->translator->trans($options['button'], $options['translationParameters'], $options['translationDomain']);
     unset($options['absolute'], $options['translationDomain'], $options['translationParameters']);
     return array_merge($pagination->getPaginatorOptions(), $pagination->getCustomParameters(), compact('fields', 'action', 'filterFieldName', 'filterValueName', 'selectedField', 'selectedValue', 'options'));
 }
Exemplo n.º 10
0
 /**
  * Create a filter url for the field named $title
  * and identified by $key which consists of
  * alias and field. $options holds all link
  * parameters like "alt, class" and so on.
  *
  * $key example: "article.title"
  *
  * @param \Twig_Environment $env
  * @param SlidingPagination $pagination
  * @param array             $fields
  * @param array             $options
  * @param array             $params
  * @param string            $template
  *
  * @return string
  */
 public function filter(\Twig_Environment $env, SlidingPagination $pagination, array $fields, $options = array(), $params = array(), $template = null)
 {
     return $env->render($template ?: $pagination->getFiltrationTemplate(), $this->processor->filter($pagination, $fields, $options, $params));
 }
Exemplo n.º 11
0
 /**
  * @param \Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination $pagination
  */
 public function addPaginationData(\Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination $pagination)
 {
     if (empty(static::$paginationData)) {
         static::$paginationData = $pagination->getPaginationData();
     }
 }
Exemplo n.º 12
0
 protected function addPaginationData(\Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination $pagination)
 {
     if (empty($this->paginationData)) {
         $this->paginationData = $pagination->getPaginationData();
     }
 }