| [ Index ] |
PHP Cross Reference of MantisBT |
[Summary view] [Print] [Text view]
1 <?php 2 # MantisBT - A PHP based bugtracking system 3 4 # MantisBT is free software: you can redistribute it and/or modify 5 # it under the terms of the GNU General Public License as published by 6 # the Free Software Foundation, either version 2 of the License, or 7 # (at your option) any later version. 8 # 9 # MantisBT is distributed in the hope that it will be useful, 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # GNU General Public License for more details. 13 # 14 # You should have received a copy of the GNU General Public License 15 # along with MantisBT. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Class for actions dealing with date periods 19 * 20 * This class encapsulates all actions dealing with time intervals. It handles data 21 * storage, and retrieval, as well as formatting and access. 22 * 23 * @copyright Logical Outcome Ltd. 2005 - 2007 24 * @author Glenn Henshaw <thraxisp@logicaloutcome.ca> 25 * @link http://www.mantisbt.org 26 * @package MantisBT 27 * @subpackage classes 28 * 29 */ 30 class Period { 31 32 /** 33 * @var string start date 34 */ 35 var $start = ''; 36 37 /** 38 * @var string end date 39 */ 40 var $end = ''; 41 42 // ******* End vars ********************************************* 43 /** 44 * Constructor 45 */ 46 function Period() { 47 $this->start = ''; 48 49 // default to today 50 $this->end = ''; 51 52 // default to today 53 } 54 55 /** 56 * set dates for a week 57 * 58 * @param string $p_when date string to expand to a week (Sun to Sat) 59 * @param int $p_weeks number of weeks 60 */ 61 function a_week( $p_when, $p_weeks = 1 ) { 62 list( $t_year, $t_month, $t_day ) = explode( "-", $p_when ); 63 $t_now = getdate( mktime( 0, 0, 0, $t_month, $t_day, $t_year ) ); 64 $this->end = strftime( "%Y-%m-%d 23:59:59", mktime( 0, 0, 0, $t_month, $t_day - $t_now['wday'] + ( $p_weeks * 7 ) - 1, $t_year ) ); 65 $this->start = strftime( "%Y-%m-%d 00:00:00", mktime( 0, 0, 0, $t_month, $t_day - $t_now['wday'], $t_year ) ); 66 } 67 68 /** 69 * set dates for this week 70 * 71 */ 72 function this_week() { 73 $this->a_week( date( 'Y-m-d' ) ); 74 } 75 76 /** 77 * set dates for last week 78 * 79 * @param int $p_weeks number of weeks 80 */ 81 function last_week( $p_weeks = 1 ) { 82 $this->a_week( date( 'Y-m-d', strtotime( '-' . $p_weeks . ' week' ) ), $p_weeks ); 83 } 84 85 /** 86 * set dates for this week to date 87 * 88 */ 89 function week_to_date() { 90 $this->this_week(); 91 $this->end = date( 'Y-m-d' ) . ' 23:59:59'; 92 } 93 94 /** 95 * set dates for a month 96 * 97 * @param string $p_when date string to expand to a month 98 */ 99 function a_month( $p_when ) { 100 list( $t_year, $t_month, $t_day ) = explode( "-", $p_when ); 101 $this->end = strftime( '%Y-%m-%d 23:59:59', mktime( 0, 0, 0, $t_month + 1, 0, $t_year ) ); 102 $this->start = strftime( '%Y-%m-%d 00:00:00', mktime( 0, 0, 0, $t_month, 1, $t_year ) ); 103 } 104 105 /** 106 * set dates for this month 107 * 108 */ 109 function this_month() { 110 $this->a_month( date( 'Y-m-d' ) ); 111 } 112 113 /** 114 * set dates for last month 115 * 116 */ 117 function last_month() { 118 $this->a_month( date( 'Y-m-d', strtotime( '-1 month' ) ) ); 119 } 120 121 /** 122 * set dates for this month to date 123 * 124 */ 125 function month_to_date() { 126 $this->end = date( 'Y-m-d' ) . ' 23:59:59'; 127 list( $t_year, $t_month, $t_day ) = explode( "-", $this->end ); 128 $this->start = strftime( '%Y-%m-%d 00:00:00', mktime( 0, 0, 0, $t_month, 1, $t_year ) ); 129 } 130 131 /** 132 * set dates for a quarter 133 * 134 * @param string $p_when date string to expand to a quarter 135 */ 136 function a_quarter( $p_when ) { 137 list( $t_year, $t_month, $t_day ) = explode( "-", $p_when ); 138 $t_month = ( (int)(( $t_month - 1 ) / 3 ) * 3 ) + 1; 139 $this->end = strftime( '%Y-%m-%d 23:59:59', mktime( 0, 0, 0, $t_month + 3, 0, $t_year ) ); 140 $this->start = strftime( '%Y-%m-%d 00:00:00', mktime( 0, 0, 0, $t_month, 1, $t_year ) ); 141 } 142 143 /** 144 * set dates for this quarter 145 * 146 */ 147 function this_quarter() { 148 $this->a_quarter( date( 'Y-m-d' ) ); 149 } 150 151 /** 152 * set dates for last month 153 * 154 */ 155 function last_quarter() { 156 $this->a_quarter( date( 'Y-m-d', strtotime( '-3 months' ) ) ); 157 } 158 159 /** 160 * set dates for this quarter to date 161 * 162 */ 163 function quarter_to_date() { 164 $this->end = date( 'Y-m-d' ) . ' 23:59:59'; 165 list( $t_year, $t_month, $t_day ) = explode( '-', $this->end ); 166 $t_month = ( (int)(( $t_month - 1 ) / 3 ) * 3 ) + 1; 167 $this->start = strftime( '%Y-%m-%d 00:00:00', mktime( 0, 0, 0, $t_month, 1, $t_year ) ); 168 } 169 170 /** 171 * set dates for a year 172 * 173 * @param string $p_when date string to expand to a year 174 */ 175 function a_year( $p_when ) { 176 list( $t_year, $t_month, $t_day ) = explode( '-', $p_when ); 177 $this->end = strftime( '%Y-%m-%d 23:59:59', mktime( 0, 0, 0, 12, 31, $t_year ) ); 178 $this->start = strftime( '%Y-%m-%d 00:00:00', mktime( 0, 0, 0, 1, 1, $t_year ) ); 179 } 180 181 /** 182 * set dates for this year 183 * 184 */ 185 function this_year() { 186 $this->a_year( date( 'Y-m-d' ) ); 187 } 188 189 /** 190 * set dates for current year, ending today 191 * 192 */ 193 function year_to_date() { 194 $this->end = date( 'Y-m-d' ) . ' 23:59:59'; 195 list( $t_year, $t_month, $t_day ) = explode( "-", $this->end ); 196 $this->start = strftime( '%Y-%m-%d 00:00:00', mktime( 0, 0, 0, 1, 1, $t_year ) ); 197 } 198 199 /** 200 * set dates for last year 201 * 202 */ 203 function last_year() { 204 $this->a_year( date( 'Y-m-d', strtotime( '-1 year' ) ) ); 205 } 206 207 /** 208 * get start date in unix timestamp format 209 * 210 */ 211 function get_start_timestamp() { 212 return strtotime( $this->start ); 213 } 214 215 /** 216 * get end date in unix timestamp format 217 * 218 */ 219 function get_end_timestamp() { 220 return strtotime( $this->end ); 221 } 222 223 /** 224 * get formatted start date 225 * 226 */ 227 function get_start_formatted() { 228 return( $this->start == '' ? '' : strftime( '%Y-%m-%d', $this->get_start_timestamp() ) ); 229 } 230 231 /** 232 * get formatted end date 233 * 234 */ 235 function get_end_formatted() { 236 return( $this->end == '' ? '' : strftime( '%Y-%m-%d', $this->get_end_timestamp() ) ); 237 } 238 239 /** 240 * get number of days in interval 241 * 242 */ 243 function get_elapsed_days() { 244 return( $this->get_end_timestamp() - $this->get_start_timestamp() ) / ( 24 * 60 * 60 ); 245 } 246 247 /** 248 * print a period selector 249 * 250 * @param string $p_control_name 251 */ 252 function period_selector( $p_control_name ) { 253 $t_periods = array( 254 0 => plugin_lang_get( 'period_none' ), 255 7 => plugin_lang_get( 'period_this_week' ), 256 8 => plugin_lang_get( 'period_last_week' ), 257 9 => plugin_lang_get( 'period_two_weeks' ), 258 1 => plugin_lang_get( 'period_this_month' ), 259 2 => plugin_lang_get( 'period_last_month' ), 260 3 => plugin_lang_get( 'period_this_quarter' ), 261 4 => plugin_lang_get( 'period_last_quarter' ), 262 5 => plugin_lang_get( 'period_year_to_date' ), 263 6 => plugin_lang_get( 'period_last_year' ), 264 10 => plugin_lang_get( 'period_select' ), 265 ); 266 $t_default = gpc_get_int( $p_control_name, 0 ); 267 $t_formatted_start = $this->get_start_formatted(); 268 $t_formatted_end = $this->get_end_formatted(); 269 $t_ret = '<div id="period_menu">'; 270 $t_ret .= get_dropdown( $t_periods, $p_control_name, $t_default, false, false ); 271 $t_ret .= "</div>\n"; 272 $t_ret .= "<div id=\"dates\">\n"; 273 $t_ret .= '<label for="start_date">' . lang_get( 'from_date' ) . '</label><input type="text" id="start_date" name="start_date" size="20" value="' . $t_formatted_start . '" class="datetime" disabled="disabled" />' . "<br />\n"; 274 $t_ret .= '<label for="end_date">' . lang_get( 'to_date' ) . '</label><input type="text" id="end_date" name="end_date" size="20" value="' . $t_formatted_end . '" class="datetime" disabled="disabled" />' . "\n"; 275 $t_ret .= "</div>\n"; 276 return $t_ret; 277 } 278 279 /** 280 * set date based on period selector 281 * 282 * @param string $p_control_name 283 * @param string $p_start_field 284 * @param string $p_end_field 285 */ 286 function set_period_from_selector( $p_control_name, $p_start_field = 'start_date', $p_end_field = 'end_date' ) { 287 $t_default = gpc_get_int( $p_control_name, 0 ); 288 switch( $t_default ) { 289 case 1: 290 $this->month_to_date(); 291 break; 292 case 2: 293 $this->last_month(); 294 break; 295 case 3: 296 $this->quarter_to_date(); 297 break; 298 case 4: 299 $this->last_quarter(); 300 break; 301 case 5: 302 $this->year_to_date(); 303 break; 304 case 6: 305 $this->last_year(); 306 break; 307 case 7: 308 $this->week_to_date(); 309 break; 310 case 8: 311 $this->last_week(); 312 break; 313 case 9: 314 $this->last_week( 2 ); 315 break; 316 case 10: 317 $t_today = date( 'Y-m-d' ); 318 if( $p_start_field != '' ) { 319 $this->start = gpc_get_string( $p_start_field, '' ) . ' 00:00:00'; 320 if( $this->start == '' ) { 321 $this->start = $t_today . ' 00:00:00'; 322 } 323 } 324 if( $p_end_field != '' ) { 325 $this->end = gpc_get_string( $p_end_field, '' ) . ' 23:59:59'; 326 if( $this->end == '' ) { 327 $this->end = $t_today . ' 23:59:59'; 328 } 329 } 330 break; 331 default: 332 } 333 } 334 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Jul 28 15:48:31 2011 | Cross-referenced by PHPXref 0.7 |