Created
August 9, 2012 22:50
-
-
Save sinamiandashti/3308761 to your computer and use it in GitHub Desktop.
zf doctrine paginator adapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* To change this template, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
/** | |
* Description of Paginator | |
* | |
* @author Sina Miandashti | |
*/ | |
class Paginator implements Zend_Paginator_Adapter_Interface { | |
protected $_doctrineQueryBuilder; | |
function __construct($_doctrineQuery) { | |
$this->_doctrineQueryBuilder = $_doctrineQuery; | |
} | |
public function count() { | |
if (!is_a($this->_doctrineQueryBuilder, 'Doctrine\ORM\Query')) { | |
$query = $this->_doctrineQueryBuilder->getQuery(); | |
} else { | |
$query = $this->_doctrineQueryBuilder; | |
} | |
return count($query->getResult()); | |
} | |
public function getItems($offset, $itemCountPerPage) { | |
$this->_doctrineQueryBuilder->setFirstResult( $offset ) | |
->setMaxResults( $itemCountPerPage ); | |
if (!is_a($this->_doctrineQueryBuilder, 'Doctrine\ORM\Query')) { | |
$query = $this->_doctrineQueryBuilder->getQuery(); | |
} else { | |
$query = $this->_doctrineQueryBuilder; | |
} | |
return $query->getResult(); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment