Advertisement
Guest User

getPosts()

a guest
Oct 31st, 2012
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. public function getPosts($limit = 10, $start = 0, $alias = null, $order = array(), $withComments)
  2.     {
  3.         $select = $this->table->select();
  4.        
  5.         if ($alias) {
  6.             $select->where('alias = ?', $alias);
  7.             return $this->table->fetchRow($select);
  8.         }
  9.         if ($withComments) {
  10.             $subselect = $this->table->select()->from(array('x' => 'blog_comments'), array('x.post_id', new Zend_Db_Expr('count(*) as comments')))->group('post_id');
  11.             $select->from(array('p' => 'blog_posts'), array('p.*'))
  12.                    ->setIntegrityCheck(false)
  13.                    ->joinLeft(array(
  14.                         'x' => $subselect,
  15.                         'x.post_id = p.id',
  16.                         array()
  17.                     ));
  18.         }
  19.        
  20.         $select->order($order);
  21.        
  22.         $adapter = new Zend_Paginator_Adapter_DbTableSelect($select);
  23.         $count = $this->table->getAdapter()->select();
  24.         $count->reset(Zend_Db_Select::COLUMNS);
  25.         $count->reset(Zend_Db_Select::FROM);
  26.         $count->from(
  27.             'blog_posts',
  28.             new Zend_Db_Expr('COUNT(*) AS `zend_paginator_row_count`')
  29.         );
  30.         $adapter->setRowCount($count);
  31.         $paginator = new Zend_Paginator($adapter);
  32.         $paginator->setItemCountPerPage($limit)
  33.                   ->setCurrentPageNumber($start);
  34.         return $paginator;
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement