Changeset 1062 for trunk/include/calendar_base.class.php
- Timestamp:
- Mar 3, 2006, 2:57:39 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/calendar_base.class.php
r1059 r1062 41 41 var $calendar_levels; 42 42 43 var $has_nav_bar; 44 43 45 /** 44 46 * Initialize the calendar … … 52 54 $this->inner_sql = $inner_sql; 53 55 $this->date_components = $date_components; 56 $this->has_nav_bar = false; 54 57 } 55 58 … … 99 102 } 100 103 return $label; 104 } 105 106 /** 107 * Gets a nice display name for a date to be shown in previos/next links. 108 */ 109 function get_date_nice_name($date) 110 { 111 $date_components = explode('-', $date); 112 $res = ''; 113 for ($i=count($date_components)-1; $i>=0; $i--) 114 { 115 if ($date_components[$i]!='any') 116 { 117 $label = $date_components[$i]; 118 if (isset($this->calendar_levels[$i]['labels'][$date_components[$i]])) 119 { 120 $label = $this->calendar_levels[$i]['labels'][$date_components[$i]]; 121 } 122 $res .= $label.' '; 123 } 124 } 125 return $res; 101 126 } 102 127 … … 212 237 } 213 238 214 if ( count($level_items)==1 ) 239 if ( count($level_items)==1 and 240 count($this->date_components)<count($this->calendar_levels)-1) 215 241 { 216 242 if ( ! isset($this->date_components[$level]) ) … … 218 244 list($key) = array_keys($level_items); 219 245 $this->date_components[$level] = (int)$key; 220 } 221 } 222 223 if ( $conf['calendar_multi_bar']==false ) 224 { 225 if ( $level<count($this->date_components) and 226 $level!=count($this->calendar_levels)-1 ) 227 { 228 return; 246 247 if ( $level<count($this->date_components) and 248 $level!=count($this->calendar_levels)-1 ) 249 { 250 return; 251 } 229 252 } 230 253 } … … 237 260 $url_base .= $this->date_components[$i].'-'; 238 261 } 239 }240 $selected = null;241 if ( isset($this->date_components[$level]) )242 {243 $selected = $this->date_components[$level];244 262 } 245 263 $nav_bar = $this->get_nav_bar_from_items( 246 264 $url_base, 247 265 $level_items, 248 $selected,266 null, 249 267 'calItem', 250 268 true, … … 256 274 'calendar.navbar', 257 275 array( 258 'BAR' => $nav_bar 276 'BAR' => $nav_bar, 259 277 ) 260 278 ); 279 $this->has_nav_bar = true; 280 } 281 282 /** 283 * Assigns the next/previous link to the template with regards to 284 * the currently choosen date. 285 */ 286 function build_next_prev() 287 { 288 global $template; 289 $prev = $next =null; 290 if ( empty($this->date_components) ) 291 return; 292 293 $current = ''; 294 $query = 'SELECT CONCAT_WS("-"'; 295 for ($i=0; $i<count($this->date_components); $i++) 296 { 297 if ( $this->date_components[$i] != 'any' ) 298 { 299 $query .= ','.$this->calendar_levels[$i]['sql']; 300 } 301 else 302 { 303 $query .= ','.'"any"'; 304 } 305 $current .= '-' . $this->date_components[$i]; 306 } 307 $current = substr($current, 1); 308 309 $query.=') as period' . $this->inner_sql .' 310 AND ' . $this->date_field . ' IS NOT NULL 311 GROUP BY period'; 312 $upper_items = array_from_query( $query, 'period'); 313 usort($upper_items, 'version_compare'); 314 //echo ('<pre>'. var_export($upper_items, true) . '</pre>'); 315 $upper_items_rank = array_flip($upper_items); 316 $current_rank = $upper_items_rank[$current]; 317 if (!$this->has_nav_bar and 318 ($current_rank>0 or $current_rank < count($upper_items)-1 ) ) 319 { 320 $template->assign_block_vars( 'calendar.navbar', array() ); 321 } 322 323 if ( $current_rank>0 ) 324 { // has previous 325 $prev = $upper_items[$current_rank-1]; 326 $template->assign_block_vars( 327 'calendar.navbar.prev', 328 array( 329 'LABEL' => $this->get_date_nice_name($prev), 330 'URL' => $this->url_base . $prev, 331 ) 332 ); 333 } 334 if ( $current_rank < count($upper_items)-1 ) 335 { 336 // has next 337 $next = $upper_items[$current_rank+1]; 338 $template->assign_block_vars( 339 'calendar.navbar.next', 340 array( 341 'LABEL' => $this->get_date_nice_name($next), 342 'URL' => $this->url_base . $next, 343 ) 344 ); 345 } 261 346 } 262 347 }
Note: See TracChangeset
for help on using the changeset viewer.