Source for file PropelPager.php
Documentation is available at PropelPager.php
* $Id: PropelPager.php 563 2007-02-01 09:45:55Z heltem $
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://propel.phpdb.org>.
* require_once 'propel/util/PropelPager.php';
* require_once 'PEACH/Propel/Poem/poemPeer.php';
* $c->addDescendingOrderByColumn(poemPeer::SID);
* $pager = new PropelPager($c, 'poemPeer', 'doSelectJoinPoemUsers', 1, 50);
* $pager = new PropelPager($c, 'poemPeer', 'doSelect', 1, 50);
* Total Pages: <?=$pager->getTotalPages()?> Total Records: <?=$pager->getTotalRecordCount()?>
* <?if ($link = $pager->getFirstPage):?>
* <a href="somescript?page=<?=$link?>"><?=$link?></a>|
* <?if ($link = $pager->getPrev()):?>
* <a href="somescript?page=<?=$link?>">Previous</a>|
* <?foreach ($pager->getPrevLinks() as $link):?>
* <a href="somescript?page=<?=$link?>"><?=$link?></a>|
* <td><?=$pager->getPage()?></td>
* <?foreach ($pager->getNextLinks() as $link):?>
* | <a href="somescript?page=<?=$link?>"><?=$link?></a>
* <?if ($link = $pager->getNext()):?>
* <a href="somescript?page=<?=$link?>">Last</a>|
* <?if ($link = $pager->getLastPage()):?>
* <a href="somescript?page=<?=$link?>"><?=$link?></a>|
* <table id="latestPoems">
* <?foreach ($pager->getResult() as $poem):?>
* <td><?=$poem->getTitle()?></td>
* <td><?=$poem->getPoemUsers()->getUname()?></td>
* <td><?=$poem->getTime()?></td>
* <td><?=$poem->getComments()?></td>
* @author Rob Halff <info@rhalff.com>
* @version $Revision: 563 $
* @copyright Copyright (c) 2004 Rob Halff: LGPL - See LICENCE
private $peerSelectMethod;
private $peerCountMethod;
/** @var int Start row (offset) */
/** @var int Max rows to return (0 means all) */
* Create a new Propel Pager.
* @param string $peerClass The name of the static Peer class.
* @param string $peerSelectMethod The name of the static method for selecting content from the Peer class.
* @param int $page The current page (1-based).
* @param int $rowsPerPage The number of rows that should be displayed per page.
public function __construct($c = null, $peerClass = null, $peerSelectMethod = null, $page = 1, $rowsPerPage = 25)
$this->guessPeerCountMethod();
* Set the criteria for this pager.
* Return the Criteria object for this pager.
$this->peerClass = $class;
* Return the Peer Classname.
* Set the Peer select method.
* This exists for legacy support, please use setPeerSelectMethod().
* @param string $method The name of the static method to call on the Peer class.
* @see setPeerSelectMethod()
* Return the Peer select method.
* This exists for legacy support, please use getPeerSelectMethod().
* @see getPeerSelectMethod()
* Set the Peer select method.
* @param string $method The name of the static method to call on the Peer class.
$this->peerSelectMethod = $method;
* Return the Peer select method.
return $this->peerSelectMethod;
* This is set based on the Peer method, for example if Peer method is doSelectJoin*() then the
* count method will be doCountJoin*().
* @param string $method The name of the static method to call on the Peer class.
$this->peerCountMethod = $method;
* Return the Peer count method.
return $this->peerCountMethod;
* Guesses the Peer count method based on the select method.
private function guessPeerCountMethod()
if ($selectMethod == 'doSelect') {
$countMethod = 'doCount';
} elseif ( ($pos = stripos($selectMethod, 'doSelectJoin')) === 0) {
$countMethod = 'doCount' . substr($selectMethod, strlen('doSelect'));
// we will fall back to doCount() if we don't understand the join
// method; however, it probably won't be accurate. Maybe triggering an error would
$countMethod = 'doCount';
* Get the paged resultset
* Get the paged resultset
* Main method which creates a paged result set based on the criteria
* and the requested peer select method.
$this->criteria->setOffset($this->start);
$this->criteria->setLimit($this->max);
* For now I can only think of returning 1 always.
* It should probably return 0 if there are no pages
* Convenience method to indicate whether current page is the first page.
* Convenience method to indicate whether current page is the last page.
* @return int $this->pages
if (!isset ($this->pages)) {
$this->pages = ceil($recordCount/ $this->max);
* get an array of previous id's
for ($i= $start; $i> $end; $i-- ) {
* get an array of next id's
for ($i= $start; $i< $end; $i++ ) {
* Returns whether last page is complete
* @return bool Last page complete or not
* Set the current page number (First page is 1).
// (re-)calculate start rec
* Set the number of rows per page.
// (re-)calculate start rec
* Get number of rows per page.
* Calculate startrow / max rows based on current page and rows-per-page.
private function calculateStart()
$this->start = ( ($this->page - 1) * $this->max );
* Gets the total number of (un-LIMITed) records.
* This method will perform a query that executes un-LIMITed query.
* @return int Total number of records - disregarding page, maxrows, etc.
if (empty($this->recordCount)) {
$this->countCriteria = clone $this->criteria;
$this->countCriteria->setLimit(0);
$this->countCriteria->setOffset(0);
return $this->recordCount;
* Sets the start row or offset.
|