PagedQuery.php

Go to the documentation of this file.
00001 <?php 00002 00003 /* 00004 * $Id: PagedQuery.php,v 1.4 2004/04/24 14:43:07 hlellelid Exp $ 00005 * 00006 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00007 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00008 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00009 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00010 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00011 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00012 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00013 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00014 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00015 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00016 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00017 * 00018 * This software consists of voluntary contributions made by many individuals 00019 * and is licensed under the LGPL. For more information please see 00020 * <http://creole.phpdb.org>. 00021 */ 00022 00023 require_once 'jargon/Query.php'; 00024 00035 class PagedQuery extends Query { 00036 00038 private $page; 00039 00045 public function __construct(Connection $conn, $sql = null, $page = 1, $rowsPerPage = 25) 00046 { 00047 parent::__construct($conn, $sql); 00048 $this->setRowsPerPage($rowsPerPage); 00049 $this->setPage($page); 00050 } 00051 00057 public function setPage($p) 00058 { 00059 $this->page = $page; 00060 // (re-)calculate start rec 00061 $this->calculateStart(); 00062 } 00063 00068 public function getPage() 00069 { 00070 return $this->page; 00071 } 00072 00077 public function setRowsPerPage($r) 00078 { 00079 $this->max = $r; 00080 // (re-)calculate start rec 00081 $this->calculateStart(); 00082 } 00083 00088 public function getRowsPerPage() 00089 { 00090 return $this->max; 00091 } 00092 00097 private function calculateStart() 00098 { 00099 $this->start = ( ($this->page - 1) * $this->max ); 00100 } 00101 00112 public function getTotalRecordCount() 00113 { 00114 $rs = $this->conn->createStatement()->executeQuery($this->sql); 00115 return $rs->getRecordCount(); 00116 } 00117 00118 } 00119

This file is part of the Creole[php5] library.


Copyright © 2004 Hans Lellelid  
Creole[php5] CVS