Skip to content

Instantly share code, notes, and snippets.

@graphicmist
Last active December 18, 2015 05:38
Show Gist options
  • Save graphicmist/5733760 to your computer and use it in GitHub Desktop.
Save graphicmist/5733760 to your computer and use it in GitHub Desktop.
Custom Adapter for Paginator
<?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