Changeset 571 for branches/1.1dev/lib
- Timestamp:
- Nov 5, 2016 10:53:54 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.1dev/lib/PageNumbers.inc.php
r82 r571 19 19 * @version 1.6 20 20 */ 21 21 22 22 require_once dirname(__FILE__) . '/App.inc.php'; 23 23 require_once dirname(__FILE__) . '/Utilities.inc.php'; … … 25 25 26 26 class PageNumbers { 27 27 28 28 var $total_items; // Total quantity of items. 29 29 var $total_pages; // The total number of pages. … … 39 39 var $set_page_number_initialized = false; 40 40 var $set_total_items_initialized = false; 41 41 42 42 // These are initialized in the constructor. 43 43 var $per_page_options; … … 50 50 var $right_dbl_arrow; 51 51 var $right_dbl_arrow_disabled; 52 52 53 53 /** 54 54 * PageNumbers constructor. All arguments are depreciated. Use set* functions instead. … … 58 58 // Default options for the quantity per page links. 59 59 $this->per_page_options = array(25, 50, 100, 200); 60 60 61 61 // Default options for the page number links. 62 62 $this->left_arrow = _("back"); … … 68 68 $this->right_dbl_arrow = '<strong>»</strong>'; 69 69 $this->right_dbl_arrow_disabled = '<span style="color: #aaaaaa;"><strong>»</strong></span>'; 70 71 // Default url base. This will be set manually after instantiation 70 71 // Default url base. This will be set manually after instantiation 72 72 // in special cases like using a /my/page/# scheme. 73 73 $this->url_base = $_SERVER['PHP_SELF'] . '?page_number='; 74 74 } 75 75 76 76 /** 77 77 * Set the number of items per page. … … 95 95 $this->set_per_page_initialized = true; 96 96 } 97 97 98 98 /** 99 99 * Set the current page number. … … 119 119 $this->set_page_number_initialized = true; 120 120 } 121 121 122 122 /** 123 123 * Set the total number of items. … … 126 126 { 127 127 if (is_numeric($total_items) && $total_items > 0) { 128 $this->total_items = $total_items; 129 } else { 130 $this->total_items = 0; 128 $this->total_items = $total_items; 129 } else { 130 $this->total_items = 0; 131 131 } 132 132 $this->set_total_items_initialized = true; 133 133 } 134 134 135 135 /** 136 136 * After $total_items or other options are set, this function calculates 137 * all the other numbers needed. If you set any variables manually, 137 * all the other numbers needed. If you set any variables manually, 138 138 * for example if $page_number comes from 139 139 * some place other than the GET or POST array, you should call this … … 153 153 logMsg(sprintf('set_total_items not initialized'), LOG_DEBUG, __FILE__, __LINE__); 154 154 } 155 156 // If the specified page exceed es total pages or is less than 1, set the page to 1.155 156 // If the specified page exceeds total pages or is less than 1, set the page to 1. 157 157 if ($this->_per_page * $this->current_page >= $this->total_items + $this->_per_page || $this->_per_page * $this->current_page < 1) { 158 158 $this->current_page = 1; 159 159 } 160 160 161 161 // The first item to be shown on this page. 162 162 $this->first_item = ($this->current_page - 1) * $this->_per_page; 163 163 164 164 // The last item to be shown on this page. 165 165 if ($this->total_items < $this->current_page * $this->_per_page) { … … 168 168 $this->last_item = $this->current_page * $this->_per_page - 1; 169 169 } 170 170 171 171 // Zeroing. Just in case. Paranoia. Yeah, negative numbers perturb me. 172 172 if ($this->first_item < 1) { … … 179 179 $this->total_items = 0; 180 180 } 181 181 182 182 // The total number of pages. 183 183 $this->total_pages = ceil($this->total_items / $this->_per_page); 184 184 185 185 // Figure out how many page number links to print. 186 186 if ($this->total_pages >= $this->max_num_links) { … … 190 190 } 191 191 } 192 192 193 193 /** 194 194 * Returns the SQL code to limit query to items that are on current page. … … 202 202 return ''; 203 203 } 204 } 204 } 205 205 206 206 /** … … 214 214 for ($i=0; $i<sizeof($this->per_page_options); $i++) { 215 215 if ($this->_per_page != $this->per_page_options[$i]) { 216 echo $sp . '<a href="' 217 . ohref($_SERVER['PHP_SELF'] . '?' . $query_key . '=' . $this->per_page_options[$i]) 216 echo $sp . '<a href="' 217 . ohref($_SERVER['PHP_SELF'] . '?' . $query_key . '=' . $this->per_page_options[$i]) 218 218 . '">' . $this->per_page_options[$i] . '</a>'; 219 219 } else { … … 226 226 /** 227 227 * Outputs an oHREF compatible url that goes to the page $page_number. 228 * Depends on $this->base_url to build the url onto. This is used in the 228 * Depends on $this->base_url to build the url onto. This is used in the 229 229 * page_number.ihtml template. 230 230 * … … 252 252 { 253 253 $page_numbers = array(); 254 254 255 255 // if ($this->current_page > $this->total_pages - floor($this->_num_links / 2)) { 256 256 // $high_num = $this->total_pages; … … 263 263 // $high_num = $low_num + $this->_num_links - 1; 264 264 // } 265 // 265 // 266 266 // for ($i = $low_num; $i < $this->current_page; $i++) { 267 267 // $page_numbers[] = array( … … 271 271 // ); 272 272 // } 273 // 273 // 274 274 // if ($this->_num_links > 0) { 275 275 // // Print the current page number. … … 280 280 // ); 281 281 // } 282 // 282 // 283 283 // // Print links to specific page numbers after the current page. 284 284 // for ($i = $this->current_page + 1; $i <= $high_num; $i++) { … … 289 289 // ); 290 290 // } 291 291 292 292 for ($i = 1; $i <= $this->total_pages; $i++) { 293 293 $page_numbers[] = array( … … 297 297 ); 298 298 } 299 299 300 300 return $page_numbers; 301 301 } … … 309 309 { 310 310 $page_numbers_string = ''; 311 311 312 312 if ($this->current_page > $this->total_pages - floor($this->_num_links / 2)) { 313 313 $high_num = $this->total_pages; … … 320 320 $high_num = $low_num + $this->_num_links - 1; 321 321 } 322 322 323 323 if ($this->current_page != 1) { 324 324 // Print "first" and "previous" page links. … … 341 341 } 342 342 } 343 343 344 344 if ($this->_num_links > 0) { 345 345 // Print the current page number. 346 346 $page_numbers_string .= sprintf('<strong>%s</strong> ', $this->current_page); 347 347 } 348 348 349 349 if ($this->current_page < $this->total_pages) { 350 350 // Print links to specific page numbers after the current page. … … 367 367 } 368 368 } 369 369 370 370 return $page_numbers_string; 371 371 } 372 372 373 373 function printPageNumbers($carry_args=null) 374 374 { 375 375 echo $this->getPageNumbers($carry_args); 376 376 } 377 377 378 378 } 379 379
Note: See TracChangeset
for help on using the changeset viewer.