예제 #1
0
 function getPager(array $criteria, $page)
 {
     $parameters = array();
     $query = $this->em->getRepository($this->class)->createQueryBuilder('c')->orderby('c.createdAt', 'DESC');
     $criteria['status'] = isset($criteria['status']) ? $criteria['status'] : CommentInterface::STATUS_VALID;
     $query->andWhere('c.status = :status');
     $parameters['status'] = $criteria['status'];
     if (isset($criteria['postId'])) {
         $query->andWhere('c.post = :postId');
         $parameters['postId'] = $criteria['postId'];
     }
     $query->setParameters($parameters);
     $pager = new Pager(500);
     // no limit
     $pager->setQuery(new ProxyQuery($query));
     $pager->setPage($page);
     $pager->init();
     return $pager;
 }
예제 #2
0
 /**
  * @param array $criteria
  * @param $page
  * @return \Sonata\AdminBundle\Datagrid\ORM\Pager
  */
 public function getPager(array $criteria, $page)
 {
     $parameters = array();
     $query = $this->em->getRepository($this->class)->createQueryBuilder('p')->select('p, t')->leftJoin('p.tags', 't')->orderby('p.publicationDateStart', 'DESC');
     // enabled
     $criteria['enabled'] = isset($criteria['enabled']) ? $criteria['enabled'] : true;
     $query->andWhere('p.enabled = :enabled');
     $parameters['enabled'] = $criteria['enabled'];
     if (isset($criteria['date'])) {
         $query->andWhere('p.publicationDateStart LIKE :date');
         $parameters['date'] = $criteria['date'];
     }
     if (isset($criteria['tag'])) {
         $query->andWhere('t.slug LIKE :tag and t.enabled = :tag_enabled');
         $parameters['tag'] = $criteria['tag'];
         $parameters['tag_enabled'] = true;
     }
     $query->setParameters($parameters);
     $pager = new Pager();
     $pager->setQuery(new ProxyQuery($query));
     $pager->setPage($page);
     $pager->init();
     return $pager;
 }