Changeset 42 for trunk/lib/PageNumbers.inc.php
- Timestamp:
- Dec 18, 2005 12:16:03 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/PageNumbers.inc.php
r41 r42 14 14 * @version 1.61 15 15 */ 16 16 17 17 require_once dirname(__FILE__) . '/Prefs.inc.php'; 18 18 19 19 class PageNumbers { 20 20 21 21 var $total_items; // Total quantity of items. 22 22 var $total_pages; // The total number of pages. … … 32 32 var $set_page_number_initialized = false; 33 33 var $set_total_items_initialized = false; 34 34 35 35 // These are initialized in the constructor. 36 36 var $per_page_options; … … 43 43 var $right_dbl_arrow; 44 44 var $right_dbl_arrow_disabled; 45 45 46 46 /** 47 47 * PageNumbers constructor. All arguments are depreciated. Use set* functions instead. … … 51 51 // Default options for the quantity per page links. 52 52 $this->per_page_options = array(25, 50, 100, 200); 53 53 54 54 // Default options for the page number links. 55 55 $this->left_arrow = _("back"); … … 61 61 $this->right_dbl_arrow = '<strong>»</strong>'; 62 62 $this->right_dbl_arrow_disabled = '<span style="color: #aaaaaa;"><strong>»</strong></span>'; 63 64 // Default url base. This will be set manually after instantiation 63 64 // Default url base. This will be set manually after instantiation 65 65 // in special cases like using a /my/page/# scheme. 66 66 $this->url_base = $_SERVER['PHP_SELF'] . '?page_number='; 67 67 } 68 68 69 69 /** 70 70 * Set the number of items per page. … … 88 88 $this->set_per_page_initialized = true; 89 89 } 90 90 91 91 /** 92 92 * Set the current page number. … … 112 112 $this->set_page_number_initialized = true; 113 113 } 114 114 115 115 /** 116 116 * Set the total number of items. … … 119 119 { 120 120 if (is_numeric($total_items) && $total_items > 0) { 121 $this->total_items = $total_items; 122 } else { 123 $this->total_items = 0; 121 $this->total_items = $total_items; 122 } else { 123 $this->total_items = 0; 124 124 } 125 125 $this->set_total_items_initialized = true; 126 126 } 127 127 128 128 /** 129 129 * After $total_items or other options are set, this function calculates 130 * all the other numbers needed. If you set any variables manually, 130 * all the other numbers needed. If you set any variables manually, 131 131 * for example if $page_number comes from 132 132 * some place other than the GET or POST array, you should call this … … 146 146 App::logMsg(sprintf('set_total_items not initialized'), LOG_ERR, __FILE__, __LINE__); 147 147 } 148 148 149 149 // If the specified page exceedes total pages or is less than 1, set the page to 1. 150 150 if ($this->_per_page * $this->current_page >= $this->total_items + $this->_per_page || $this->_per_page * $this->current_page < 1) { 151 151 $this->current_page = 1; 152 152 } 153 153 154 154 // The first item to be shown on this page. 155 155 $this->first_item = ($this->current_page - 1) * $this->_per_page; 156 156 157 157 // The last item to be shown on this page. 158 158 if ($this->total_items < $this->current_page * $this->_per_page) { … … 161 161 $this->last_item = $this->current_page * $this->_per_page - 1; 162 162 } 163 163 164 164 // Zeroing. Just in case. Paranoia. Yeah, negative numbers perturb me. 165 165 if ($this->first_item < 1) { … … 172 172 $this->total_items = 0; 173 173 } 174 174 175 175 // The total number of pages. 176 176 $this->total_pages = ceil($this->total_items / $this->_per_page); 177 177 178 178 // Figure out how many page number links to print. 179 179 if ($this->total_pages >= $this->max_num_links) { … … 183 183 } 184 184 } 185 185 186 186 /** 187 187 * Returns the SQL code to limit query to items that are on current page. … … 195 195 return ''; 196 196 } 197 } 197 } 198 198 199 199 /** … … 221 221 /** 222 222 * Outputs an App::oHREF compatible url that goes to the page $page_number. 223 * Depends on $this->base_url to build the url onto. This is used in the 223 * Depends on $this->base_url to build the url onto. This is used in the 224 224 * page_number.ihtml template. 225 225 * … … 247 247 { 248 248 $page_numbers = array(); 249 249 250 250 for ($i = 1; $i < $this->total_pages; $i++) { 251 251 $page_numbers[] = array( … … 255 255 ); 256 256 } 257 257 258 258 return $page_numbers; 259 259 } … … 267 267 { 268 268 $page_numbers_string = ''; 269 269 270 270 if ($this->current_page > $this->total_pages - floor($this->_num_links / 2)) { 271 271 $high_num = $this->total_pages; … … 278 278 $high_num = $low_num + $this->_num_links - 1; 279 279 } 280 280 281 281 if ($this->current_page != 1) { 282 282 // Print "first" and "previous" page links. … … 299 299 } 300 300 } 301 301 302 302 if ($this->_num_links > 0) { 303 303 // Print the current page number. 304 304 $page_numbers_string .= sprintf('<strong>%s</strong> ', $this->current_page); 305 305 } 306 306 307 307 if ($this->current_page < $this->total_pages) { 308 308 // Print links to specific page numbers after the current page. … … 325 325 } 326 326 } 327 327 328 328 return $page_numbers_string; 329 329 } 330 330 331 331 function printPageNumbers($carry_args=null) 332 332 { 333 333 echo $this->getPageNumbers($carry_args); 334 334 } 335 335 336 336 } 337 337
Note: See TracChangeset
for help on using the changeset viewer.