Beispiel #1
0
 /**
  * @param integer $categoryId
  * @param integer $page
  * @param integer $limit
  * @param array   $criteria
  *
  * @return PagerInterface
  */
 public function getSubCategoriesPager($categoryId, $page = 1, $limit = 25, $criteria = array())
 {
     $queryBuiler = $this->getRepository()->createQueryBuilder()->select('c')->from($this->class, 'c')->where('c.parent = :categoryId')->setParameter('categoryId', $categoryId);
     $pager = new Pager($limit);
     $pager->setQuery(new ProxyQuery($queryBuiler));
     $pager->setPage($page);
     $pager->init();
     return $pager;
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function getPager(array $criteria, $page, $maxPerPage = 10, array $sort = array())
 {
     if (!isset($criteria['mode'])) {
         $criteria['mode'] = 'public';
     }
     $parameters = array();
     $query = $this->getRepository()->createQueryBuilder('p')->select('p,t');
     if ($criteria['mode'] == 'admin') {
         $query->leftJoin('p.tags', 't')->leftJoin('p.author', 'a');
     } else {
         $query->leftJoin('p.tags', 't', Join::WITH, 't.enabled = true')->leftJoin('p.author', 'a', Join::WITH, 'a.enabled = true');
     }
     if ($criteria['mode'] == 'public') {
         // enabled
         $criteria['enabled'] = isset($criteria['enabled']) ? $criteria['enabled'] : true;
         $query->andWhere('p.enabled = :enabled');
         $parameters['enabled'] = $criteria['enabled'];
     }
     if (isset($criteria['date'])) {
         $query->andWhere($criteria['date']['query']);
         $parameters = array_merge($parameters, $criteria['date']['params']);
     }
     if (isset($criteria['tag'])) {
         $query->andWhere('t.slug LIKE :tag');
         $parameters['tag'] = (string) $criteria['tag'];
     }
     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($maxPerPage);
     $proxyQuery = new ProxyQuery($query);
     $proxyQuery->setSortBy(array(), array('fieldName' => 'publicationDateStart'));
     $proxyQuery->setSortOrder('DESC');
     $pager->setQuery($proxyQuery);
     $pager->setPage($page);
     $pager->init();
     return $pager;
 }
 public function getMedias(array $criteria, $page, $maxMediaPerPage = 5)
 {
     $query = $this->em->getRepository($this->class)->createQueryBuilder('m');
     // enabled
     $criteria['enabled'] = isset($criteria['enabled']) ? $criteria['enabled'] : true;
     $query->andWhere('m.enabled = :enabled');
     $parameters['enabled'] = $criteria['enabled'];
     if (isset($criteria['context'])) {
         $query->andWhere('m.context = :context');
         $parameters['context'] = $criteria['context'];
     }
     $query->setParameters($parameters);
     $pager = new Pager();
     $pager->setMaxPerPage($maxMediaPerPage);
     $pager->setQuery(new ProxyQuery($query));
     $pager->setPage($page);
     $pager->init();
     return $pager;
 }
 /**
  * @param array   $criteria
  * @param integer $page
  * @param integer $maxPerPage
  *
  * @return \Sonata\AdminBundle\Datagrid\PagerInterface
  */
 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');
     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($this->proxyQuery($query));
     $pager->setPage($page);
     $pager->init();
     return $pager;
 }
 /**
  * @param array $criteria
  * @param integer $page
  * @param integer $maxPerPage
  *
  * @return \Sonata\AdminBundle\Datagrid\ORM\Pager
  */
 public function getPager(array $criteria, $page, $maxPerPage = 10)
 {
     $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();
     $pager->setMaxPerPage($maxPerPage);
     $pager->setQuery(new ProxyQuery($query));
     $pager->setPage($page);
     $pager->init();
     return $pager;
 }
 /**
  * Retrieve posts, based on the criteria, a page at a time.
  * Valid criteria are:
  *    enabled - boolean
  *    date - query
  *    tag - string
  *    author - 'NULL', 'NOT NULL', id, array of ids
  *
  * @param array $criteria
  * @param integer $page
  * @param integer $maxPerPage
  *
  * @return \Sonata\AdminBundle\Datagrid\ORM\Pager
  */
 public function getPager(array $criteria, $page, $maxPerPage = 10)
 {
     $parameters = array();
     $query = $this->em->getRepository($this->class)->createQueryBuilder('p')->select('p, t')->leftJoin('p.tags', 't', Expr\Join::WITH, 't.enabled = true')->leftJoin('p.author', 'a', Expr\Join::WITH, 'a.enabled = true')->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($criteria['date']['query']);
         $parameters = array_merge($parameters, $criteria['date']['params']);
     }
     if (isset($criteria['tag'])) {
         $query->andWhere('t.slug LIKE :tag');
         $parameters['tag'] = (string) $criteria['tag'];
     }
     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'], ',')));
         }
     }
     $query->setParameters($parameters);
     $pager = new Pager();
     $pager->setMaxPerPage($maxPerPage);
     $pager->setQuery(new ProxyQuery($query));
     $pager->setPage($page);
     $pager->init();
     return $pager;
 }