Last active
December 18, 2015 05:38
-
-
Save graphicmist/5733760 to your computer and use it in GitHub Desktop.
Custom Adapter for Paginator
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 | |
namespace Report\Adapter; | |
use Zend\Paginator\Adapter\DbSelect; | |
use Zend\Db\Sql\Select; | |
class PaginatorAdapter extends DbSelect { | |
public function count() | |
{ | |
if ($this->rowCount !== null) { | |
return $this->rowCount; | |
} | |
$select = clone $this->select; | |
$select->reset(Select::LIMIT); | |
$select->reset(Select::OFFSET); | |
$select->reset(Select::ORDER); | |
// get join information, clear, and repopulate without columns | |
$joins = $select->getRawState(Select::JOINS); | |
$select->reset(Select::JOINS); | |
foreach ($joins as $join) { | |
$select->join($join['name'], $join['on'], array(), $join['type']); | |
} | |
$columns = $select->getRawState(Select::COLUMNS); | |
$select->columns($columns); | |
//echo $select->getSqlString($this->sql->getAdapter()->getPlatform()); | |
$statement = $this->sql->prepareStatementForSqlObject($select); | |
$result = $statement->execute(); | |
$this->rowCount = $result->count(); | |
return $this->rowCount; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment