Minahito
minah****@users*****
2006年 10月 6日 (金) 20:14:36 JST
Index: xoops2jp/html/core/XCube_PageNavigator.class.php diff -u xoops2jp/html/core/XCube_PageNavigator.class.php:1.1.2.1 xoops2jp/html/core/XCube_PageNavigator.class.php:1.1.2.2 --- xoops2jp/html/core/XCube_PageNavigator.class.php:1.1.2.1 Fri Sep 29 17:13:22 2006 +++ xoops2jp/html/core/XCube_PageNavigator.class.php Fri Oct 6 20:14:36 2006 @@ -1,55 +1,149 @@ <?php /** * @package XCube - * @version $Id: XCube_PageNavigator.class.php,v 1.1.2.1 2006/09/29 08:13:22 minahito Exp $ + * @version $Id: XCube_PageNavigator.class.php,v 1.1.2.2 2006/10/06 11:14:36 minahito Exp $ */ -define("XCUBE_PAGENAVI_START",1); -define("XCUBE_PAGENAVI_PERPAGE",2); +define('XCUBE_PAGENAVI_START', 1); +define('XCUBE_PAGENAVI_PERPAGE', 2); + +define('XCUBE_PAGENAVI_SORT', 1); +define('XCUBE_PAGENAVI_PAGE', 4); + /** - * This is a class in a semiautomatic that acquires page navigation information. + * This is a utility class which acquires page navigation informations + * --- sort, offset and limit --- semiautomatically. And, the base modules may + * offer place holders which is able to connect with interfaces of this class. */ class XCube_PageNavigator { - var $mStart=0; - var $mTotal=0; + /** + * Array for extra informations. + * @var Array + */ + var $mAttributes = array(); + + /** + * Offset. + * @var int + */ + var $mStart = 0; + + /** + * The max number of items which this navigator handles. + * @var int + */ + var $mTotal = 0; + /** + * The value indicating whether the mTotal property already has been + * specified. + * @var bool + */ + var $_mIsSpecifedTotal = false; + + /** + * This delegate is used in only case which mTotal isn't set yet. + * + * void getTotal(int &total, const XCube_Navigator); + * + * @var XCube_Delegate + */ + var $mGetTotal = null; + + /** + * Per page. + * @var int + */ var $mPerpage = 20; + + /** + * Flag indicating whether this class receives the perpage value specified + * by the request. + * @var bool + */ var $mPerpageFreeze = false; - var $mUrl=null; + /** + * Array for sort. + * @var Array + */ + var $mSort = array(); + /** + * The base url for this navigator. + * @var string + */ + var $mUrl = ""; + + /** + * A prefix for variable names fetched by this navigator. If two independent + * navigators are used, this property is must. + */ var $mPrefix = null; - var $mExtra=array(); + /** + * Array of string for re-building the query strings. + */ + var $mExtra = array(); - var $mFlags=0; + /** + * Options indicating what this navigator fetches automatically. + */ + var $mFlags = 0; + /** + * @XCube_Delegate + */ + var $mExtraFetch = null; + + /** + * Constructor. + * @param string $url + * @param int $total + * @param int flag + */ function XCube_PageNavigator($url, $total=0, $flags=0) { $this->mUrl = $url; $this->setTotal($total); $this->mFlags = $flags; + + $this->mExtraFetch =& new XCube_Delegate(); } + /** + * Gets values which this navigator handles, from the request. And, sets + * values to this object's properties. + */ function fetch() { + $root =& XCube_Root::getSingleton(); + $startKey = $this->getStartKey(); $perpageKey = $this->getPerpageKey(); - - if ($this->mFlags & XCUBE_PAGENAVI_START && isset($_REQUEST[$startKey])) { - $this->mStart = intval($_REQUEST[$startKey]); + + if ($this->mFlags & XCUBE_PAGENAVI_START) { + $t_start = $root->mContext->mRequest->getRequest($this->getStartKey()); + if ($t_start != null && intval($t_start) >= 0) { + $this->mStart = intval($t_start); + } } - if ($this->mFlags & XCUBE_PAGENAVI_PERPAGE && isset($_REQUEST[$perpageKey]) && !$this->mPerpageFreeze) { - $this->mPerpage = intval($_REQUEST[$perpageKey]); + if ($this->mFlags & XCUBE_PAGENAVI_PERPAGE && !$this->mPerpageFreeze) { + $t_perpage = $root->mContext->mRequest->getRequest($this->getPerpageKey()); + if ($t_perpage != null && intval($t_perpage) >= 0) { + $this->mPerpage = intval($t_perpage); + } } + + $this->mExtraFetch->call(new XCube_Ref($this)); } - function addExtra($key,$value) + function addExtra($key, $value) { - $this->mExtra[$key]=$value; + $this->mExtra[$key] = $value; } function removeExtra($key) @@ -135,10 +229,15 @@ function setTotal($total) { $this->mTotal = intval($total); + $this->_mIsSpecifiedTotal = true; } function getTotal() { + if (!$this->_mIsSpecifiedTotal) { + $this->mGetTotal->call(new XCube_Ref($this->mTotal), $this); + } + return $this->mTotal; }