Beispiel #1
0
 /**
  * Gets paged search results from search options
  *
  * @param array $options
  * @param int $page
  * @return Zend\Paginator\Paginator
  **/
 public function pagedResults(array $options, $page = 1)
 {
     $this->getForm()->setData($options);
     $config = $this->em->getConfiguration();
     $config->addCustomDatetimeFunction('YEAR', 'Blog\\Util\\Query\\Mysql\\Year');
     $qb = $this->em->createQueryBuilder();
     $qb->select('p')->from(self::ENTITY_POST, 'p')->andWhere('p.isPublished = :published')->orderBy('p.dateAdded', 'DESC');
     $params = array('published' => 1);
     if (isset($options['search']) && $options['search']) {
         $qb->andWhere($qb->expr()->orX($qb->expr()->like('p.content', ':search'), $qb->expr()->like('p.title', ':search')));
         $params['search'] = '%' . $options['search'] . '%';
     }
     if (isset($options['category']) && $options['category']) {
         $qb->join('p.category', 'c');
         $qb->andWhere('c.id = :category_id');
         $params['category_id'] = $options['category'];
     }
     if (isset($options['year']) && $options['year']) {
         $qb->andWhere('YEAR(p.dateAdded) = :year');
         $params['year'] = $options['year'];
     }
     $qb->setParameters($params);
     $paginator = PaginatorFactory::create($qb, $page, 5);
     return $paginator;
 }
Beispiel #2
0
 /**
  * Gets paged comments
  *
  * @param int $page
  * @return Zend\Paginator\Paginator
  **/
 public function getPaged($page = 1)
 {
     $qb = $this->em->createQueryBuilder();
     $qb->select('c')->from(self::ENTITY_COMMENT, 'c')->orderBy('c.dateAdded', 'DESC');
     $paginator = PaginatorFactory::create($qb, $page, 10);
     return $paginator;
 }
Beispiel #3
0
 /**
  * Gets paged posts from a year
  *
  * @param int $year
  * @param int $page
  * @return Zend\Paginator\Paginator
  **/
 public function getPagedFromArchive($year, $page)
 {
     $qb = $this->em->createQueryBuilder();
     $config = $this->em->getConfiguration();
     $config->addCustomDatetimeFunction('YEAR', 'Blog\\Util\\Query\\Mysql\\Year');
     $qb->select('partial p.{id, title}')->from(self::ENTITY_POST, 'p')->where('p.isPublished = :published')->andWhere('YEAR(p.dateAdded) = :year')->orderBy('p.dateAdded', 'DESC')->setParameters(array('published' => 1, 'year' => $year));
     $paginator = PaginatorFactory::create($qb, $page);
     return $paginator;
 }