cvs: pear /Structures_DataGrid/DataGrid Core.php

From: Date: Fri, 27 May 2005 14:42:51 +0000
Subject: cvs: pear /Structures_DataGrid/DataGrid Core.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-32155@lists.php.net to get a copy of this message
asnagy Fri May 27 10:42:51 2005 EDT Modified files: /pear/Structures_DataGrid/DataGrid Core.php Log: Added 4 new core functions that retrieve some statistical data about the datagrid paging. (Bug #4416) Provided by Mark Wiesemann. http://cvs.php.net/diff.php/pear/Structures_DataGrid/DataGrid/Core.php?r1=1.28&r2=1.29&ty=u Index: pear/Structures_DataGrid/DataGrid/Core.php diff -u pear/Structures_DataGrid/DataGrid/Core.php:1.28 pear/Structures_DataGrid/DataGrid/Core.php:1.29 --- pear/Structures_DataGrid/DataGrid/Core.php:1.28 Thu Jan 27 17:18:15 2005 +++ pear/Structures_DataGrid/DataGrid/Core.php Fri May 27 10:42:50 2005 @@ -16,7 +16,7 @@ // | Author: Andrew Nagy <asnagy@webitecture.org> | // +----------------------------------------------------------------------+ // -// $Id: Core.php,v 1.28 2005/01/27 22:18:15 asnagy Exp $ +// $Id: Core.php,v 1.29 2005/05/27 14:42:50 asnagy Exp $ require_once 'Structures/DataGrid/Column.php'; require_once 'Structures/DataGrid/Record.php'; @@ -28,7 +28,7 @@ * It offers the paging and sorting methods as well as the record and column * management methods. * - * @version $Revision: 1.28 $ + * @version $Revision: 1.29 $ * @author Andrew S. Nagy <asnagy@webitecture.org> * @access public * @package Structures_DataGrid @@ -126,8 +126,74 @@ { $this->page = $page; } + + /** + * Returns the total number of pages + * (returns 0 if there are no records, returns 1 if there is no row limit) + * + * @return string the total number of pages + * @access public + */ + function getPageCount() + { + if (is_null($this->rowLimit) || $this->getRecordCount() == 0) { + return 1; + } else { + return ceil($this->getRecordCount() / $this->rowLimit); + } + } + + /** + * Returns the total number of records + * + * @return string the total number of records + * @access public + */ + function getRecordCount() + { + if ($this->_dataSource != null) { + return $this->_dataSource->count(); + } else { + return count($this->recordSet); + } + } + + /** + * Returns the number of the first record of the current page + * (returns 0 if there are no records, returns 1 if there is no row limit) + * + * @return string the number of the first record currently shown + * @access public + */ + function getCurrentRecordNumberStart() + { + if (is_null($this->page)) { + return 1; + } elseif ($this->getRecordCount() == 0) { + return 0; + } else { + return ($this->page - 1) * $this->rowLimit + 1; + } + } /** + * Returns the number of the last record of the current page + * + * @return string the number of the last record currently shown + * @access public + */ + function getCurrentRecordNumberEnd() + { + if (is_null($this->rowLimit)) { + return $this->getRecordCount(); + } else { + return + min($this->getCurrentRecordNumberStart() + $this->rowLimit - 1, + $this->getRecordCount()); + } + } + + /** * If you need to change the request variables, you can define a prefix. * This is extra useful when using multiple datagrids. *

« previous php.pear.cvs (#32155) next »