Changeset 136 for trunk/lib/PageNumbers.inc.php
- Timestamp:
- Jun 3, 2006 7:47:48 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/PageNumbers.inc.php
r111 r136 4 4 * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information 5 5 * 6 * The PageNumbers ::class provides a common abstracted interface to the6 * The PageNumbers class provides a common abstracted interface to the 7 7 * multiple pages features. It sets the various numbers needed to display items 8 8 * on a page, and includes functions for working with these numbers. … … 72 72 function setPerPage($per_page, $default=25, $save_value=true) 73 73 { 74 // (1) By provided argument, if valid. 74 $prefs =& Prefs::getInstance(); 75 76 // (1) By provided argument, if valid. 75 77 // (2) By saved preference, if available. 76 78 // (3) Set to default value if provided and valid. … … 79 81 $this->_per_page = $per_page; 80 82 if ($save_value) { 81 Prefs::setValue('items_per_page', $this->_per_page, $_SERVER['PHP_SELF']);82 } 83 } else if ($save_value && Prefs::exists('items_per_page', $_SERVER['PHP_SELF'])) {84 $this->_per_page = (int) Prefs::getValue('items_per_page', $_SERVER['PHP_SELF']);83 $prefs->set('items_per_page', $this->_per_page, $_SERVER['PHP_SELF']); 84 } 85 } else if ($save_value && $prefs->exists('items_per_page', $_SERVER['PHP_SELF'])) { 86 $this->_per_page = (int)$prefs->get('items_per_page', $_SERVER['PHP_SELF']); 85 87 } else if (is_numeric($default) && $default > 0) { 86 88 $this->_per_page = $default; … … 94 96 function setPageNumber($page_number, $save_value=true) 95 97 { 96 // (1) By provided argument, if valid. 98 $prefs =& Prefs::getInstance(); 99 100 // (1) By provided argument, if valid. 97 101 // (2) By saved preference, if available. 98 102 // (3) Don't change from what was provided at class instantiation. … … 105 109 } 106 110 if ($save_value) { 107 Prefs::setValue('page_number', $this->current_page, $_SERVER['PHP_SELF']);108 } 109 } else if ($save_value && Prefs::exists('page_number', $_SERVER['PHP_SELF'])) {110 $this->current_page = (int) Prefs::getValue('page_number', $_SERVER['PHP_SELF']);111 $prefs->set('page_number', $this->current_page, $_SERVER['PHP_SELF']); 112 } 113 } else if ($save_value && $prefs->exists('page_number', $_SERVER['PHP_SELF'])) { 114 $this->current_page = (int)$prefs->get('page_number', $_SERVER['PHP_SELF']); 111 115 } 112 116 $this->set_page_number_initialized = true; … … 137 141 function calculate() 138 142 { 143 $app =& App::getInstance(); 144 139 145 if (!$this->set_per_page_initialized) { 140 App::logMsg(sprintf('set_per_page not initialized'), LOG_ERR, __FILE__, __LINE__);146 $app->logMsg(sprintf('set_per_page not initialized'), LOG_ERR, __FILE__, __LINE__); 141 147 } 142 148 if (!$this->set_page_number_initialized) { 143 App::logMsg(sprintf('set_page_number not initialized'), LOG_ERR, __FILE__, __LINE__);149 $app->logMsg(sprintf('set_page_number not initialized'), LOG_ERR, __FILE__, __LINE__); 144 150 } 145 151 if (!$this->set_total_items_initialized) { 146 App::logMsg(sprintf('set_total_items not initialized'), LOG_ERR, __FILE__, __LINE__);152 $app->logMsg(sprintf('set_total_items not initialized'), LOG_ERR, __FILE__, __LINE__); 147 153 } 148 154 … … 189 195 function getLimitSQL() 190 196 { 197 $app =& App::getInstance(); 198 $db =& DB::getInstance(); 199 191 200 if (is_numeric($this->first_item) && is_numeric($this->_per_page)) { 192 return ' LIMIT ' . DB::escapeString($this->first_item) . ', ' . DB::escapeString($this->_per_page) . ' ';193 } else { 194 App::logMsg(sprintf('Could not find SQL to LIMIT by %s %s.', $this->first_item, $this->_per_page), LOG_WARNING, __FILE__, __LINE__);201 return ' LIMIT ' . $db->escapeString($this->first_item) . ', ' . $db->escapeString($this->_per_page) . ' '; 202 } else { 203 $app->logMsg(sprintf('Could not find SQL to LIMIT by %s %s.', $this->first_item, $this->_per_page), LOG_WARNING, __FILE__, __LINE__); 195 204 return ''; 196 205 } … … 204 213 function printPerPageLinks($query_key='per_page') 205 214 { 215 $app =& App::getInstance(); 216 206 217 $sp = ''; 207 218 for ($i=0; $i<sizeof($this->per_page_options); $i++) { … … 209 220 printf('%s<a href="%s">%s</a>', 210 221 $sp, 211 App::oHREF($_SERVER['PHP_SELF'] . '?' . $query_key . '=' . $this->per_page_options[$i]),222 $app->oHREF($_SERVER['PHP_SELF'] . '?' . $query_key . '=' . $this->per_page_options[$i]), 212 223 $this->per_page_options[$i] 213 224 ); … … 220 231 221 232 /** 222 * Outputs an App::oHREF compatible url that goes to the page $page_number.233 * Outputs an $app->oHREF compatible url that goes to the page $page_number. 223 234 * Depends on $this->base_url to build the url onto. This is used in the 224 235 * page_number.ihtml template. … … 232 243 function getPageNumURL($page_number, $carry_args=null) 233 244 { 234 return App::oHREF($this->url_base . $page_number, $carry_args); 245 $app =& App::getInstance(); 246 247 return $app->oHREF($this->url_base . $page_number, $carry_args); 235 248 } 236 249 function printPageNumURL($page_number, $carry_args=null)
Note: See TracChangeset
for help on using the changeset viewer.