Minahito
minah****@users*****
2006年 10月 12日 (木) 20:00:45 JST
Index: xoops2jp/html/core/XCube_PageNavigator.class.php diff -u xoops2jp/html/core/XCube_PageNavigator.class.php:1.1.2.2 xoops2jp/html/core/XCube_PageNavigator.class.php:1.1.2.3 --- xoops2jp/html/core/XCube_PageNavigator.class.php:1.1.2.2 Fri Oct 6 20:14:36 2006 +++ xoops2jp/html/core/XCube_PageNavigator.class.php Thu Oct 12 20:00:45 2006 @@ -1,7 +1,7 @@ <?php /** * @package XCube - * @version $Id: XCube_PageNavigator.class.php,v 1.1.2.2 2006/10/06 11:14:36 minahito Exp $ + * @version $Id: XCube_PageNavigator.class.php,v 1.1.2.3 2006/10/12 11:00:45 minahito Exp $ */ define('XCUBE_PAGENAVI_START', 1); @@ -34,29 +34,13 @@ * The max number of items which this navigator handles. * @var int */ - var $mTotal = 0; + var $mTotalItems = 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; + var $mPerpage = 5; /** * Flag indicating whether this class receives the perpage value specified @@ -96,7 +80,24 @@ /** * @XCube_Delegate */ - var $mExtraFetch = null; + var $mFetch = null; + + /** + * The value indicating whether the mTotal property already has been + * specified. + * @var bool + */ + var $_mIsSpecifedTotalItems = 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 $mGetTotalItems = null; + /** * Constructor. @@ -104,13 +105,15 @@ * @param int $total * @param int flag */ - function XCube_PageNavigator($url, $total=0, $flags=0) + function XCube_PageNavigator($url, $flags = XCUBE_PAGENAVI_START) { $this->mUrl = $url; - $this->setTotal($total); $this->mFlags = $flags; - $this->mExtraFetch =& new XCube_Delegate(); + $this->mFetch =& new XCube_Delegate(); + $this->mFetch->add(array(&$this, 'fetchNaviControl')); + + $this->mGetTotalItems =& new XCube_Delegate(); } /** @@ -119,6 +122,11 @@ */ function fetch() { + $this->mFetch->call(new XCube_Ref($this)); + } + + function fetchNaviControl() + { $root =& XCube_Root::getSingleton(); $startKey = $this->getStartKey(); @@ -137,8 +145,6 @@ $this->mPerpage = intval($t_perpage); } } - - $this->mExtraFetch->call(new XCube_Ref($this)); } function addExtra($key, $value) @@ -208,6 +214,56 @@ return $url . $demiliter . $this->getStartKey() . "="; } + function renderUrlForSort() + { + if(count($this->mExtra) > 0) { + $tarr=array(); + + foreach($this->mExtra as $key=>$value) { + $tarr[]=$key."=".urlencode($value); + } + + $tarr[] = $this->getPerpageKey() . "=" . $this->mPerpage; + + if(strpos($this->mUrl,"?")!==false) { + return $this->mUrl."&".implode("&",$tarr); + } + else { + return $this->mUrl."?".implode("&",$tarr); + } + } + + return $this->mUrl; + } + + function renderUrlForPage($page = null) + { + $tarr=array(); + + foreach($this->mExtra as $key=>$value) { + $tarr[]=$key."=".urlencode($value); + } + + foreach($this->mSort as $key=>$value) { + $tarr[]=$key."=".urlencode($value); + } + + $tarr[] = $this->getPerpageKey() . "=" . $this->getPerpage(); + + if ($page !== null) { + $tarr[] = $this->getStartKey() . '=' . intval($page); + } + + if(strpos($this->mUrl,"?")!==false) { + return $this->mUrl."&".implode("&",$tarr); + } + else { + return $this->mUrl."?".implode("&",$tarr); + } + + return $this->mUrl; + } + /** * Return url string for sort. The return value is complete style. */ @@ -226,21 +282,30 @@ return $this->mStart; } - function setTotal($total) + function setTotalItems($total) { $this->mTotal = intval($total); $this->_mIsSpecifiedTotal = true; } - function getTotal() + function getTotalItems() { - if (!$this->_mIsSpecifiedTotal) { - $this->mGetTotal->call(new XCube_Ref($this->mTotal), $this); + if ($this->_mIsSpecifedTotalItems == false) { + $total = 0; + $this->mGetTotalItems->call(new XCube_Ref($total)); + $this->setTotalItems($total); + + $this->_mIsSpecifedTotalItems = true; } return $this->mTotal; } + function getTotalPages() + { + return ceil($this->getTotalItems() / $this->getPerpage()); + } + function setPerpage($perpage) { $this->mPerpage = intval($perpage); @@ -275,6 +340,35 @@ { return $this->mPrefix . "perpage"; } + + function getCurrentPage() + { + return intval(floor(($this->getStart() + $this->getPerpage()) / $this->getPerpage())); + } + + function hasPrivPage() + { + return ($this->getStart() - $this->getPerpage()) >= 0; + } + + function getPrivStart() + { + $prev = $this->getStart() - $this->getPerpage(); + + return ($prev > 0) ? $prev : 0; + } + + function hasNextPage() + { + return $this->getTotalItems() > ($this->getStart() + $this->getPerpage()); + } + + function getNextStart() + { + $next = $this->getStart() + $this->getPerpage(); + + return ($this->getTotalItems() > $next) ? $next : 0; + } } ?> \ No newline at end of file