Changeset 1086 for trunk/include/calendar_base.class.php
- Timestamp:
- Mar 17, 2006, 5:13:19 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/calendar_base.class.php
r1069 r1086 34 34 // used for queries (INNER JOIN or normal) 35 35 var $inner_sql; 36 // base url used when generating html links37 var $url_base;38 // array of date components e.g. (2005,10,12) ...39 var $date_components;40 36 // 41 37 var $calendar_levels; … … 45 41 /** 46 42 * Initialize the calendar 47 * @param string date_field db column on which this calendar works48 43 * @param string inner_sql used for queries (INNER JOIN or normal) 49 * @param array date_components 50 */ 51 function initialize($date_field, $inner_sql, $date_components) 52 { 53 $this->date_field = $date_field; 44 */ 45 function initialize($inner_sql) 46 { 47 global $page; 48 if ($page['chronology']['field']=='posted') 49 { 50 $this->date_field = 'date_available'; 51 } 52 else 53 { 54 $this->date_field = 'date_creation'; 55 } 54 56 $this->inner_sql = $inner_sql; 55 $this->date_components = $date_components;56 57 $this->has_nav_bar = false; 57 58 } … … 59 60 function get_display_name() 60 61 { 61 global $conf ;62 global $conf, $page; 62 63 $res = ''; 63 $url = $this->url_base; 64 65 for ($i=0; $i<count($this->date_components); $i++) 64 65 for ($i=0; $i<count($page['chronology_date']); $i++) 66 66 { 67 67 $res .= $conf['level_separator']; 68 if ( $i>0)69 { 70 $ url .= '-';71 }72 $url .= $this->date_components[$i];73 if ( isset($this->date_components[$i+1]))74 {68 if ( isset($page['chronology_date'][$i+1]) ) 69 { 70 $chronology_date = array_slice($page['chronology_date'],0, $i+1); 71 $url = duplicate_index_url( 72 array( 'chronology_date'=>$chronology_date ), 73 array( 'start' ) 74 ); 75 75 $res .= 76 76 '<a href="'.$url.'">' 77 .$this->get_date_component_label($i, $ this->date_components[$i])77 .$this->get_date_component_label($i, $page['chronology_date'][$i]) 78 78 .'</a>'; 79 79 } … … 82 82 $res .= 83 83 '<span class="calInHere">' 84 .$this->get_date_component_label($i, $ this->date_components[$i])84 .$this->get_date_component_label($i, $page['chronology_date'][$i]) 85 85 .'</span>'; 86 86 } … … 132 132 * Creates a calendar navigation bar. 133 133 * 134 * @param string url_base - links start with this root134 * @param array date_components 135 135 * @param array items - hash of items to put in the bar (e.g. 2005,2006) 136 136 * @param array selected_item - item currently selected (e.g. 2005) … … 141 141 * @return string the navigation bar 142 142 */ 143 function get_nav_bar_from_items($ url_base, $items, $selected_item,143 function get_nav_bar_from_items($date_components, $items, $selected_item, 144 144 $class_prefix, $show_any, 145 145 $show_empty=false, $labels=null) 146 146 { 147 global $conf ;147 global $conf, $page; 148 148 149 149 $nav_bar = ''; … … 181 181 { 182 182 $nav_bar .= '<span class="'.$class_prefix.'">'; 183 $url = $url_base . $item; 183 $url = duplicate_index_url( 184 array('chronology_date'=>array_merge($date_components,$item)), 185 array( 'start' ) 186 ); 184 187 $nav_bar .= '<a href="'.$url.'">'; 185 188 $nav_bar .= $label; … … 204 207 { 205 208 $nav_bar .= '<span class="'.$class_prefix.'">'; 206 $url = $url_base . 'any'; 209 $url = duplicate_index_url( 210 array('chronology_date'=>array_merge($date_components,'any')), 211 array( 'start' ) 212 ); 207 213 $nav_bar .= '<a href="'.$url.'">'; 208 214 $nav_bar .= $label; … … 222 228 function build_nav_bar($level, $labels=null) 223 229 { 224 global $template, $conf ;230 global $template, $conf, $page; 225 231 226 232 $query = ' … … 241 247 242 248 if ( count($level_items)==1 and 243 count($ this->date_components)<count($this->calendar_levels)-1)244 { 245 if ( ! isset($ this->date_components[$level]) )249 count($page['chronology_date'])<count($this->calendar_levels)-1) 250 { 251 if ( ! isset($page['chronology_date'][$level]) ) 246 252 { 247 253 list($key) = array_keys($level_items); 248 $ this->date_components[$level] = (int)$key;249 250 if ( $level<count($ this->date_components) and254 $page['chronology_date'][$level] = (int)$key; 255 256 if ( $level<count($page['chronology_date']) and 251 257 $level!=count($this->calendar_levels)-1 ) 252 258 { … … 256 262 } 257 263 258 $url_base = $this->url_base;259 for ($i=0; $i<$level; $i++)260 {261 if (isset($this->date_components[$i]))262 {263 $url_base .= $this->date_components[$i].'-';264 }265 }266 264 $nav_bar = $this->get_nav_bar_from_items( 267 $ url_base,265 $page['chronology_date'], 268 266 $level_items, 269 267 null, … … 289 287 function build_next_prev() 290 288 { 291 global $template ;289 global $template, $page; 292 290 $prev = $next =null; 293 if ( empty($ this->date_components) )291 if ( empty($page['chronology_date']) ) 294 292 return; 295 293 $query = 'SELECT CONCAT_WS("-"'; 296 for ($i=0; $i<count($ this->date_components); $i++)297 { 298 if ( 'any' === $ this->date_components[$i] )294 for ($i=0; $i<count($page['chronology_date']); $i++) 295 { 296 if ( 'any' === $page['chronology_date'] ) 299 297 { 300 298 $query .= ','.'"any"'; … … 305 303 } 306 304 } 307 $current = implode('-', $ this->date_components);305 $current = implode('-', $page['chronology_date'] ); 308 306 309 307 $query.=') as period' . $this->inner_sql .' … … 328 326 $template->assign_block_vars( 'calendar.navbar', array() ); 329 327 } 328 330 329 if ( $current_rank>0 ) 331 330 { // has previous 332 331 $prev = $upper_items[$current_rank-1]; 332 $chronology_date = explode('-', $prev); 333 333 $template->assign_block_vars( 334 334 'calendar.navbar.prev', 335 335 array( 336 336 'LABEL' => $this->get_date_nice_name($prev), 337 'URL' => $this->url_base . $prev, 337 'URL' => duplicate_index_url( 338 array('chronology_date'=>$chronology_date), array('start') 339 ) 338 340 ) 339 341 ); 340 342 } 341 343 if ( $current_rank < count($upper_items)-1 ) 342 { 343 // has next 344 { // has next 344 345 $next = $upper_items[$current_rank+1]; 346 $chronology_date = explode('-', $next); 345 347 $template->assign_block_vars( 346 348 'calendar.navbar.next', 347 349 array( 348 350 'LABEL' => $this->get_date_nice_name($next), 349 'URL' => $this->url_base . $next, 351 'URL' => duplicate_index_url( 352 array('chronology_date'=>$chronology_date), array('start') 353 ) 350 354 ) 351 355 );
Note: See TracChangeset
for help on using the changeset viewer.