[ Index ] |
|
Code source de Mantis 1.1.0rc3 |
1 <?php 2 # Mantis - a php based bugtracking system 3 4 # Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org 5 # Copyright (C) 2002 - 2007 Mantis Team - mantisbt-dev@lists.sourceforge.net 6 7 # Mantis is free software: you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation, either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # Mantis is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with Mantis. If not, see <http://www.gnu.org/licenses/>. 19 20 # -------------------------------------------------------- 21 # $Id: class.period.php,v 1.1.2.1 2007-10-13 22:35:16 giallu Exp $ 22 # -------------------------------------------------------- 23 /** 24 * Class for actions dealing with date periods 25 * 26 * This class encapsulates all actions dealing with time intervals. It handles data 27 * storage, and retrieval, as well as formatting and access. 28 * 29 * @copyright Logical Outcome Ltd. 2005 - 2007 30 * @author Glenn Henshaw <thraxisp@logicaloutcome.ca> 31 * 32 * @version $Id: class.period.php,v 1.1.2.1 2007-10-13 22:35:16 giallu Exp $ 33 */ 34 class Period { 35 /** 36 * @var string start date 37 */ 38 var $start = ''; 39 /** 40 * @var string end date 41 */ 42 var $end = ''; 43 44 //******* End vars ********************************************* 45 46 /** 47 * Constructor 48 */ 49 function Period() { 50 $this->start = ''; // default to today 51 $this->end = ''; // default to today 52 } 53 54 /** 55 * return a matching SQL clause 56 * 57 * create an SQL clause that matches the set date. 58 * 59 * @return string SQL clause 60 */ 61 function get_sql_clause () { 62 if ( '' == $this->start ) { 63 if ( '' == $this->end ) { 64 $t_clause = ''; 65 } else { 66 $t_clause = " =< '" . $this->end . "'"; 67 } 68 } else { 69 if ( '' == $this->end ) { 70 $t_clause = " >= '" . $this->start . "'"; 71 } else { 72 $t_clause = " BETWEEN '" . $this->start . "' AND '" . $this->end . "'"; 73 } 74 } 75 return $t_clause; 76 } 77 78 /** 79 * return a matching text clause 80 * 81 * create an text clause that matches the set date. 82 * 83 * @return string SQL clause 84 */ 85 function get_text_clause () { 86 if ( '' == $this->start ) { 87 if ( '' == $this->end ) { 88 $t_clause = lang_get( 'all_dates' ); 89 } else { 90 list( $t_end_date, $t_end_time ) = split( ' ', $this->end ); 91 $t_clause = lang_get( 'before' ) . ' ' . $t_end_date; 92 } 93 } else { 94 list( $t_start_date, $t_start_time ) = split( ' ', $this->start ); 95 if ( '' == $this->end ) { 96 $t_clause = lang_get( 'after' ) . ' ' . $t_start_date; 97 } else { 98 list( $t_end_date, $t_end_time ) = split( ' ', $this->end ); 99 $t_clause = lang_get( 'from_date' ) . ' ' . $t_start_date . ' ' . lang_get( 'to_date' ) . ' ' . $t_end_date; 100 } 101 } 102 return $t_clause; 103 } 104 105 /** 106 * set dates for a week 107 * 108 * @param string date string to expand to a week (Sun to Sat) 109 */ 110 function a_week ( $p_when, $p_weeks = 1 ) { 111 list( $t_year, $t_month, $t_day ) = split( "-", $p_when ); 112 $t_now = getdate( mktime( 0,0,0,$t_month, $t_day, $t_year ) ); 113 $this->end = strftime( "%Y-%m-%d 23:59:59", 114 mktime( 0,0,0, $t_month, $t_day - $t_now['wday'] + ( $p_weeks * 7 ) - 1, $t_year ) ); 115 $this->start = strftime( "%Y-%m-%d 00:00:00", mktime( 0,0,0,$t_month, $t_day - $t_now['wday'], $t_year ) ); 116 } 117 118 /** 119 * set dates for this week 120 * 121 */ 122 function this_week ( ) { 123 $this->a_week( date( 'Y-m-d' ) ); 124 } 125 126 /** 127 * set dates for last week 128 * 129 */ 130 function last_week ( $p_weeks = 1) { 131 $this->a_week( date( 'Y-m-d', strtotime( '-'.$p_weeks.' week' ) ), $p_weeks ); 132 } 133 134 /** 135 * set dates for this week to date 136 * 137 */ 138 function week_to_date ( ) { 139 $this->this_week( ); 140 $this->end = date( 'Y-m-d' ) . ' 23:59:59'; 141 } 142 143 /** 144 * set dates for a month 145 * 146 * @param string date string to expand to a month 147 */ 148 function a_month ( $p_when ) { 149 list( $t_year, $t_month, $t_day ) = split( "-", $p_when ); 150 $this->end = strftime( "%Y-%m-%d 23:59:59", mktime( 0,0,0, $t_month+1, 0, $t_year ) ); 151 $this->start = strftime( "%Y-%m-%d 00:00:00", mktime( 0,0,0,$t_month, 1, $t_year ) ); 152 } 153 154 /** 155 * set dates for this month 156 * 157 */ 158 function this_month ( ) { 159 $this->a_month( date( 'Y-m-d' ) ); 160 } 161 162 /** 163 * set dates for last month 164 * 165 */ 166 function last_month ( ) { 167 $this->a_month( date( 'Y-m-d', strtotime( '-1 month' ) ) ); 168 } 169 170 /** 171 * set dates for this month to date 172 * 173 */ 174 function month_to_date ( ) { 175 $this->end = date( 'Y-m-d' ) . ' 23:59:59'; 176 list( $t_year, $t_month, $t_day ) = split( "-", $this->end ); 177 $this->start = strftime( "%Y-%m-%d 00:00:00", mktime( 0,0,0,$t_month, 1, $t_year ) ); 178 } 179 180 /** 181 * set dates for a quarter 182 * 183 * @param string date string to expand to a quarter 184 */ 185 function a_quarter ( $p_when ) { 186 list( $t_year, $t_month, $t_day ) = split( "-", $p_when ); 187 $t_month = ( (int)( ( $t_month - 1 ) / 3 ) * 3 ) + 1; 188 $this->end = strftime( "%Y-%m-%d 23:59:59", mktime( 0,0,0, $t_month+3, 0, $t_year ) ); 189 $this->start = strftime( "%Y-%m-%d 00:00:00", mktime( 0,0,0,$t_month, 1, $t_year ) ); 190 } 191 192 /** 193 * set dates for this quarter 194 * 195 */ 196 function this_quarter ( ) { 197 $this->a_quarter( date( 'Y-m-d' ) ); 198 } 199 200 /** 201 * set dates for last month 202 * 203 */ 204 function last_quarter ( ) { 205 $this->a_quarter( date( 'Y-m-d', strtotime( '-3 months' ) ) ); 206 } 207 208 /** 209 * set dates for this quarter to date 210 * 211 */ 212 function quarter_to_date ( ) { 213 $this->end = date( 'Y-m-d' ) . ' 23:59:59'; 214 list( $t_year, $t_month, $t_day ) = split( "-", $this->end ); 215 $t_month = ( (int)( ( $t_month - 1 ) / 3 ) * 3 ) + 1; 216 $this->start = strftime( "%Y-%m-%d 00:00:00", mktime( 0,0,0,$t_month, 1, $t_year ) ); 217 } 218 219 /** 220 * set dates for a year 221 * 222 * @param string date string to expand to a year 223 */ 224 function a_year ( $p_when ) { 225 list( $t_year, $t_month, $t_day ) = split( "-", $p_when ); 226 $this->end = strftime( "%Y-%m-%d 23:59:59", mktime( 0,0,0, 12, 31, $t_year ) ); 227 $this->start = strftime( "%Y-%m-%d 00:00:00", mktime( 0,0,0, 1, 1, $t_year ) ); 228 } 229 230 /** 231 * set dates for this year 232 * 233 */ 234 function this_year ( ) { 235 $this->a_year( date( 'Y-m-d' ) ); 236 } 237 238 /** 239 * set dates for current year, ending today 240 * 241 */ 242 function year_to_date ( ) { 243 $this->end = date( 'Y-m-d' ) . ' 23:59:59'; 244 list( $t_year, $t_month, $t_day ) = split( "-", $this->end ); 245 $this->start = strftime( "%Y-%m-%d 00:00:00", mktime( 0,0,0, 1, 1, $t_year ) ); 246 } 247 248 /** 249 * set dates for last year 250 * 251 */ 252 function last_year ( ) { 253 $this->a_year( date( 'Y-m-d', strtotime( '-1 year' ) ) ); 254 } 255 256 /** 257 * get start date in unix timestamp format 258 * 259 */ 260 function get_start_timestamp ( ) { 261 return strtotime( $this->start ); 262 } 263 264 /** 265 * get end date in unix timestamp format 266 * 267 */ 268 function get_end_timestamp ( ) { 269 return strtotime( $this->end ); 270 } 271 272 /** 273 * get formatted start date 274 * 275 */ 276 function get_start_formatted ( ) { 277 return ($this->start == '' ? '' : strftime( '%Y-%m-%d', $this->get_start_timestamp()) ); 278 } 279 280 /** 281 * get formatted end date 282 * 283 */ 284 function get_end_formatted ( ) { 285 return ($this->end == '' ? '' : strftime( '%Y-%m-%d', $this->get_end_timestamp()) ); 286 } 287 288 /** 289 * get number of days in interval 290 * 291 */ 292 function get_elapsed_days ( ) { 293 return ( $this->get_end_timestamp() - $this->get_start_timestamp() ) / (24 * 60 * 60); 294 } 295 296 /** 297 * print a period selector 298 * 299 */ 300 function period_selector ( $p_control_name ) { 301 $t_periods = array( 302 0 => lang_get( 'period_none' ), 303 7 => lang_get( 'period_this_week' ), 304 8 => lang_get( 'period_last_week' ), 305 9 => lang_get( 'period_two_weeks' ), 306 1 => lang_get( 'period_this_month' ), 307 2 => lang_get( 'period_last_month' ), 308 3 => lang_get( 'period_this_quarter' ), 309 4 => lang_get( 'period_last_quarter' ), 310 5 => lang_get( 'period_year_to_date' ), 311 6 => lang_get( 'period_last_year' ), 312 10 => lang_get( 'period_select' ) 313 ); 314 $t_default = gpc_get_int( $p_control_name, 0 ); 315 $t_formatted_start = $this->get_start_formatted(); 316 $t_formatted_end = $this->get_end_formatted(); 317 $t_ret = '<div id="period_menu">'; 318 $t_ret .= get_dropdown( $t_periods, $p_control_name, $t_default, false, false, 'setDisplay(\'dates\', document.getElementById(\''.$p_control_name.'\').value == 10)'); 319 $t_ret .= '</div><div id="dates">'. 320 lang_get('from_date').' '. 321 '<input type="text" id="start_date" name="start_date" size="10" value="'.$t_formatted_start.'" />'. 322 '<img src="images/calendar-img.gif" id="f_trigger_s" style="cursor: pointer; border: 1px solid red;" '. 323 ' title="Date selector" onmouseover="this.style.background=\'red\';"'. 324 ' onmouseout="this.style.background=\'white\'" />'."\n". 325 '<br />'. 326 lang_get('to_date').' '. 327 '<input type="text" id="end_date" name="end_date" size="10" value="'.$t_formatted_end.'" />'. 328 '<img src="images/calendar-img.gif" id="f_trigger_e" style="cursor: pointer; border: 1px solid red;" '. 329 ' title="Date selector" onmouseover="this.style.background=\'red\';"'. 330 ' onmouseout="this.style.background=\'white\'" />'."\n". 331 '<script type="text/javascript"> 332 <!-- 333 Calendar.setup({ inputField : "start_date", ifFormat : "%Y-%m-%d", button : "f_trigger_s", 334 align : "cR", singleClick : false, showTime : false }); 335 Calendar.setup({ inputField : "end_date", ifFormat : "%Y-%m-%d", button : "f_trigger_e", 336 align : "cR", singleClick : false, showTime : false }); 337 var t = document.getElementById(\''.$p_control_name.'\').value; 338 setDisplay(\''.$p_control_name.'\',true); 339 setDisplay(\'dates\', document.getElementById(\''.$p_control_name.'\').value == 10); 340 //--> 341 </script>'."\n". 342 '</div>'; 343 return $t_ret; 344 345 } 346 347 /** 348 * set date based on period selector 349 * 350 */ 351 function set_period_from_selector ( $p_control_name, $p_start_field='start_date', $p_end_field='end_date' ) { 352 $t_default = gpc_get_int( $p_control_name, 0 ); 353 switch ( $t_default ) { 354 case 1: 355 $this->month_to_date(); 356 break; 357 case 2: 358 $this->last_month(); 359 break; 360 case 3: 361 $this->quarter_to_date(); 362 break; 363 case 4: 364 $this->last_quarter(); 365 break; 366 case 5: 367 $this->year_to_date(); 368 break; 369 case 6: 370 $this->last_year(); 371 break; 372 case 7: 373 $this->week_to_date(); 374 break; 375 case 8: 376 $this->last_week(); 377 break; 378 case 9: 379 $this->last_week( 2 ); 380 break; 381 case 10: 382 $t_today = date( 'Y-m-d' ); 383 if ($p_start_field != '') { 384 $this->start = gpc_get_string($p_start_field, '') . ' 00:00:00'; 385 if ($this->start == '') { 386 $this->start = $t_today . ' 00:00:00'; 387 } 388 } 389 if ($p_end_field != '') { 390 $this->end = gpc_get_string($p_end_field, '') . ' 23:59:59'; 391 if ($this->end == '') { 392 $this->end = $t_today . ' 23:59:59'; 393 } 394 } 395 break; 396 default: 397 } 398 } 399 400 } // end class 401 402 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 09:42:17 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |