/** * {@inheritdoc} */ public function getPager(array $criteria, $page, $limit = 10, array $sort = array()) { $parameters = array(); $query = $this->getRepository()->createQueryBuilder('t')->select('t'); if (isset($criteria['enabled'])) { $query->andWhere('t.enabled = :enabled'); $parameters['enabled'] = (bool) $criteria['enabled']; } $query->setParameters($parameters); $pager = new Pager(); $pager->setMaxPerPage($limit); $pager->setQuery(new ProxyQuery($query)); $pager->setPage($page); $pager->init(); return $pager; }
/** * Return a paged query, and sets variables for paging * * @param array $query An array with the query * @param mixed $page Current page or false * @param mixed $maxPerPage Limit (max per page) or false * @param mixed $sort Current sort or false * * @return Dynamic\MongoDBBundle\Core\DynamicPager */ protected function getPager($query=array(), $page=false, $maxPerPage=false, $sort=false) { $this->pager->setCurrent($page ? $page : $this->getPage()); $this->pager->setLimit($maxPerPage ? $maxPerPage : $this->generator->list->max_per_page); $this->pager->setQuery($query ? $query : $this->getQuery()); $this->configureSort(); if ($sort && is_array($sort)) { $this->pager->setSort($sort); } elseif (count($this->getSort()) !== 0) { $this->pager->setSort($this->getSort()); } else { $this->pager->setSort($this->generator->list->sort); } return $this->pager; }