[ Index ] |
|
Code source de Joomla 1.0.13 |
1 <?php 2 /** 3 * @version $Id: pageNavigation.php 5513 2006-10-19 12:17:15Z friesengeist $ 4 * @package Joomla 5 * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved. 6 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php 7 * Joomla! is free software. This version may have been modified pursuant 8 * to the GNU General Public License, and as distributed it includes or 9 * is derivative of works licensed under the GNU General Public License or 10 * other free or open source software licenses. 11 * See COPYRIGHT.php for copyright notices and details. 12 */ 13 14 // no direct access 15 defined( '_VALID_MOS' ) or die( 'Restricted access' ); 16 17 /** 18 * Page navigation support class 19 * @package Joomla 20 */ 21 class mosPageNav { 22 /** @var int The record number to start dislpaying from */ 23 var $limitstart = null; 24 /** @var int Number of rows to display per page */ 25 var $limit = null; 26 /** @var int Total number of rows */ 27 var $total = null; 28 29 function mosPageNav( $total, $limitstart, $limit ) { 30 $this->total = (int) $total; 31 $this->limitstart = (int) max( $limitstart, 0 ); 32 $this->limit = (int) max( $limit, 0 ); 33 } 34 /** 35 * Returns the html limit # input box 36 * @param string The basic link to include in the href 37 * @return string 38 */ 39 function getLimitBox ( $link ) { 40 $limits = array(); 41 for ($i=5; $i <= 30; $i+=5) { 42 $limits[] = mosHTML::makeOption( "$i" ); 43 } 44 $limits[] = mosHTML::makeOption( "50" ); 45 46 // build the html select list 47 $link = $link ."&limit=' + this.options[selectedIndex].value + '&limitstart=". $this->limitstart; 48 $link = sefRelToAbs( $link ); 49 return mosHTML::selectList( $limits, 'limit', 'class="inputbox" size="1" onchange="document.location.href=\''. $link .'\';"', 'value', 'text', $this->limit ); 50 } 51 /** 52 * Writes the html limit # input box 53 * @param string The basic link to include in the href 54 */ 55 function writeLimitBox ( $link ) { 56 echo mosPageNav::getLimitBox( $link ); 57 } 58 /** 59 * Writes the html for the pages counter, eg, Results 1-10 of x 60 */ 61 function writePagesCounter() { 62 $txt = ''; 63 $from_result = $this->limitstart+1; 64 if ($this->limitstart + $this->limit < $this->total) { 65 $to_result = $this->limitstart + $this->limit; 66 } else { 67 $to_result = $this->total; 68 } 69 if ($this->total > 0) { 70 $txt .= _PN_RESULTS." $from_result - $to_result "._PN_OF." $this->total"; 71 } 72 return $to_result ? $txt : ''; 73 } 74 75 /** 76 * Writes the html for the leafs counter, eg, Page 1 of x 77 */ 78 function writeLeafsCounter() { 79 $txt = ''; 80 $page = ceil( ($this->limitstart + 1) / $this->limit ); 81 if ($this->total > 0) { 82 $total_pages = ceil( $this->total / $this->limit ); 83 $txt .= _PN_PAGE." $page "._PN_OF." $total_pages"; 84 } 85 return $txt; 86 } 87 88 /** 89 * Writes the html links for pages, eg, previous, next, 1 2 3 ... x 90 * @param string The basic link to include in the href 91 */ 92 function writePagesLinks( $link ) { 93 $txt = ''; 94 95 $displayed_pages = 10; 96 $total_pages = $this->limit ? ceil( $this->total / $this->limit ) : 0; 97 $this_page = $this->limit ? ceil( ($this->limitstart+1) / $this->limit ) : 1; 98 $start_loop = (floor(($this_page-1)/$displayed_pages))*$displayed_pages+1; 99 if ($start_loop + $displayed_pages - 1 < $total_pages) { 100 $stop_loop = $start_loop + $displayed_pages - 1; 101 } else { 102 $stop_loop = $total_pages; 103 } 104 105 $link .= '&limit='. $this->limit; 106 107 if (!defined( '_PN_LT' ) || !defined( '_PN_RT' ) ) { 108 DEFINE('_PN_LT','<'); 109 DEFINE('_PN_RT','>'); 110 } 111 112 $pnSpace = ''; 113 if (_PN_LT || _PN_RT) $pnSpace = " "; 114 115 if ($this_page > 1) { 116 $page = ($this_page - 2) * $this->limit; 117 $txt .= '<a href="'. sefRelToAbs( "$link&limitstart=0" ) .'" class="pagenav" title="'. _PN_START .'">'. _PN_LT . _PN_LT . $pnSpace . _PN_START .'</a> '; 118 $txt .= '<a href="'. sefRelToAbs( "$link&limitstart=$page" ) .'" class="pagenav" title="'. _PN_PREVIOUS .'">'. _PN_LT . $pnSpace . _PN_PREVIOUS .'</a> '; 119 } else { 120 $txt .= '<span class="pagenav">'. _PN_LT . _PN_LT . $pnSpace . _PN_START .'</span> '; 121 $txt .= '<span class="pagenav">'. _PN_LT . $pnSpace . _PN_PREVIOUS .'</span> '; 122 } 123 124 for ($i=$start_loop; $i <= $stop_loop; $i++) { 125 $page = ($i - 1) * $this->limit; 126 if ($i == $this_page) { 127 $txt .= '<span class="pagenav">'. $i .'</span> '; 128 } else { 129 $txt .= '<a href="'. sefRelToAbs( $link .'&limitstart='. $page ) .'" class="pagenav"><strong>'. $i .'</strong></a> '; 130 } 131 } 132 133 if ($this_page < $total_pages) { 134 $page = $this_page * $this->limit; 135 $end_page = ($total_pages-1) * $this->limit; 136 $txt .= '<a href="'. sefRelToAbs( $link .'&limitstart='. $page ) .' " class="pagenav" title="'. _PN_NEXT .'">'. _PN_NEXT . $pnSpace . _PN_RT .'</a> '; 137 $txt .= '<a href="'. sefRelToAbs( $link .'&limitstart='. $end_page ) .' " class="pagenav" title="'. _PN_END .'">'. _PN_END . $pnSpace . _PN_RT . _PN_RT .'</a>'; 138 } else { 139 $txt .= '<span class="pagenav">'. _PN_NEXT . $pnSpace . _PN_RT .'</span> '; 140 $txt .= '<span class="pagenav">'. _PN_END . $pnSpace . _PN_RT . _PN_RT .'</span>'; 141 } 142 return $txt; 143 } 144 /** 145 * Sets the vars {PAGE_LINKS}, {PAGE_LIST_OPTIONS} and {PAGE_COUNTER} for the page navigation template 146 * @param object The patTemplate object 147 * @param string The full link to be used in the nav link, eg index.php?option=com_content 148 * @param string The name of the template to add the variables 149 */ 150 function setTemplateVars( &$tmpl, $link = '', $name = 'admin-list-footer' ) { 151 $tmpl->addVar( $name, 'PAGE_LINKS', $this->writePagesLinks( $link ) ); 152 $tmpl->addVar( $name, 'PAGE_LIST_OPTIONS', $this->getLimitBox( $link ) ); 153 $tmpl->addVar( $name, 'PAGE_COUNTER', $this->writePagesCounter() ); 154 } 155 } 156 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 14:43:32 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |