Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Record_PaginatorAdapter Class Reference

An adapter to assist Zend_Paginator in paginating records. More...

List of all members.

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

Detailed Description

An adapter to assist Zend_Paginator in paginating records.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Constructor & Destructor Documentation

P4Cms_Record_PaginatorAdapter::__construct ( P4Cms_Record_Query query = null)

Accept a query object during construction.

Parameters:
P4Cms_Record_Query$queryOptional - the query to use to select results.
    {
        if (!isset($query)) {
            $query = new P4Cms_Record_Query;
        }

        $this->_query = $query;
    }

Member Function Documentation

P4Cms_Record_PaginatorAdapter::count ( )

Compute the count of items in the result.

Returns:
integer The count of items.
    {
        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.

Parameters:
integer$offsetThe index of the first result to return.
integer$itemCountPerPageThe count of results to return.
Returns:
P4Cms_Model_Iterator An iterator containing the selected results.
    {
        $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.

Parameters:
P4Cms_Record_Query$queryThe query for results.
    {
        $this->_query = $query;
        $this->_count = null;
    }

Member Data Documentation

P4Cms_Record_PaginatorAdapter::$_count = null [protected]
P4Cms_Record_PaginatorAdapter::$_query = null [protected]

The documentation for this class was generated from the following file: