/**
  * Test get results method retuns query results
  */
 public function testGetResults()
 {
     $query = $this->getMock('Sonata\\DatagridBundle\\ProxyQuery\\ProxyQueryInterface');
     $object1 = new \stdClass();
     $object1->foo = 'bar1';
     $object2 = new \stdClass();
     $object2->foo = 'bar2';
     $object3 = new \stdClass();
     $object3->foo = 'bar3';
     $expectedObjects = array($object1, $object2, $object3);
     $query->expects($this->any())->method('execute')->will($this->returnValue($expectedObjects));
     $this->pager->setQuery($query);
     $this->assertEquals($expectedObjects, $this->pager->getResults());
 }
 /**
  * {@inheritdoc}
  */
 public function getPager(array $criteria, $page, $limit = 10, array $sort = array())
 {
     $query = $this->getRepository()->createQueryBuilder('i')->select('i');
     $fields = $this->getEntityManager()->getClassMetadata($this->class)->getFieldNames();
     foreach ($sort as $field => $direction) {
         if (!in_array($field, $fields)) {
             throw new \RuntimeException(sprintf("Invalid sort field '%s' in '%s' class", $field, $this->class));
         }
     }
     if (count($sort) == 0) {
         $sort = array('reference' => 'ASC');
     }
     foreach ($sort as $field => $direction) {
         $query->orderBy(sprintf('i.%s', $field), strtoupper($direction));
     }
     $parameters = array();
     if (isset($criteria['status'])) {
         $query->andWhere('i.status = :status');
         $parameters['status'] = $criteria['status'];
     }
     $query->setParameters($parameters);
     $pager = new Pager();
     $pager->setMaxPerPage($limit);
     $pager->setQuery(new ProxyQuery($query));
     $pager->setPage($page);
     $pager->init();
     return $pager;
 }
 /**
  * {@inheritdoc}
  */
 public function getPager(array $criteria, $page, $limit = 10, array $sort = array())
 {
     /**
      * @var QueryBuilder $query
      */
     $query = $this->getRepository()->createQueryBuilder('m')->select('m');
     $fields = $this->getEntityManager()->getClassMetadata($this->class)->getFieldNames();
     foreach ($sort as $field => $direction) {
         if (!in_array($field, $fields)) {
             throw new \RuntimeException(sprintf("Invalid sort field '%s' in '%s' class", $field, $this->class));
         }
     }
     foreach ($sort as $field => $direction) {
         $query->orderBy(sprintf('m.%s', $field), strtoupper($direction));
     }
     $parameters = array();
     if (isset($criteria['category'])) {
         $query->andWhere('m.category IN :category');
         $parameters['category'] = $criteria['category'];
     }
     if (isset($criteria['enabled'])) {
         $query->andWhere('m.enabled = :enabled');
         $parameters['enabled'] = $criteria['enabled'];
     }
     $query->setParameters($parameters);
     $pager = new Pager();
     $pager->setMaxPerPage($limit);
     $pager->setQuery(new ProxyQuery($query));
     $pager->setPage($page);
     $pager->init();
     return $pager;
 }
 /**
  * {@inheritdoc}
  */
 public function getPager(array $criteria, $page, $limit = 10, array $sort = array())
 {
     $parameters = array();
     /**
      * @var QueryBuilder $query
      */
     $query = $this->getRepository()->createQueryBuilder('c')->select('c');
     if (isset($criteria['site'])) {
         $query->andWhere('c.site = :site');
         $paremeters['site'] = $criteria['site'];
     }
     if (isset($criteria['enabled'])) {
         $query->andWhere('c.enabled = :enabled');
         $parameters['enabled'] = (bool) $criteria['enabled'];
     }
     if ($sort) {
         foreach ($sort as $k => $v) {
             $query->addOrderBy($k, $v);
         }
     } else {
         $query->addOrderBy('c.name', 'ASC');
     }
     $query->setParameters($parameters);
     $pager = new Pager();
     $pager->setMaxPerPage($limit);
     $pager->setQuery(new ProxyQuery($query));
     $pager->setPage($page);
     $pager->init();
     return $pager;
 }
 /**
  * {@inheritdoc}
  *
  * Valid criteria are:
  *    enabled - boolean
  *    date - query
  *    author - 'NULL', 'NOT NULL', id, array of ids
  *    mode - string public|admin
  */
 public function getPager(array $criteria, $page, $limit = 10, array $sort = array())
 {
     if (!isset($criteria['mode'])) {
         $criteria['mode'] = 'public';
     }
     $parameters = array();
     $query = $this->getRepository()->createQueryBuilder('p')->select('p')->orderBy('p.publicationDateStart', 'DESC');
     if (!isset($criteria['enabled']) && $criteria['mode'] == 'public') {
         $criteria['enabled'] = true;
     }
     if (isset($criteria['enabled'])) {
         $query->andWhere('p.enabled = :enabled');
         $parameters['enabled'] = $criteria['enabled'];
     }
     if (isset($criteria['date']) && isset($criteria['date']['query']) && isset($criteria['date']['params'])) {
         $query->andWhere($criteria['date']['query']);
         $parameters = array_merge($parameters, $criteria['date']['params']);
     }
     /*        if (isset($criteria['author'])) {
                 if (!is_array($criteria['author']) && stristr($criteria['author'], 'NULL')) {
                     $query->andWhere('p.author IS ' . $criteria['author']);
                 } else {
                     $query->andWhere(sprintf('p.author IN (%s)', implode((array) $criteria['author'], ',')));
                 }
             }*/
     if (isset($criteria['collection']) && $criteria['collection'] instanceof CollectionInterface) {
         $query->andWhere('p.collection = :collectionid');
         $parameters['collectionid'] = $criteria['collection']->getId();
     }
     $query->setParameters($parameters);
     $pager = new Pager();
     $pager->setMaxPerPage($limit);
     $pager->setQuery(new ProxyQuery($query));
     $pager->setPage($page);
     $pager->init();
     return $pager;
 }
 /**
  * {@inheritdoc}
  */
 public function getPager(array $criteria, $page, $limit = 10, array $sort = array())
 {
     $query = $this->getRepository()->createQueryBuilder('b')->select('b');
     $parameters = array();
     $query->setParameters($parameters);
     $pager = new Pager();
     $pager->setMaxPerPage($limit);
     $pager->setQuery(new ProxyQuery($query));
     $pager->setPage($page);
     $pager->init();
     return $pager;
 }
 /**
  * {@inheritdoc}
  */
 public function getPager(array $criteria, $page, $maxPerPage = 10)
 {
     $parameters = array();
     $query = $this->getRepository()->createQueryBuilder('c')->select('c');
     $criteria['enabled'] = isset($criteria['enabled']) ? $criteria['enabled'] : true;
     $query->andWhere('c.enabled = :enabled');
     $parameters['enabled'] = $criteria['enabled'];
     $query->setParameters($parameters);
     $pager = new Pager();
     $pager->setMaxPerPage($maxPerPage);
     $pager->setQuery(new ProxyQuery($query));
     $pager->setPage($page);
     $pager->init();
     return $pager;
 }
