Changeset 1059 for trunk/include/calendar_monthly.class.php
- Timestamp:
- Feb 28, 2006, 5:28:06 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/calendar_monthly.class.php
r1057 r1059 37 37 { 38 38 39 /** 40 * Initialize the calendar 41 * @param string date_field db column on which this calendar works 42 * @param string inner_sql used for queries (INNER JOIN or normal) 43 * @param array date_components 44 */ 45 function initialize($date_field, $inner_sql, $date_components) 46 { 47 parent::initialize($date_field, $inner_sql, $date_components); 48 global $lang; 49 $this->calendar_levels = array( 50 array( 51 'sql'=> 'YEAR('.$this->date_field.')', 52 'labels' => null 53 ), 54 array( 55 'sql'=> 'MONTH('.$this->date_field.')', 56 'labels' => $lang['month'] 57 ), 58 array( 59 'sql'=> 'DAYOFMONTH('.$this->date_field.')', 60 'labels' => null 61 ), 62 ); 63 } 64 39 65 /** 40 66 * Generate navigation bars for category page … … 44 70 function generate_category_content($url_base, $view_type) 45 71 { 46 global $ lang, $conf;72 global $conf; 47 73 48 74 $this->url_base = $url_base; … … 60 86 if ($this->build_year_calendar()) 61 87 { 62 if ( $conf['calendar_multi_bar'] ) 63 $this->build_nav_bar2(CYEAR, 'YEAR'); // years 88 $this->build_nav_bar(CYEAR); // years 64 89 return true; 65 90 } … … 69 94 {//case C: year+month given - display a nice month calendar 70 95 $this->build_month_calendar(); 71 if ( $conf['calendar_multi_bar'] ) 72 { 73 $this->build_nav_bar2(CYEAR, 'YEAR'); // years 74 } 75 if (count($this->date_components)>=1 and 76 ( $conf['calendar_multi_bar'] or count($this->date_components)==1 ) ) 77 { 78 $this->build_nav_bar2(CMONTH, 'MONTH', $lang['month']); // month 79 } 96 $this->build_nav_bar(CYEAR); // years 97 $this->build_nav_bar(CMONTH); // month 80 98 return true; 81 99 } … … 84 102 if ($view_type==CAL_VIEW_LIST or count($this->date_components)==3) 85 103 { 86 if ( $conf['calendar_multi_bar'] or count($this->date_components)==0 ) 87 { 88 $this->build_nav_bar2(CYEAR, 'YEAR'); // years 89 } 90 if ( count($this->date_components)>=1 and 91 ( $conf['calendar_multi_bar'] or count($this->date_components)==1 ) 92 ) 93 { 94 $this->build_nav_bar2(CMONTH, 'MONTH', $lang['month']); // month 104 if ( count($this->date_components)>=0 ) 105 { 106 $this->build_nav_bar(CYEAR); // years 107 } 108 if ( count($this->date_components)>=1) 109 { 110 $this->build_nav_bar(CMONTH); // month 95 111 } 96 112 if ( count($this->date_components)>=2 ) 97 113 { 98 $this->build_nav_bar2(CDAY, 'DAYOFMONTH' ); // days 114 $this->build_nav_bar( 115 CDAY, 116 $this->get_all_days_in_month( 117 $this->date_components[CYEAR] ,$this->date_components[CMONTH] 118 ) 119 ); // days 99 120 } 100 121 } … … 142 163 if (isset($date[CMONTH]) and $date[CMONTH]!='any') 143 164 { 144 $res .= ' AND MONTH('.$this->date_field.')='.$date[CMONTH];145 } 146 if (isset($date[ 2]) and $date[2]!='any')147 { 148 $res .= ' AND DAYOFMONTH('.$this->date_field.')='.$date[CDAY];165 $res .= ' AND '.$this->calendar_levels[CMONTH]['sql'].'='.$date[CMONTH]; 166 } 167 if (isset($date[CDAY]) and $date[CDAY]!='any') 168 { 169 $res .= ' AND '.$this->calendar_levels[CDAY]['sql'].'='.$date[CDAY]; 149 170 } 150 171 } … … 156 177 if (isset($date[CMONTH]) and $date[CMONTH]!='any') 157 178 { 158 $res .= ' AND MONTH('.$this->date_field.')='.$date[CMONTH];179 $res .= ' AND '.$this->calendar_levels[CMONTH]['sql'].'='.$date[CMONTH]; 159 180 } 160 181 if (isset($date[CDAY]) and $date[CDAY]!='any') 161 182 { 162 $res .= ' AND DAYOFMONTH('.$this->date_field.')='.$date[CDAY];183 $res .= ' AND '.$this->calendar_levels[CDAY]['sql'].'='.$date[CDAY]; 163 184 } 164 185 } … … 167 188 168 189 169 function get_display_name()170 {171 global $conf, $lang;172 $res = '';173 $url = $this->url_base;174 if ( isset($this->date_components[CYEAR]) )175 {176 $res .= $conf['level_separator'];177 $url .= $this->date_components[CYEAR].'-';178 $res .=179 '<a href="'.$url.'">'180 .$this->get_date_component_label($this->date_components[CYEAR])181 .'</a>';182 }183 if ( isset($this->date_components[CMONTH]) )184 {185 $res .= $conf['level_separator'];186 $url .= $this->date_components[CMONTH].'-';187 $res .=188 '<a href="'.$url.'">'189 .$this->get_date_component_label(190 $this->date_components[CMONTH],191 $lang['month']192 )193 .'</a>';194 }195 if ( isset($this->date_components[CDAY]) )196 {197 $res .= $conf['level_separator'];198 $url .= $this->date_components[CDAY].'-';199 $res .=200 '<a href="'.$url.'">'201 .$this->get_date_component_label($this->date_components[CDAY])202 .'</a>';203 }204 205 return $res;206 }207 208 190 209 191 //--------------------------------------------------------- private members --- 210 function build_nav_bar2($level, $sql_func, $labels=null) 211 { 212 parent::build_nav_bar($level, $sql_func, '', $labels); 192 193 // returns an array with alll the days in a given month 194 function get_all_days_in_month($year, $month) 195 { 196 $md= array(1=>31,28,31,30,31,30,31,31,30,31,30,31); 197 198 if ( is_numeric($year) and $month==2) 199 { 200 $nb_days = $md[2]; 201 if ( ($year%4==0) and ( ($year%100!=0) or ($year%400!=0) ) ) 202 { 203 $nb_days++; 204 } 205 } 206 elseif ( is_numeric($month) ) 207 { 208 $nb_days = $md[ $month ]; 209 } 210 else 211 { 212 $nb_days = 31; 213 } 214 return range(1, $nb_days); 213 215 } 214 216 … … 217 219 assert( count($this->date_components) == 0 ); 218 220 $query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%Y%m")) as period, 219 COUNT( id) as count';221 COUNT( DISTINCT(id) ) as count'; 220 222 $query.= $this->inner_sql; 221 223 $query.= $this->get_date_where(); … … 224 226 225 227 $result = pwg_query($query); 228 $items=array(); 226 229 while ($row = mysql_fetch_array($result)) 227 230 { … … 253 256 254 257 $url_base .= '-'; 255 $nav_bar .= $this->get_nav_bar_from_items( $url_base, 256 $year_data['children'], null, 'calCal', false, $lang['month'] );258 $nav_bar .= $this->get_nav_bar_from_items( $url_base, 259 $year_data['children'], null, 'calCal', false, false, $lang['month'] ); 257 260 258 261 $template->assign_block_vars( 'calendar.calbar', … … 267 270 assert( count($this->date_components) == 1 ); 268 271 $query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%m%d")) as period, 269 COUNT( id) as count';272 COUNT( DISTINCT(id) ) as count'; 270 273 $query.= $this->inner_sql; 271 274 $query.= $this->get_date_where(); … … 274 277 275 278 $result = pwg_query($query); 279 $items=array(); 276 280 while ($row = mysql_fetch_array($result)) 277 281 { … … 308 312 309 313 $url_base .= '-'; 310 $nav_bar .= $this->get_nav_bar_from_items( $url_base, 314 $nav_bar .= $this->get_nav_bar_from_items( $url_base, 311 315 $month_data['children'], null, 'calCal', false ); 312 316 … … 332 336 { 333 337 $d = $row['period']; 334 $items[$d] = $row['count']; 335 } 336 337 global $lang, $template; 338 339 $template->assign_block_vars('thumbnails', array()); 340 $template->assign_block_vars('thumbnails.line', array()); 341 foreach ( $items as $day=>$nb_images) 342 { 343 $url_base = $this->url_base. 344 $this->date_components[CYEAR].'-'. 345 $this->date_components[CMONTH].'-'.$day; 338 $items[$d] = array('nb_images'=>$row['count']); 339 } 340 341 foreach ( $items as $day=>$data) 342 { 346 343 $this->date_components[CDAY]=$day; 347 344 $query = ' … … 355 352 356 353 $row = mysql_fetch_array(pwg_query($query)); 357 358 $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']); 359 $thumbnail_title = $lang['day'][$row['dw']] . ' ' . $day; 360 $name = $thumbnail_title .' ('.$nb_images.')'; 354 $items[$day]['tn_path'] = get_thumbnail_src($row['path'], @$row['tn_ext']); 355 $items[$day]['tn_file'] = $row['file']; 356 $items[$day]['tn_dw'] = $row['dw']; 357 } 358 359 global $lang, $template; 360 $template->assign_block_vars('thumbnails', array()); 361 $template->assign_block_vars('thumbnails.line', array()); 362 foreach ( $items as $day=>$data) 363 { 364 $url_base = $this->url_base. 365 $this->date_components[CYEAR].'-'. 366 $this->date_components[CMONTH].'-'.$day; 367 368 $thumbnail_title = $lang['day'][$data['tn_dw']] . ' ' . $day; 369 $name = $thumbnail_title .' ('.$data['nb_images'].')'; 361 370 362 371 $template->assign_block_vars( 363 372 'thumbnails.line.thumbnail', 364 373 array( 365 'IMAGE'=>$ thumbnail_src,366 'IMAGE_ALT'=>$ row['file'],374 'IMAGE'=>$data['tn_path'], 375 'IMAGE_ALT'=>$data['tn_file'], 367 376 'IMAGE_TITLE'=>$thumbnail_title, 368 377 'U_IMG_LINK'=>$url_base … … 376 385 ); 377 386 } 387 378 388 return true; 379 389 }
Note: See TracChangeset
for help on using the changeset viewer.