Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function getPosts($limit = 10, $start = 0, $alias = null, $order = array(), $withComments)
- {
- $select = $this->table->select();
- if ($alias) {
- $select->where('alias = ?', $alias);
- return $this->table->fetchRow($select);
- }
- if ($withComments) {
- $subselect = $this->table->select()->from(array('x' => 'blog_comments'), array('x.post_id', new Zend_Db_Expr('count(*) as comments')))->group('post_id');
- $select->from(array('p' => 'blog_posts'), array('p.*'))
- ->setIntegrityCheck(false)
- ->joinLeft(array(
- 'x' => $subselect,
- 'x.post_id = p.id',
- array()
- ));
- }
- $select->order($order);
- $adapter = new Zend_Paginator_Adapter_DbTableSelect($select);
- $count = $this->table->getAdapter()->select();
- $count->reset(Zend_Db_Select::COLUMNS);
- $count->reset(Zend_Db_Select::FROM);
- $count->from(
- 'blog_posts',
- new Zend_Db_Expr('COUNT(*) AS `zend_paginator_row_count`')
- );
- $adapter->setRowCount($count);
- $paginator = new Zend_Paginator($adapter);
- $paginator->setItemCountPerPage($limit)
- ->setCurrentPageNumber($start);
- return $paginator;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement