Zend Framework  1.12
Public Member Functions | Public Attributes | Protected Attributes | List of all members
Zend_Paginator_Adapter_DbSelect Class Reference

Public Member Functions

 __construct (Zend_Db_Select $select)
 Constructor.
 
 getCacheIdentifier ()
 Returns the cache identifier.
 
 setRowCount ($rowCount)
 Sets the total row count, either directly or through a supplied query.
 
 getItems ($offset, $itemCountPerPage)
 Returns an array of items for a page.
 
 count ()
 Returns the total number of rows in the result set.
 
 getCountSelect ()
 Get the COUNT select object for the provided query.
 

Public Attributes

const ROW_COUNT_COLUMN = 'zend_paginator_row_count'
 

Protected Attributes

 $_countSelect = null
 
 $_select = null
 
 $_rowCount = null
 
 $_cacheIdentifier = null
 

Constructor & Destructor Documentation

__construct ( Zend_Db_Select  $select)

Constructor.

Parameters
Zend_Db_Select$selectThe select query

Member Function Documentation

count ( )

Returns the total number of rows in the result set.

Returns
integer
getCacheIdentifier ( )

Returns the cache identifier.

Returns
string
getCountSelect ( )

Get the COUNT select object for the provided query.

TODO: Have a look at queries that have both GROUP BY and DISTINCT specified. In that use-case I'm expecting problems when either GROUP BY or DISTINCT has one column.

Returns
Zend_Db_Select

We only need to generate a COUNT query once. It will not change for this instance.

If we're dealing with a UNION query, execute the UNION as a subquery to the COUNT query.

If there is more than one column AND it's a DISTINCT query, more than one group, or if the query has a HAVING clause, then take the original query and use it as a subquery os the COUNT query.

If the original query had a GROUP BY or a DISTINCT part and only one column was specified, create a COUNT(DISTINCT ) query instead of a regular COUNT query.

Create the COUNT part of the query

getItems (   $offset,
  $itemCountPerPage 
)

Returns an array of items for a page.

Parameters
integer$offsetPage offset
integer$itemCountPerPageNumber of items per page
Returns
array

Implements Zend_Paginator_Adapter_Interface.

setRowCount (   $rowCount)

Sets the total row count, either directly or through a supplied query.

Without setting this, getPages() selects the count as a subquery (SELECT COUNT ... FROM (SELECT ...)). While this yields an accurate count even with queries containing clauses like LIMIT, it can be slow in some circumstances. For example, in MySQL, subqueries are generally slow when using the InnoDB storage engine. Users are therefore encouraged to profile their queries to find the solution that best meets their needs.

Parameters
Zend_Db_Select | integer$totalRowCountTotal row count integer or query
Returns
Zend_Paginator_Adapter_DbSelect $this
Exceptions
Zend_Paginator_Exception
See Also
Zend_Paginator_Exception
Zend_Paginator_Exception

Member Data Documentation

$_cacheIdentifier = null
protected
$_countSelect = null
protected
$_rowCount = null
protected
$_select = null
protected
const ROW_COUNT_COLUMN = 'zend_paginator_row_count'