Overview

Packages

  • Auth
  • Core
  • Horde
    • Imsp
  • None
  • Notification

Classes

  • Horde
  • Horde_Config
  • Horde_Config_Form
  • Horde_Core_ActiveSync_Connector
  • Horde_Core_ActiveSync_Driver
  • Horde_Core_Ajax_Application
  • Horde_Core_Ajax_Imple
  • Horde_Core_Ajax_Imple_AutoCompleter
  • Horde_Core_Ajax_Imple_Geocoder_Geonames
  • Horde_Core_Ajax_Imple_SpellChecker
  • Horde_Core_Alarm_Handler_Notify
  • Horde_Core_Auth_Application
  • Horde_Core_Auth_Composite
  • Horde_Core_Auth_Ldap
  • Horde_Core_Auth_Msad
  • Horde_Core_Auth_Shibboleth
  • Horde_Core_Auth_Signup_Base
  • Horde_Core_Auth_Signup_Form
  • Horde_Core_Auth_Signup_Null
  • Horde_Core_Auth_Signup_Sql
  • Horde_Core_Auth_Signup_SqlObject
  • Horde_Core_Autoloader_Callback_Mime
  • Horde_Core_Autoloader_Callback_Nls
  • Horde_Core_Block
  • Horde_Core_Block_Collection
  • Horde_Core_Block_Layout
  • Horde_Core_Block_Layout_Manager
  • Horde_Core_Block_Layout_View
  • Horde_Core_Block_Upgrade
  • Horde_Core_Browser
  • Horde_Core_Bundle
  • Horde_Core_Cli
  • Horde_Core_Controller_NotFound
  • Horde_Core_Controller_RequestConfiguration
  • Horde_Core_Controller_RequestMapper
  • Horde_Core_Controller_SettingsFinder
  • Horde_Core_Db_Migration
  • Horde_Core_Factory_ActiveSyncBackend
  • Horde_Core_Factory_ActiveSyncServer
  • Horde_Core_Factory_ActiveSyncState
  • Horde_Core_Factory_Ajax
  • Horde_Core_Factory_Alarm
  • Horde_Core_Factory_Auth
  • Horde_Core_Factory_AuthSignup
  • Horde_Core_Factory_Base
  • Horde_Core_Factory_BlockCollection
  • Horde_Core_Factory_Browser
  • Horde_Core_Factory_Cache
  • Horde_Core_Factory_Crypt
  • Horde_Core_Factory_Data
  • Horde_Core_Factory_Db
  • Horde_Core_Factory_DbBase
  • Horde_Core_Factory_DbPear
  • Horde_Core_Factory_Dns
  • Horde_Core_Factory_Editor
  • Horde_Core_Factory_Facebook
  • Horde_Core_Factory_Group
  • Horde_Core_Factory_History
  • Horde_Core_Factory_HttpClient
  • Horde_Core_Factory_Identity
  • Horde_Core_Factory_Image
  • Horde_Core_Factory_Imple
  • Horde_Core_Factory_Imsp
  • Horde_Core_Factory_ImspAuth
  • Horde_Core_Factory_Injector
  • Horde_Core_Factory_KolabServer
  • Horde_Core_Factory_KolabSession
  • Horde_Core_Factory_KolabStorage
  • Horde_Core_Factory_Ldap
  • Horde_Core_Factory_Lock
  • Horde_Core_Factory_Logger
  • Horde_Core_Factory_LoginTasks
  • Horde_Core_Factory_Mail
  • Horde_Core_Factory_Mapper
  • Horde_Core_Factory_Matcher
  • Horde_Core_Factory_Memcache
  • Horde_Core_Factory_MimeViewer
  • Horde_Core_Factory_Notification
  • Horde_Core_Factory_Perms
  • Horde_Core_Factory_PermsCore
  • Horde_Core_Factory_Prefs
  • Horde_Core_Factory_Request
  • Horde_Core_Factory_Secret
  • Horde_Core_Factory_SessionHandler
  • Horde_Core_Factory_Share
  • Horde_Core_Factory_ShareBase
  • Horde_Core_Factory_Template
  • Horde_Core_Factory_TextFilter
  • Horde_Core_Factory_ThemesCache
  • Horde_Core_Factory_Token
  • Horde_Core_Factory_Tree
  • Horde_Core_Factory_Twitter
  • Horde_Core_Factory_UrlShortener
  • Horde_Core_Factory_Vfs
  • Horde_Core_Factory_View
  • Horde_Core_Factory_Weather
  • Horde_Core_Group_Ldap
  • Horde_Core_Log_Logger
  • Horde_Core_LoginTasks
  • Horde_Core_LoginTasks_Backend_Horde
  • Horde_Core_LoginTasks_SystemTask_Upgrade
  • Horde_Core_Mime_Viewer_Syntaxhighlighter
  • Horde_Core_Mime_Viewer_Vcard
  • Horde_Core_Notification_Event_Status
  • Horde_Core_Notification_Handler_Decorator_Hordelog
  • Horde_Core_Notification_Storage_Session
  • Horde_Core_Perms
  • Horde_Core_Perms_Ui
  • Horde_Core_Prefs_Cache_Session
  • Horde_Core_Prefs_Identity
  • Horde_Core_Prefs_Storage_Configuration
  • Horde_Core_Prefs_Storage_Hooks
  • Horde_Core_Prefs_Storage_Upgrade
  • Horde_Core_Prefs_Ui
  • Horde_Core_Prefs_Ui_Widgets
  • Horde_Core_Share_Driver
  • Horde_Core_Share_FactoryCallback
  • Horde_Core_Sidebar
  • Horde_Core_Text_Filter_Bbcode
  • Horde_Core_Text_Filter_Emails
  • Horde_Core_Text_Filter_Emoticons
  • Horde_Core_Text_Filter_Highlightquotes
  • Horde_Core_Translation
  • Horde_Core_Tree_Html
  • Horde_Core_Tree_Javascript
  • Horde_Core_Tree_Simplehtml
  • Horde_Core_Ui_FlagImage
  • Horde_Core_Ui_JsCalendar
  • Horde_Core_Ui_Language
  • Horde_Core_Ui_Layout
  • Horde_Core_Ui_ModalFormRenderer
  • Horde_Core_Ui_Pager
  • Horde_Core_Ui_Tabs
  • Horde_Core_Ui_TagCloud
  • Horde_Core_Ui_VarRenderer
  • Horde_Core_Ui_VarRenderer_Html
  • Horde_Core_Ui_VarRenderer_TablesetHtml
  • Horde_Core_Ui_Widget
  • Horde_ErrorHandler
  • Horde_Help
  • Horde_Menu
  • Horde_Registry
  • Horde_Registry_Api
  • Horde_Registry_Application
  • Horde_Registry_Caller
  • Horde_Registry_Nlsconfig
  • Horde_Script_Files
  • Horde_Session
  • Horde_Session_Null
  • Horde_Themes
  • Horde_Themes_Cache
  • Horde_Themes_Css
  • Horde_Themes_Element
  • Horde_Themes_Image
  • Horde_Themes_Sound

Exceptions

  • Horde_Exception_HookNotSet
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * The Horde_Core_Ui_Pager:: provides links to individual pages.
  4:  *
  5:  * Copyright 2004-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * See the enclosed file COPYING for license information (LGPL). If you
  8:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
  9:  *
 10:  * @author   Ben Chavet <ben@chavet.net>
 11:  * @author   Joel Vandal <joel@scopserv.com>
 12:  * @author   Chuck Hagenbuch <chuck@horde.org>
 13:  * @category Horde
 14:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
 15:  * @package  Core
 16:  */
 17: class Horde_Core_Ui_Pager extends Horde_Core_Ui_Widget
 18: {
 19:     /**
 20:      * Constructor.
 21:      *
 22:      * TODO
 23:      */
 24:     public function __construct($name, $vars, $config)
 25:     {
 26:         $config = array_merge(array(
 27:             'page_limit' => 10,
 28:             'perpage' => 100
 29:         ), $config);
 30: 
 31:         parent::__construct($name, $vars, $config);
 32: 
 33:         // @todo Make sure 'url' argument is a Horde_Url object.
 34:         if (!($this->_config['url'] instanceof Horde_Url)) {
 35:             $this->_config['url'] = new Horde_Url($this->_config['url']);
 36:         }
 37:     }
 38: 
 39:     /**
 40:      * Render the pager.
 41:      *
 42:      * @return string  HTML code containing a centered table with the pager
 43:      *                 links.
 44:      */
 45:     public function render($data = null)
 46:     {
 47:         global $prefs, $registry, $conf;
 48: 
 49:         $num = $this->_config['num'];
 50:         $url = $this->_config['url'];
 51: 
 52:         $page_limit = $this->_config['page_limit'];
 53:         $perpage = $this->_config['perpage'];
 54: 
 55:         $current_page = $this->_vars->get($this->_name);
 56: 
 57:         // Figure out how many pages there will be.
 58:         $pages = ($num / $perpage);
 59:         if (is_integer($pages)) {
 60:             $pages--;
 61:         }
 62:         $pages = (int)$pages;
 63: 
 64:         // Return nothing if there is only one page.
 65:         if ($pages == 0 || $num == 0) {
 66:             return '';
 67:         }
 68: 
 69:         $html = '<div class="pager">';
 70: 
 71:         if ($current_page > 0) {
 72:             // Create the '<< Prev' link if we are not on the first page.
 73:             $link = $this->_link($this->_addPreserved($url->copy()->add($this->_name, $current_page - 1)));
 74: 
 75:             $prev_text = isset($this->_config['previousHTML'])
 76:                 ? $this->_config['previousHTML']
 77:                 : htmlspecialchars(Horde_Core_Translation::t("<Previous"));
 78: 
 79:             $html .= Horde::link($link, '', 'prev') . $prev_text . '</a>';
 80:         }
 81: 
 82:         // Figure out the top & bottom display limits.
 83:         $bottom = max(0, $current_page - ($page_limit / 2) + 1);
 84:         $top = $bottom + $page_limit - 1;
 85:         if ($top - 1 > $pages) {
 86:             $bottom -= ($top - 1) - $pages;
 87:             $top = $pages + 1;
 88:         }
 89: 
 90:         // Create bottom '[x-y]' link if necessary.
 91:         if ($bottom > 0) {
 92:             $link = $this->_link($this->_addPreserved($url->copy()->add($this->_name, $bottom - 1)));
 93:             $html .= ' ' . Horde::link($link, '', 'prevRange') . '[' . ($bottom == 1 ? $bottom : '1-' . $bottom) . ']</a>';
 94:         }
 95: 
 96:         // Create links to individual pages between limits.
 97:         for ($i = $bottom; $i <= $top && $i <= $pages; ++$i) {
 98:             if ($i == $current_page) {
 99:                 $html .= ' <strong>(' . ($i + 1) . ')</strong>';
100:             } elseif ($i >= 0 && $i <= $pages) {
101:                 $link = $this->_link($this->_addPreserved($url->copy()->add($this->_name, $i)));
102:                 $html .= ' ' . Horde::link($link) . ($i + 1) . '</a>';
103:             }
104:         }
105: 
106:         // Create top '[x-y]' link if necessary.
107:         if ($top < $pages) {
108:             $link = $this->_link($this->_addPreserved($url->copy()->add($this->_name, $top + 1)));
109: 
110:             $html .= ' ' . Horde::link($link, '', 'nextRange') . '[' .
111:                 ($top + 2 == $pages + 1 ? $pages + 1 : ($top + 2) . '-' . ($pages + 1)) . ']</a>';
112:         }
113: 
114:         // Create the 'Next>>' link if we are not on the last page.
115:         if ($current_page < $pages) {
116:             $link = $this->_link($this->_addPreserved($url->copy()->add($this->_name, $current_page + 1)));
117: 
118:             $next_text = isset($this->_config['nextHTML'])
119:                 ? $this->_config['nextHTML']
120:                 : htmlspecialchars(Horde_Core_Translation::t("Next>"));
121: 
122:             $html .= ' ' . Horde::link($link, '', 'next') . $next_text . '</a>';
123:         }
124: 
125:         return $html . '</div>';
126:     }
127: 
128: }
129: 
API documentation generated by ApiGen