Beispiel #8
0
 /**
  * {@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;
 }
 /**
  * {@inheritdoc}
  */
 public function getPager(array $criteria, $page, $limit = 10, array $sort = array())
 {
     $query = $this->getRepository()->createQueryBuilder('p')->select('p');
     $fields = $this->getEntityManager()->getClassMetadata($this->class)->getFieldNames();
     foreach ($sort as $field => $direction) {
         if (!in_array($field, $fields)) {
             throw new \RuntimeException(sprintf("Invalid sort field '%s' in '%s' class", $field, $this->class));
         }
     }
     if (count($sort) == 0) {
         $sort = array('name' => 'ASC');
     }
     foreach ($sort as $field => $direction) {
         $query->orderBy(sprintf('p.%s', $field), strtoupper($direction));
     }
     $parameters = array();
     if (isset($criteria['enabled'])) {
         $query->andWhere('p.enabled = :enabled');
         $parameters['enabled'] = $criteria['enabled'];
     }
     if (isset($criteria['edited'])) {
         $query->andWhere('p.edited = :edited');
         $parameters['edited'] = $criteria['edited'];
     }
     if (isset($criteria['site'])) {
         $query->join('p.site', 's');
         $query->andWhere('s.id = :siteId');
         $parameters['siteId'] = $criteria['site'];
     }
     if (isset($criteria['parent'])) {
         $query->join('p.parent', 'pa');
         $query->andWhere('pa.id = :parentId');
         $parameters['parentId'] = $criteria['parent'];
     }
     if (isset($criteria['root'])) {
         $isRoot = (bool) $criteria['root'];
         if ($isRoot) {
             $query->andWhere('p.parent IS NULL');
         } else {
             $query->andWhere('p.parent IS NOT NULL');
         }
     }
     $query->setParameters($parameters);
     $pager = new Pager();
     $pager->setMaxPerPage($limit);
     $pager->setQuery(new ProxyQuery($query));
     $pager->setPage($page);
     $pager->init();
     return $pager;
 }
 /**
  * {@inheritdoc}
  */
 public function getPager(array $criteria, $page, $limit = 10, array $sort = array())
 {
     $query = $this->getRepository()->createQueryBuilder('p')->select('p');
     $parameters = array();
     if (isset($criteria['enabled'])) {
         $query->andWhere('p.enabled = :enabled');
         $parameters['enabled'] = $criteria['enabled'];
     }
     if (isset($criteria['edited'])) {
         $query->andWhere('p.edited = :edited');
         $parameters['edited'] = $criteria['edited'];
     }
     if (isset($criteria['site'])) {
         $query->join('p.site', 's');
         $query->andWhere('s.id = :siteId');
         $parameters['siteId'] = $criteria['site'];
     }
     if (isset($criteria['parent'])) {
         $query->join('p.parent', 'pa');
         $query->andWhere('pa.id = :parentId');
         $parameters['parentId'] = $criteria['parent'];
     }
     if (isset($criteria['root'])) {
         $isRoot = (bool) $criteria['root'];
         if ($isRoot) {
             $query->andWhere('p.parent IS NULL');
         } else {
             $query->andWhere('p.parent IS NOT NULL');
         }
     }
     $query->setParameters($parameters);
     $pager = new Pager();
     $pager->setMaxPerPage($limit);
     $pager->setQuery(new ProxyQuery($query));
     $pager->setPage($page);
     $pager->init();
     return $pager;
 }
 /**
  * {@inheritdoc}
  */
 public function getPager(array $criteria, $page, $limit = 10, array $sort = array())
 {
     $parameters = array('context_enabled' => true);
     $query = $this->getRepository()->createQueryBuilder('c')->select('c')->innerJoin('c.context', 'cc')->andWhere('cc.enabled = :context_enabled');
     if (isset($criteria['context'])) {
         $query->andWhere('c.context = :context');
         $parameters['context'] = $criteria['context'];
     }
     if (isset($criteria['site'])) {
         $query->andWhere('cc.site = :site');
         $parameters['site'] = $criteria['site'];
     }
     if (isset($criteria['enabled'])) {
         $query->andWhere('c.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;
 }
Beispiel #12
0
 /**
  * {@inheritDoc}
  */
 public function getPager(array $criteria, $page, $limit = 10, array $sort = array())
 {
     if (!isset($criteria['mode'])) {
         $criteria['mode'] = 'public';
     }
     $parameters = array();
     $query = $this->getRepository()->createQueryBuilder('c')->orderby('c.createdAt', 'DESC');
     if ($criteria['mode'] == 'public') {
         $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();
     $pager->setMaxPerPage($limit);
     $pager->setQuery(new ProxyQuery($query));
     $pager->setPage($page);
     $pager->init();
     return $pager;
 }
Beispiel #13
0
 /**
  * {@inheritdoc}
  */
 public function getPager(array $criteria, $page, $limit = 10, array $sort = array())
 {
     $query = $this->getRepository()->createQueryBuilder('p')->select('p');
     $fields = $this->getEntityManager()->getClassMetadata($this->class)->getFieldNames();
     foreach ($sort as $field => $direction) {
         if (!in_array($field, $fields)) {
             unset($sort[$field]);
         }
     }
     if (count($sort) == 0) {
         $sort = array('name' => 'ASC');
     }
     foreach ($sort as $field => $direction) {
         $query->orderBy(sprintf('p.%s', $field), strtoupper($direction));
     }
     $parameters = array();
     if (isset($criteria['enabled'])) {
         $query->andWhere('p.enabled = :enabled');
         $parameters['enabled'] = $criteria['enabled'];
     }
     $query->setParameters($parameters);
     $pager = new Pager();
     $pager->setMaxPerPage($limit);
     $pager->setQuery(new ProxyQuery($query));
     $pager->setPage($page);
     $pager->init();
     return $pager;
 }
Beispiel #14
0
 public function getPostsSearchPager(array $criteria, $page, $limit = 10, array $sort = array())
 {
     $parameters = array();
     $em = $this->postManager->getEntityManager();
     $query = $em->createQueryBuilder()->select('p')->from('AppBundle:News\\Post', 'p')->orderBy('p.publicationDateStart', 'DESC');
     if ($criteria['search']) {
         $query->andWhere('p.title LIKE :search');
         $parameters['search'] = (string) '%' . $criteria['search'] . '%';
     }
     /* d($parameters); */
     $query->setParameters($parameters);
     /*dd($query->getQuery()->getResult());*/
     /* d($query->getResult()); */
     $pager = new Pager();
     $pager->setMaxPerPage($limit);
     $pager->setQuery(new ProxyQuery($query));
     $pager->setPage($page);
     /*dd($criteria);*/
     $pager->init();
     return $pager;
 }
 /**
  * {@inheritdoc}
  */
 public function getPager(array $criteria, $page, $limit = 10, array $sort = array())
 {
     $query = $this->repository->createQueryBuilder('u')->select('u');
     $fields = $this->objectManager->getClassMetadata($this->class)->getFieldNames();
     foreach ($sort as $field => $direction) {
         if (!in_array($field, $fields)) {
             throw new \RuntimeException(sprintf("Invalid sort field '%s' in '%s' class", $field, $this->class));
         }
     }
     if (count($sort) == 0) {
         $sort = array('username' => 'ASC');
     }
     foreach ($sort as $field => $direction) {
         $query->orderBy(sprintf('u.%s', $field), strtoupper($direction));
     }
     if (isset($criteria['enabled'])) {
         $query->andWhere('u.enabled = :enabled');
         $query->setParameter('enabled', $criteria['enabled']);
     }
     if (isset($criteria['locked'])) {
         $query->andWhere('u.locked = :locked');
         $query->setParameter('locked', $criteria['locked']);
     }
     $pager = new Pager();
     $pager->setMaxPerPage($limit);
     $pager->setQuery(new ProxyQuery($query));
     $pager->setPage($page);
     $pager->init();
     return $pager;
 }