Changeset 1057 for trunk/include/calendar_monthly.class.php
- Timestamp:
- Feb 24, 2006, 6:58:48 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/calendar_monthly.class.php
r1056 r1057 27 27 include_once(PHPWG_ROOT_PATH.'include/calendar_base.class.php'); 28 28 29 define ('CYEAR', 0); 30 define ('CMONTH', 1); 31 define ('CDAY', 2); 32 29 33 /** 30 34 * Monthly calendar style (composed of years/months and days) … … 38 42 * where not included here, true otherwise 39 43 */ 40 function generate_category_content($url_base, $view_type , &$requested)41 { 42 global $lang ;44 function generate_category_content($url_base, $view_type) 45 { 46 global $lang, $conf; 43 47 44 48 $this->url_base = $url_base; 45 49 46 if ($view_type==CAL_VIEW_CALENDAR and count($requested)==0) 47 {//case A: no year given - display all years+months 48 if ($this->build_global_calendar($requested)) 50 if ($view_type==CAL_VIEW_CALENDAR) 51 { 52 if ( count($this->date_components)==0 ) 53 {//case A: no year given - display all years+months 54 if ($this->build_global_calendar()) 55 return true; 56 } 57 58 if ( count($this->date_components)==1 ) 59 {//case B: year given - display all days in given year 60 if ($this->build_year_calendar()) 61 { 62 if ( $conf['calendar_multi_bar'] ) 63 $this->build_nav_bar2(CYEAR, 'YEAR'); // years 64 return true; 65 } 66 } 67 68 if ( count($this->date_components)==2 ) 69 {//case C: year+month given - display a nice month calendar 70 $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 } 49 80 return true; 50 } 51 52 if ($view_type==CAL_VIEW_CALENDAR and count($requested)==1) 53 {//case B: year given - display all days in given year 54 if ($this->build_year_calendar($requested)) 55 { 56 $this->build_nav_bar2($view_type, $requested, 0, 'YEAR'); // years 57 return true; 58 } 59 } 60 61 if ($view_type==CAL_VIEW_CALENDAR and count($requested)==2) 62 {//case C: year+month given - display a nice month calendar 63 $this->build_month_calendar($requested); 64 $this->build_nav_bar2(CAL_VIEW_CALENDAR, $requested, 0, 'YEAR'); // years 65 if (count($requested)>0) 66 $this->build_nav_bar2(CAL_VIEW_CALENDAR, $requested, 1, 'MONTH', $lang['month']); // month 67 return true; 68 } 69 70 if ($view_type==CAL_VIEW_LIST or count($requested)==3) 71 { 72 $this->build_nav_bar2($view_type, $requested, 0, 'YEAR'); // years 73 if (count($requested)>0) 74 $this->build_nav_bar2($view_type, $requested, 1, 'MONTH', $lang['month']); // month 75 if (count($requested)>1) 76 $this->build_nav_bar2($view_type, $requested, 2, 'DAYOFMONTH' ); // days 81 } 82 } 83 84 if ($view_type==CAL_VIEW_LIST or count($this->date_components)==3) 85 { 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 95 } 96 if ( count($this->date_components)>=2 ) 97 { 98 $this->build_nav_bar2(CDAY, 'DAYOFMONTH' ); // days 99 } 77 100 } 78 101 return false; … … 82 105 /** 83 106 * Returns a sql where subquery for the date field 84 * @param array requested selected levels for this calendar85 * (e.g. 2005,11,5 for 5th of November 2005)86 107 * @param int max_levels return the where up to this level 87 108 * (e.g. 2=only year and month) 88 109 * @return string 89 110 */ 90 function get_date_where($requested, $max_levels=3) 91 { 92 while (count($requested)>$max_levels) 93 { 94 array_pop($requested); 111 function get_date_where($max_levels=3) 112 { 113 $date = $this->date_components; 114 while (count($date)>$max_levels) 115 { 116 array_pop($date); 95 117 } 96 118 $res = ''; 97 if (isset($ requested[0]) and $requested[0]!='any')98 { 99 $b = $ requested[0] . '-';100 $e = $ requested[0] . '-';101 if (isset($ requested[1]) and $requested[1]!='any')102 { 103 $b .= $ requested[1] . '-';104 $e .= $ requested[1] . '-';105 if (isset($ requested[2]) and $requested[2]!='any')106 { 107 $b .= $ requested[2];108 $e .= $ requested[2];119 if (isset($date[CYEAR]) and $date[CYEAR]!='any') 120 { 121 $b = $date[CYEAR] . '-'; 122 $e = $date[CYEAR] . '-'; 123 if (isset($date[CMONTH]) and $date[CMONTH]!='any') 124 { 125 $b .= $date[CMONTH] . '-'; 126 $e .= $date[CMONTH] . '-'; 127 if (isset($date[CDAY]) and $date[CDAY]!='any') 128 { 129 $b .= $date[CDAY]; 130 $e .= $date[CDAY]; 109 131 } 110 132 else … … 118 140 $b .= '01-01'; 119 141 $e .= '12-31'; 120 if (isset($ requested[1]) and $requested[1]!='any')121 { 122 $res .= ' AND MONTH('.$this->date_field.')='.$ requested[1];123 } 124 if (isset($ requested[2]) and $requested[2]!='any')125 { 126 $res .= ' AND DAYOFMONTH('.$this->date_field.')='.$ requested[2];142 if (isset($date[CMONTH]) and $date[CMONTH]!='any') 143 { 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]; 127 149 } 128 150 } … … 132 154 { 133 155 $res = ' AND '.$this->date_field.' IS NOT NULL'; 134 if (isset($ requested[1]) and $requested[1]!='any')135 { 136 $res .= ' AND MONTH('.$this->date_field.')='.$ requested[1];137 } 138 if (isset($ requested[2]) and $requested[2]!='any')139 { 140 $res .= ' AND DAYOFMONTH('.$this->date_field.')='.$ requested[2];156 if (isset($date[CMONTH]) and $date[CMONTH]!='any') 157 { 158 $res .= ' AND MONTH('.$this->date_field.')='.$date[CMONTH]; 159 } 160 if (isset($date[CDAY]) and $date[CDAY]!='any') 161 { 162 $res .= ' AND DAYOFMONTH('.$this->date_field.')='.$date[CDAY]; 141 163 } 142 164 } … … 144 166 } 145 167 168 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 146 209 //--------------------------------------------------------- private members --- 147 function build_nav_bar2($ view_type, $requested, $level, $sql_func, $labels=null)148 { 149 parent::build_nav_bar($ view_type, $requested, $level, $sql_func, '', $labels);150 } 151 152 function build_global_calendar( &$requested)153 { 154 assert( count($ requested) == 0 );210 function build_nav_bar2($level, $sql_func, $labels=null) 211 { 212 parent::build_nav_bar($level, $sql_func, '', $labels); 213 } 214 215 function build_global_calendar() 216 { 217 assert( count($this->date_components) == 0 ); 155 218 $query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%Y%m")) as period, 156 219 COUNT(id) as count'; 157 220 $query.= $this->inner_sql; 158 $query.= $this->get_date_where( $requested);221 $query.= $this->get_date_where(); 159 222 $query.= ' 160 223 GROUP BY period'; … … 176 239 {// only one year exists so bail out to year view 177 240 list($y) = array_keys($items); 178 array_push($requested, $y );241 $this->date_components[CYEAR] = $y; 179 242 return false; 180 243 } … … 183 246 foreach ( $items as $year=>$year_data) 184 247 { 185 $url_base = $this->url_base .'c-'.$year;248 $url_base = $this->url_base.$year; 186 249 187 250 $nav_bar = '<span class="calCalHead"><a href="'.$url_base.'">'.$year.'</a>'; … … 200 263 } 201 264 202 function build_year_calendar( &$requested)203 { 204 assert( count($ requested) == 1 );265 function build_year_calendar() 266 { 267 assert( count($this->date_components) == 1 ); 205 268 $query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%m%d")) as period, 206 269 COUNT(id) as count'; 207 270 $query.= $this->inner_sql; 208 $query.= $this->get_date_where( $requested);271 $query.= $this->get_date_where(); 209 272 $query.= ' 210 273 GROUP BY period'; … … 226 289 { // only one month exists so bail out to month view 227 290 list($m) = array_keys($items); 228 array_push($requested, $m );291 $this->date_components[CMONTH] = $m; 229 292 if (count($items[$m]['children'])==1) 230 293 { // or even to day view if everything occured in one day 231 294 list($d) = array_keys($items[$m]['children']); 232 array_push($requested, $d);295 $this->date_components[CDAY] = $d; 233 296 } 234 297 return false; … … 237 300 foreach ( $items as $month=>$month_data) 238 301 { 239 $url_base = $this->url_base. 'c-'.$requested[0].'-'.$month;302 $url_base = $this->url_base.$this->date_components[CYEAR].'-'.$month; 240 303 241 304 $nav_bar = '<span class="calCalHead"><a href="'.$url_base.'">'; … … 256 319 } 257 320 258 function build_month_calendar( $requested)321 function build_month_calendar() 259 322 { 260 323 $query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%d")) as period, 261 324 COUNT(id) as count'; 262 325 $query.= $this->inner_sql; 263 $query.= $this->get_date_where($ requested, 2);326 $query.= $this->get_date_where($this->date_components); 264 327 $query.= ' 265 328 GROUP BY period'; … … 278 341 foreach ( $items as $day=>$nb_images) 279 342 { 280 $url_base = $this->url_base.'c-'.$requested[0].'-'.$requested[1].'-'.$day; 281 $requested[2]=$day; 343 $url_base = $this->url_base. 344 $this->date_components[CYEAR].'-'. 345 $this->date_components[CMONTH].'-'.$day; 346 $this->date_components[CDAY]=$day; 282 347 $query = ' 283 348 SELECT file,tn_ext,path, DAYOFWEEK('.$this->date_field.')-1 as dw'; 284 349 $query.= $this->inner_sql; 285 $query.= $this->get_date_where( $requested);350 $query.= $this->get_date_where(); 286 351 $query.= ' 287 352 ORDER BY RAND() 288 353 LIMIT 0,1'; 354 unset ( $this->date_components[CDAY] ); 289 355 290 356 $row = mysql_fetch_array(pwg_query($query));
Note: See TracChangeset
for help on using the changeset viewer.