[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 3 require_once dirname(__FILE__) . '/Widget.php'; 4 5 /** 6 * The Horde_UI_Pager:: provides links to individual pages. 7 * 8 * $Horde: framework/UI/UI/Pager.php,v 1.7.10.8 2006/06/20 09:08:26 jan Exp $ 9 * 10 * Copyright 2004-2006 Joel Vandal <jvandal@infoteck.qc.ca> 11 * 12 * See the enclosed file COPYING for license information (LGPL). If you 13 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 14 * 15 * @author Ben Chavet <ben@chavet.net> 16 * @author Joel Vandal <jvandal@infoteck.qc.ca> 17 * @author Chuck Hagenbuch <chuck@horde.org> 18 * @since Horde_UI 0.0.1 19 * @package Horde_UI 20 */ 21 class Horde_UI_Pager extends Horde_UI_Widget { 22 23 function Horde_UI_Pager($name, &$vars, $config) 24 { 25 if (!isset($config['page_limit'])) { 26 $config['page_limit'] = 10; 27 } 28 if (!isset($config['perpage'])) { 29 $config['perpage'] = 100; 30 } 31 parent::Horde_UI_Widget($name, $vars, $config); 32 } 33 34 /** 35 * Render the pager. 36 * 37 * @return string HTML code containing a centered table with the pager 38 * links. 39 */ 40 function render() 41 { 42 global $prefs, $registry, $conf; 43 44 $num = $this->_config['num']; 45 $url = $this->_config['url']; 46 $page_limit = $this->_config['page_limit']; 47 $perpage = $this->_config['perpage']; 48 49 $current_page = $this->_vars->get($this->_name); 50 51 // Figure out how many pages there will be. 52 $pages = ($num / $perpage); 53 if (is_integer($pages)) { 54 $pages--; 55 } 56 $pages = (int)$pages; 57 58 // Return nothing if there is only one page. 59 if ($pages == 0 || $num == 0) { 60 return ''; 61 } 62 63 $html = '<div class="pager">'; 64 65 // Create the '<< Prev' link if we are not on the first page. 66 $link = Util::addParameter($url, $this->_name, $current_page - 1); 67 $link = $this->_addPreserved($link); 68 if ($current_page > 0) { 69 $html .= Horde::link(Horde::applicationUrl($link), '', 'prev') . htmlspecialchars(_("<Previous")) . '</a>'; 70 } 71 72 // Figure out the top & bottom display limits. 73 $bottom = max(0, $current_page - ($page_limit / 2) + 1); 74 $top = $bottom + $page_limit - 1; 75 if ($top - 1 > $pages) { 76 $bottom -= ($top - 1) - $pages; 77 $top = $pages + 1; 78 } 79 80 // Create bottom '[x-y]' link if necessary. 81 $link = $this->_addPreserved(Util::addParameter($url, $this->_name, $bottom - 1)); 82 if ($bottom > 0) { 83 $html .= ' ' . Horde::link(Horde::applicationUrl($link), '', 'prevRange') . '[' . ($bottom == 1 ? $bottom : '1-' . $bottom) . ']</a>'; 84 } 85 86 // Create links to individual pages between limits. 87 for ($i = $bottom; $i <= $top && $i <= $pages; ++$i) { 88 if ($i == $current_page) { 89 $html .= ' <strong>(' . ($i + 1) . ')</strong>'; 90 } elseif ($i >= 0 && $i <= $pages) { 91 $link = $this->_addPreserved(Util::addParameter($url, $this->_name, $i)); 92 $html .= ' ' . Horde::link(Horde::applicationUrl($link)) . ($i + 1) . '</a>'; 93 } 94 } 95 96 // Create top '[x-y]' link if necessary. 97 if ($top < $pages) { 98 $link = $this->_addPreserved(Util::addParameter($url, $this->_name, $top + 1)); 99 $html .= ' ' . Horde::link(Horde::applicationUrl($link), '', 'nextRange') . '[' . 100 ($top + 2 == $pages + 1 ? $pages + 1 : ($top + 2) . '-' . ($pages + 1)) . ']</a>'; 101 } 102 103 // Create the 'Next>>' link if we are not on the last page. 104 if ($current_page < $pages) { 105 $link = $this->_addPreserved(Util::addParameter($url, $this->_name, $current_page + 1)); 106 $html .= ' ' . Horde::link(Horde::applicationUrl($link), '', 'next') . htmlspecialchars(_("Next>")) . '</a>'; 107 } 108 109 return $html . '</div>'; 110 } 111 112 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |