|
Perforce Chronicle 2012.2/486814
API Documentation
|
An adapter to assist Zend_Paginator in paginating records. More...
Public Member Functions | |
| __construct (P4Cms_Record_Query $query=null) | |
| Accept a query object during construction. | |
| count () | |
| Compute the count of items in the result. | |
| getItems ($offset, $itemCountPerPage) | |
| Get the iterator items appearing on a particular 'page' of results. | |
| setQuery (P4Cms_Record_Query $query) | |
| Set the query for fetching results to be paginated. | |
Public Attributes | |
| const | DEFAULT_PAGE_SIZE = 25 |
Protected Attributes | |
| $_count = null | |
| $_query = null | |
An adapter to assist Zend_Paginator in paginating records.
| P4Cms_Record_PaginatorAdapter::__construct | ( | P4Cms_Record_Query $ | query = null | ) |
Accept a query object during construction.
| P4Cms_Record_Query | $query | Optional - the query to use to select results. |
{
if (!isset($query)) {
$query = new P4Cms_Record_Query;
}
$this->_query = $query;
}
| P4Cms_Record_PaginatorAdapter::count | ( | ) |
Compute the count of items in the result.
{
if ($this->_count === null) {
$recordClass = $this->_query->getRecordClass();
$this->_count = $recordClass::count($this->_query);
}
return $this->_count;
}
| P4Cms_Record_PaginatorAdapter::getItems | ( | $ | offset, |
| $ | itemCountPerPage | ||
| ) |
Get the iterator items appearing on a particular 'page' of results.
| integer | $offset | The index of the first result to return. |
| integer | $itemCountPerPage | The count of results to return. |
{
$query = clone $this->_query;
// limit total number of rows.
if (is_string($itemCountPerPage) || is_float($itemCountPerPage)) {
$itemCountPerPage = (int) $itemCountPerPage;
}
if ($itemCountPerPage < 1) {
$itemCountPerPage = static::DEFAULT_PAGE_SIZE;
}
$query->setMaxRows($itemCountPerPage);
// ignore first 'offset' rows.
$query->setStartRow($offset);
$recordClass = $this->_query->getRecordClass();
return $recordClass::fetchAll($query);
}
| P4Cms_Record_PaginatorAdapter::setQuery | ( | P4Cms_Record_Query $ | query | ) |
Set the query for fetching results to be paginated.
| P4Cms_Record_Query | $query | The query for results. |
{
$this->_query = $query;
$this->_count = null;
}
P4Cms_Record_PaginatorAdapter::$_count = null [protected] |
P4Cms_Record_PaginatorAdapter::$_query = null [protected] |