[ 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: graph_api.php,v 1.36.2.1 2007-10-13 22:35:29 giallu Exp $ 22 # -------------------------------------------------------- 23 24 if ( ON == config_get( 'use_jpgraph' ) ) { 25 $t_jpgraph_path = config_get( 'jpgraph_path' ); 26 27 require_once( $t_jpgraph_path.'jpgraph.php' ); 28 require_once( $t_jpgraph_path.'jpgraph_line.php' ); 29 require_once( $t_jpgraph_path.'jpgraph_bar.php' ); 30 require_once( $t_jpgraph_path.'jpgraph_pie.php' ); 31 require_once( $t_jpgraph_path.'jpgraph_pie3d.php' ); 32 require_once( $t_jpgraph_path.'jpgraph_canvas.php' ); 33 34 } 35 36 function graph_get_font() { 37 $t_font_map = array( 38 'arial' => FF_ARIAL, 39 'verdana' => FF_VERDANA, 40 'courier' => FF_COURIER, 41 'comic' => FF_COMIC, 42 'times' => FF_TIMES, 43 'georgia' => FF_GEORGIA, 44 'trebuche' => FF_TREBUCHE, 45 'vera' => FF_VERA, 46 'veramono' => FF_VERAMONO, 47 'veraserif' => FF_VERASERIF ); 48 49 $t_font = config_get( 'graph_font', ''); 50 if ( isset( $t_font_map[$t_font] ) ) { 51 return $t_font_map[$t_font]; 52 } else { 53 return FF_FONT1; 54 } 55 } 56 57 ### Graph API ### 58 # -------------------- 59 # graphing routines 60 # -------------------- 61 function graph_bar( $p_metrics, $p_title='', $p_graph_width = 350, $p_graph_height = 400 ){ 62 63 $t_graph_font = graph_get_font(); 64 65 error_check( is_array( $p_metrics ) ? array_sum( $p_metrics ) : 0, $p_title ); 66 67 $graph = new Graph( $p_graph_width, $p_graph_height ); 68 $graph->img->SetMargin(40,40,40,170); 69 if ( ON == config_get_global( 'jpgraph_antialias' ) ) { 70 $graph->img->SetAntiAliasing(); 71 } 72 $graph->SetScale('textlin'); 73 $graph->SetMarginColor('white'); 74 $graph->SetFrame(false); 75 $graph->title->Set($p_title); 76 $graph->title->SetFont( $t_graph_font, FS_BOLD ); 77 $graph->xaxis->SetTickLabels( array_keys( $p_metrics ) ); 78 if ( FF_FONT2 <= $t_graph_font ) { 79 $graph->xaxis->SetLabelAngle(60); 80 } else { 81 $graph->xaxis->SetLabelAngle(90); # can't rotate non truetype fonts 82 } 83 $graph->xaxis->SetFont( $t_graph_font ); 84 85 $graph->legend->SetFont( $t_graph_font ); 86 87 $graph->yaxis->scale->ticks->SetDirection(-1); 88 $graph->yaxis->SetFont( $t_graph_font ); 89 90 $p1 = new BarPlot( array_values( $p_metrics ) ); 91 $p1->SetFillColor('yellow'); 92 $p1->SetWidth(0.8); 93 $graph->Add($p1); 94 if ( helper_show_queries() ) { 95 $graph->subtitle->Set( db_count_queries() . ' queries (' . db_count_unique_queries() . ' unique) (' . db_time_queries() . 'sec)' ); 96 $graph->subtitle->SetFont( $t_graph_font, FS_NORMAL, 8 ); 97 } 98 99 $graph->Stroke(); 100 101 } 102 103 # Function which displays the charts using the absolute values according to the status (opened/closed/resolved) 104 function graph_group( $p_metrics, $p_title='', $p_graph_width = 350, $p_graph_height = 400, $p_baseline = 100 ){ 105 # $p_metrics is an array of three arrays 106 # $p_metrics['open'] = array( 'enum' => value, ...) 107 # $p_metrics['resolved'] 108 # $p_metrics['closed'] 109 110 $t_graph_font = graph_get_font(); 111 112 # count up array portions that are set 113 $t_count = 0; 114 foreach ( array( 'open', 'resolved', 'closed' ) as $t_label ) { 115 if ( is_array( $p_metrics[$t_label] ) ) { 116 $t_count += array_sum( $p_metrics[$t_label] ); 117 } 118 } 119 120 error_check( $t_count, $p_title ); 121 122 # calculate totals 123 $total = graph_total_metrics( $p_metrics ); 124 125 #defines margin according to height 126 $graph = new Graph( $p_graph_width, $p_graph_height ); 127 $graph->img->SetMargin( 45, 35, 35, $p_baseline ); 128 if ( ON == config_get_global( 'jpgraph_antialias' ) ) { 129 $graph->img->SetAntiAliasing(); 130 } 131 $graph->SetScale('textlin'); 132 $graph->SetMarginColor('white'); 133 $graph->SetFrame(false); 134 $graph->title->SetFont( $t_graph_font, FS_BOLD ); 135 $graph->title->Set($p_title); 136 $graph->xaxis->SetTickLabels( array_keys( $p_metrics['open'] ) ); 137 if ( FF_FONT2 <= $t_graph_font ) { 138 $graph->xaxis->SetLabelAngle(60); 139 } else { 140 $graph->xaxis->SetLabelAngle(90); # can't rotate non truetype fonts 141 } 142 $graph->xaxis->SetFont( $t_graph_font ); 143 $graph->legend->Pos(0.05, 0.08); 144 $graph->legend->SetFont( $t_graph_font ); 145 146 $graph->yaxis->scale->ticks->SetDirection(-1); 147 $graph->yaxis->SetFont( $t_graph_font ); 148 $graph->yscale->SetGrace(10); 149 150 #adds on the same graph 151 $tot = new BarPlot( array_values( $total ) ); 152 $tot->SetFillColor('lightblue'); 153 $tot->SetWidth(0.7); 154 $tot->SetLegend( lang_get( 'legend_total' ) ); 155 $graph->Add($tot); 156 157 $p1 = new BarPlot( array_values( $p_metrics['open'] ) ); 158 $p1->SetFillColor('yellow'); 159 $p1->SetWidth(1); 160 $p1->SetLegend( lang_get( 'legend_opened' ) ); 161 162 $p2 = new BarPlot( array_values( $p_metrics['closed'] ) ); 163 $p2->SetFillColor('blue'); 164 $p2->SetWidth(1); 165 $p2->SetLegend( lang_get( 'legend_closed' ) ); 166 167 $p3 = new BarPlot( array_values( $p_metrics['resolved'] ) ); 168 $p3->SetFillColor('red'); 169 $p3->SetWidth(1); 170 $p3->SetLegend( lang_get( 'legend_resolved' ) ); 171 172 $gbplot = new GroupBarPlot(array($p1,$p3,$p2)); 173 $graph->Add($gbplot); 174 175 if ( helper_show_queries() ) { 176 $graph->subtitle->Set( db_count_queries() . ' queries (' . db_count_unique_queries() . ' unique) (' . db_time_queries() . 'sec)' ); 177 $graph->subtitle->SetFont( $t_graph_font, FS_NORMAL, 8 ); 178 } 179 180 $graph->Stroke(); 181 182 } 183 184 # -------------------- 185 # Function that displays charts in % according to the status 186 # @@@ this function is not used... 187 function graph_group_pct( $p_title='', $p_graph_width = 350, $p_graph_height = 400 ){ 188 global $enum_name, $enum_name_count; 189 global $open_bug_count, $closed_bug_count, $resolved_bug_count; 190 191 error_check( $open_bug_count + $closed_bug_count + $resolved_bug_count, $p_title ); 192 193 $graph = new Graph(250,400); 194 $graph->img->SetMargin(35,35,35,150); 195 if ( ON == config_get_global( 'jpgraph_antialias' ) ) { 196 $graph->img->SetAntiAliasing(); 197 } 198 $graph->SetScale('textlin'); 199 $graph->SetMarginColor('white'); 200 $graph->SetFrame(false); 201 $graph->title->Set($p_title); 202 $graph->xaxis->SetTickLabels($enum_name); 203 $graph->xaxis->SetLabelAngle(90); 204 205 $graph->yaxis->scale->ticks->SetDirection(-1); 206 207 $p1 = new BarPlot($open_bug_count); 208 $p1->SetFillColor('yellow'); 209 $p1->SetWidth(0.8); 210 $p1->SetLegend( lang_get( 'legend_opened' ) ); 211 212 $p2 = new BarPlot($closed_bug_count); 213 $p2->SetFillColor('blue'); 214 $p2->SetWidth(0.8); 215 $p2->SetLegend( lang_get( 'legend_closed' ) ); 216 217 $p3 = new BarPlot($resolved_bug_count); 218 $p3->SetFillColor('red'); 219 $p3->SetWidth(0.8); 220 $p3->SetLegend( lang_get( 'legend_resolved' ) ); 221 222 $gbplot = new GroupBarPlot(array($p1,$p2,$p3)); 223 224 $graph->Add($gbplot); 225 if ( helper_show_queries() ) { 226 $graph->subtitle->Set( db_count_queries() . ' queries (' . db_count_unique_queries() . ' unique)' ); 227 } 228 $graph->Stroke(); 229 } 230 231 # -------------------- 232 # Function that displays pie charts 233 function graph_pie( $p_metrics, $p_title='', 234 $p_graph_width = 500, $p_graph_height = 350, $p_center = 0.4, $p_poshorizontal = 0.10, $p_posvertical = 0.09 ){ 235 236 $t_graph_font = graph_get_font(); 237 238 error_check( is_array( $p_metrics ) ? array_sum( $p_metrics ) : 0, $p_title ); 239 240 $graph = new PieGraph( $p_graph_width, $p_graph_height); 241 $graph->img->SetMargin(40,40,40,100); 242 $graph->title->Set($p_title); 243 $graph->title->SetFont( $t_graph_font, FS_BOLD ); 244 245 $graph->SetMarginColor('white'); 246 $graph->SetFrame(false); 247 248 $graph->legend->Pos($p_poshorizontal, $p_posvertical); 249 $graph->legend->SetFont( $t_graph_font ); 250 251 $p1 = new PiePlot3d( array_values( $p_metrics ) ); // should be reversed? 252 $p1->SetTheme('earth'); 253 #$p1->SetTheme("sand"); 254 $p1->SetCenter($p_center); 255 $p1->SetAngle(60); 256 $p1->SetLegends( array_keys( $p_metrics ) ); 257 258 # Label format 259 $p1->value->SetFormat('%2.0f'); 260 $p1->value->Show(); 261 $p1->value->SetFont( $t_graph_font ); 262 263 $graph->Add($p1); 264 if ( helper_show_queries() ) { 265 $graph->subtitle->Set( db_count_queries() . ' queries (' . db_count_unique_queries() . ' unique) (' . db_time_queries() . 'sec)' ); 266 $graph->subtitle->SetFont( $t_graph_font, FS_NORMAL, 8 ); 267 } 268 $graph->Stroke(); 269 } 270 271 # -------------------- 272 function graph_cumulative_bydate( $p_metrics, $p_graph_width = 300, $p_graph_height = 380 ){ 273 274 $t_graph_font = graph_get_font(); 275 error_check( is_array( $p_metrics ) ? count($p_metrics) : 0, lang_get( 'cumulative' ) . ' ' . lang_get( 'by_date' ) ); 276 277 foreach ($p_metrics as $i=>$vals) { 278 if ( $i > 0 ) { 279 $plot_date[] = $i; 280 $reported_plot[] = $p_metrics[$i][0]; 281 $resolved_plot[] = $p_metrics[$i][1]; 282 $still_open_plot[] = $p_metrics[$i][2]; 283 } 284 } 285 286 $graph = new Graph( $p_graph_width, $p_graph_height ); 287 $graph->img->SetMargin(40,40,40,170); 288 if ( ON == config_get_global( 'jpgraph_antialias' ) ) { 289 $graph->img->SetAntiAliasing(); 290 } 291 $graph->SetScale('linlin'); 292 $graph->SetMarginColor('white'); 293 $graph->SetFrame(false); 294 $graph->title->Set( lang_get( 'cumulative' ) . ' ' . lang_get( 'by_date' ) ); 295 $graph->title->SetFont( $t_graph_font, FS_BOLD ); 296 297 $graph->legend->Pos(0.05,0.9,'right','bottom'); 298 $graph->legend->SetShadow(false); 299 $graph->legend->SetFillColor('white'); 300 $graph->legend->SetLayout(LEGEND_HOR); 301 $graph->legend->SetFont( $t_graph_font ); 302 303 $graph->yaxis->scale->ticks->SetDirection(-1); 304 $graph->yaxis->SetFont( $t_graph_font ); 305 306 if ( FF_FONT2 <= $t_graph_font ) { 307 $graph->xaxis->SetLabelAngle(60); 308 } else { 309 $graph->xaxis->SetLabelAngle(90); # can't rotate non truetype fonts 310 } 311 $graph->xaxis->SetLabelFormatCallback('graph_date_format'); 312 $graph->xaxis->SetFont( $t_graph_font ); 313 314 $p1 = new LinePlot($reported_plot, $plot_date); 315 $p1->SetColor('blue'); 316 $p1->SetCenter(); 317 $p1->SetLegend( lang_get( 'legend_reported' ) ); 318 $graph->Add($p1); 319 320 $p3 = new LinePlot($still_open_plot, $plot_date); 321 $p3->SetColor('red'); 322 $p3->SetCenter(); 323 $p3->SetLegend( lang_get( 'legend_still_open' ) ); 324 $graph->Add($p3); 325 326 $p2 = new LinePlot($resolved_plot, $plot_date); 327 $p2->SetColor('black'); 328 $p2->SetCenter(); 329 $p2->SetLegend( lang_get( 'legend_resolved' ) ); 330 $graph->Add($p2); 331 332 if ( helper_show_queries() ) { 333 $graph->subtitle->Set( db_count_queries() . ' queries (' . db_count_unique_queries() . ' unique) (' . db_time_queries() . 'sec)' ); 334 $graph->subtitle->SetFont( $t_graph_font, FS_NORMAL, 8 ); 335 } 336 $graph->Stroke(); 337 } 338 339 340 # -------------------- 341 function graph_bydate( $p_metrics, $p_labels, $p_title, $p_graph_width = 300, $p_graph_height = 380 ){ 342 343 $t_graph_font = graph_get_font(); 344 error_check( is_array( $p_metrics ) ? count($p_metrics) : 0, lang_get( 'by_date' ) ); 345 346 $graph = new Graph( $p_graph_width, $p_graph_height ); 347 $graph->img->SetMargin(40,140,40,100); 348 if ( ON == config_get_global( 'jpgraph_antialias' ) ) { 349 $graph->img->SetAntiAliasing(); 350 } 351 $graph->SetScale('linlin'); 352 $graph->SetMarginColor('white'); 353 $graph->SetFrame(false); 354 $graph->title->Set( lang_get( 'by_date' ) ); 355 $graph->title->SetFont( $t_graph_font, FS_BOLD ); 356 357 $graph->legend->Pos(0.01,0.05,'right','top'); 358 $graph->legend->SetShadow(false); 359 $graph->legend->SetFillColor('white'); 360 $graph->legend->SetLayout(LEGEND_VERT); 361 $graph->legend->SetFont( $t_graph_font ); 362 363 $graph->yaxis->scale->ticks->SetDirection(-1); 364 $graph->yaxis->SetFont( $t_graph_font ); 365 $graph->yaxis->scale->SetAutoMin(0); 366 367 if ( FF_FONT2 <= $t_graph_font ) { 368 $graph->xaxis->SetLabelAngle(60); 369 } else { 370 $graph->xaxis->SetLabelAngle(90); # can't rotate non truetype fonts 371 } 372 $graph->xaxis->SetLabelFormatCallback('graph_date_format'); 373 $graph->xaxis->SetFont( $t_graph_font ); 374 375 $t_line_colours = config_get( 'graph_colors' ); 376 $t_count_colours = count($t_line_colours); 377 $t_lines = count($p_metrics) - 1; 378 $t_line = array(); 379 for ( $i = 1; $i <= $t_lines; $i++) { 380 $t_line[$i] = new LinePlot($p_metrics[$i], $p_metrics[0]); 381 $t_line[$i]->SetColor($t_line_colours[$i % $t_count_colours]); 382 $t_line[$i]->SetCenter(); 383 $t_line[$i]->SetLegend( lang_get_defaulted( $p_labels[$i] ) ); 384 $graph->Add($t_line[$i]); 385 } 386 387 if ( helper_show_queries() ) { 388 $graph->subtitle->Set( db_count_queries() . ' queries (' . db_count_unique_queries() . ' unique) (' . db_time_queries() . 'sec)' ); 389 $graph->subtitle->SetFont( $t_graph_font, FS_NORMAL, 8 ); 390 } 391 $graph->Stroke(); 392 } 393 394 395 # -------------------- 396 # utilities 397 # -------------------- 398 function graph_total_metrics( $p_metrics ){ 399 foreach ( $p_metrics['open'] as $t_enum => $t_value ) { 400 $total[$t_enum] = $t_value + $p_metrics['resolved'][$t_enum] + $p_metrics['closed'][$t_enum]; 401 } 402 return $total; 403 } 404 405 406 407 # -------------------- 408 # Data Extractions 409 # -------------------- 410 # -------------------- 411 # summarize metrics by a single field in the bug table 412 function create_bug_enum_summary( $p_enum_string, $p_enum ) { 413 $t_project_id = helper_get_current_project(); 414 $t_bug_table = config_get( 'mantis_bug_table' ); 415 $t_user_id = auth_get_current_user_id(); 416 $specific_where = " AND " . helper_project_specific_where( $t_project_id, $t_user_id ); 417 418 $t_arr = explode_enum_string( $p_enum_string ); 419 $enum_count = count( $t_arr ); 420 for ($i=0;$i<$enum_count;$i++) { 421 $t_s = explode_enum_arr( $t_arr[$i] ); 422 $c_s[0] = addslashes($t_s[0]); 423 $t_key = get_enum_to_string( $p_enum_string, $t_s[0] ); 424 425 $query = "SELECT COUNT(*) 426 FROM $t_bug_table 427 WHERE $p_enum='$c_s[0]' $specific_where"; 428 $result = db_query( $query ); 429 $t_metrics[$t_key] = db_result( $result, 0 ); 430 } # end for 431 return $t_metrics; 432 } 433 434 # Function which gives the absolute values according to the status (opened/closed/resolved) 435 function enum_bug_group( $p_enum_string, $p_enum ) { 436 $t_bug_table = config_get( 'mantis_bug_table' ); 437 438 $t_project_id = helper_get_current_project(); 439 $t_bug_table = config_get( 'mantis_bug_table' ); 440 $t_user_id = auth_get_current_user_id(); 441 $t_res_val = config_get( 'bug_resolved_status_threshold' ); 442 $t_clo_val = CLOSED; 443 $specific_where = " AND " . helper_project_specific_where( $t_project_id, $t_user_id ); 444 445 $t_arr = explode_enum_string( $p_enum_string ); 446 $enum_count = count( $t_arr ); 447 for ( $i=0; $i < $enum_count; $i++) { 448 $t_s = explode( ':', $t_arr[$i] ); 449 $t_key = get_enum_to_string( $p_enum_string, $t_s[0] ); 450 451 # Calculates the number of bugs opened and puts the results in a table 452 $query = "SELECT COUNT(*) 453 FROM $t_bug_table 454 WHERE $p_enum='$t_s[0]' AND 455 status<'$t_res_val' $specific_where"; 456 $result2 = db_query( $query ); 457 $t_metrics['open'][$t_key] = db_result( $result2, 0, 0); 458 459 # Calculates the number of bugs closed and puts the results in a table 460 $query = "SELECT COUNT(*) 461 FROM $t_bug_table 462 WHERE $p_enum='$t_s[0]' AND 463 status='$t_clo_val' $specific_where"; 464 $result2 = db_query( $query ); 465 $t_metrics['closed'][$t_key] = db_result( $result2, 0, 0); 466 467 # Calculates the number of bugs resolved and puts the results in a table 468 $query = "SELECT COUNT(*) 469 FROM $t_bug_table 470 WHERE $p_enum='$t_s[0]' AND 471 status>='$t_res_val' AND 472 status<'$t_clo_val' $specific_where"; 473 $result2 = db_query( $query ); 474 $t_metrics['resolved'][$t_key] = db_result( $result2, 0, 0); 475 } ### end for 476 477 return $t_metrics; 478 } 479 480 # -------------------- 481 function create_developer_summary() { 482 483 $t_project_id = helper_get_current_project(); 484 $t_user_table = config_get( 'mantis_user_table' ); 485 $t_bug_table = config_get( 'mantis_bug_table' ); 486 $t_user_id = auth_get_current_user_id(); 487 $specific_where = " AND " . helper_project_specific_where( $t_project_id, $t_user_id ); 488 489 $t_res_val = config_get( 'bug_resolved_status_threshold' ); 490 $t_clo_val = CLOSED; 491 492 $query = "SELECT handler_id, status 493 FROM $t_bug_table 494 WHERE handler_id != '' $specific_where"; 495 $result = db_query( $query ); 496 $t_total_handled = db_num_rows( $result ); 497 498 $t_handler_arr = array(); 499 for ( $i = 0; $i < $t_total_handled; $i++ ) { 500 $row = db_fetch_array( $result ); 501 if ( !isset( $t_handler_arr[$row['handler_id']] ) ) { 502 $t_handler_arr[$row['handler_id']]['res'] = 0; 503 $t_handler_arr[$row['handler_id']]['open'] = 0; 504 $t_handler_arr[$row['handler_id']]['close'] = 0; 505 } 506 if ( $row['status'] >= $t_res_val ) { 507 if ( $row['status'] >= $t_clo_val ) { 508 $t_handler_arr[$row['handler_id']]['close']++; 509 } else { 510 $t_handler_arr[$row['handler_id']]['res']++; 511 } 512 } else { 513 $t_handler_arr[$row['handler_id']]['open']++; 514 } 515 } 516 517 if ( count( $t_handler_arr ) == 0 ) { 518 return array( 'open' => array() ); 519 } 520 521 $t_imploded_handlers = implode( ',', array_keys( $t_handler_arr ) ); 522 $query = "SELECT id, username 523 FROM $t_user_table 524 WHERE id IN ($t_imploded_handlers) 525 ORDER BY username"; 526 $result = db_query( $query ); 527 $user_count = db_num_rows( $result ); 528 529 for ($i=0;$i<$user_count;$i++) { 530 $row = db_fetch_array( $result ); 531 extract( $row, EXTR_PREFIX_ALL, 'v' ); 532 533 $t_metrics['open'][$v_username] = $t_handler_arr[$v_id]['open']; 534 $t_metrics['resolved'][$v_username] = $t_handler_arr[$v_id]['res']; 535 $t_metrics['closed'][$v_username] = $t_handler_arr[$v_id]['close']; 536 } # end for 537 return $t_metrics; 538 } 539 540 # -------------------- 541 function create_reporter_summary() { 542 global $reporter_name, $reporter_count; 543 544 545 $t_project_id = helper_get_current_project(); 546 $t_user_table = config_get( 'mantis_user_table' ); 547 $t_bug_table = config_get( 'mantis_bug_table' ); 548 $t_user_id = auth_get_current_user_id(); 549 $specific_where = " AND " . helper_project_specific_where( $t_project_id, $t_user_id ); 550 551 $query = "SELECT reporter_id 552 FROM $t_bug_table 553 WHERE id != '' $specific_where"; 554 $result = db_query( $query ); 555 $t_total_reported = db_num_rows( $result ); 556 557 $t_reporter_arr = array(); 558 for ( $i = 0; $i < $t_total_reported; $i++ ) { 559 $row = db_fetch_array( $result ); 560 561 if ( isset( $t_reporter_arr[$row['reporter_id']] ) ) { 562 $t_reporter_arr[$row['reporter_id']]++; 563 } else { 564 $t_reporter_arr[$row['reporter_id']] = 1; 565 } 566 } 567 568 if ( count( $t_reporter_arr ) == 0 ) { 569 return array(); 570 } 571 572 $t_imploded_reporters = implode( ',', array_keys( $t_reporter_arr ) ); 573 $query = "SELECT id, username 574 FROM $t_user_table 575 WHERE id IN ($t_imploded_reporters) 576 ORDER BY username"; 577 $result = db_query( $query ); 578 $user_count = db_num_rows( $result ); 579 580 for ($i=0;$i<$user_count;$i++) { 581 $row = db_fetch_array( $result ); 582 extract( $row, EXTR_PREFIX_ALL, 'v' ); 583 584 $t_metrics[$v_username] = $t_reporter_arr[$v_id]; 585 } # end for 586 return $t_metrics; 587 } 588 589 # -------------------- 590 function create_category_summary() { 591 global $category_name, $category_bug_count; 592 593 $t_project_id = helper_get_current_project(); 594 $t_cat_table = config_get( 'mantis_project_category_table' ); 595 $t_bug_table = config_get( 'mantis_bug_table' ); 596 $t_user_id = auth_get_current_user_id(); 597 $specific_where = helper_project_specific_where( $t_project_id, $t_user_id ); 598 599 $query = "SELECT DISTINCT category 600 FROM $t_cat_table 601 WHERE $specific_where 602 ORDER BY category"; 603 $result = db_query( $query ); 604 $category_count = db_num_rows( $result ); 605 if ( 0 == $category_count ) { 606 return array(); 607 } 608 609 for ($i=0;$i<$category_count;$i++) { 610 $row = db_fetch_array( $result ); 611 $t_cat_name = $row['category']; 612 $c_category_name = addslashes($t_cat_name); 613 $query = "SELECT COUNT(*) 614 FROM $t_bug_table 615 WHERE category='$c_category_name' AND $specific_where"; 616 $result2 = db_query( $query ); 617 $t_metrics[$t_cat_name] = db_result( $result2, 0, 0 ); 618 } # end for 619 return $t_metrics; 620 } 621 622 # -------------------- 623 function cmp_dates($a, $b){ 624 if ($a[0] == $b[0]) { 625 return 0; 626 } 627 return ( $a[0] < $b[0] ) ? -1 : 1; 628 } 629 630 # -------------------- 631 function find_date_in_metrics($aDate){ 632 global $metrics; 633 $index = -1; 634 for ($i=0;$i<count($metrics);$i++) { 635 if ($aDate == $metrics[$i][0]){ 636 $index = $i; 637 break; 638 } 639 } 640 return $index; 641 } 642 643 # -------------------- 644 function create_cumulative_bydate(){ 645 646 $t_clo_val = CLOSED; 647 $t_res_val = config_get( 'bug_resolved_status_threshold' ); 648 $t_bug_table = config_get( 'mantis_bug_table' ); 649 $t_history_table = config_get( 'mantis_bug_history_table' ); 650 651 $t_project_id = helper_get_current_project(); 652 $t_user_id = auth_get_current_user_id(); 653 $specific_where = helper_project_specific_where( $t_project_id, $t_user_id ); 654 655 # Get all the submitted dates 656 $query = "SELECT date_submitted 657 FROM $t_bug_table 658 WHERE $specific_where 659 ORDER BY date_submitted"; 660 $result = db_query( $query ); 661 $bug_count = db_num_rows( $result ); 662 663 for ($i=0;$i<$bug_count;$i++) { 664 $row = db_fetch_array( $result ); 665 # rationalise the timestamp to a day to reduce the amount of data 666 $t_date = db_unixtimestamp( $row['date_submitted'] ); 667 $t_date = (int) ( $t_date / 86400 ); 668 669 if ( isset( $metrics[$t_date] ) ){ 670 $metrics[$t_date][0]++; 671 } else { 672 $metrics[$t_date] = array( 1, 0, 0 ); 673 } 674 } 675 676 ### Get all the dates where a transition from not resolved to resolved may have happened 677 # also, get the last updated date for the bug as this may be all the information we have 678 $query = "SELECT $t_bug_table.id, last_updated, date_modified, new_value, old_value 679 FROM $t_bug_table LEFT JOIN $t_history_table 680 ON $t_bug_table.id = $t_history_table.bug_id 681 WHERE $specific_where 682 AND $t_bug_table.status >= '$t_res_val' 683 AND ( ( $t_history_table.new_value >= '$t_res_val' 684 AND $t_history_table.field_name = 'status' ) 685 OR $t_history_table.id is NULL ) 686 ORDER BY $t_bug_table.id, date_modified ASC"; 687 $result = db_query( $query ); 688 $bug_count = db_num_rows( $result ); 689 690 $t_last_id = 0; 691 for ($i=0;$i<$bug_count;$i++) { 692 $row = db_fetch_array( $result ); 693 $t_id = $row['id']; 694 # if h_last_updated is NULL, there were no appropriate history records 695 # (i.e. pre 0.18 data), use last_updated from bug table instead 696 if (NULL == $row['date_modified']) { 697 $t_date = db_unixtimestamp( $row['last_updated'] ); 698 } else { 699 if ( $t_res_val > $row['old_value'] ) { 700 $t_date = db_unixtimestamp( $row['date_modified'] ); 701 } 702 } 703 if ( $t_id <> $t_last_id ) { 704 if ( 0 <> $t_last_id ) { 705 # rationalise the timestamp to a day to reduce the amount of data 706 $t_date_index = (int) ( $t_last_date / 86400 ); 707 708 if ( isset( $metrics[$t_date_index] ) ){ 709 $metrics[$t_date_index][1]++; 710 } else { 711 $metrics[$t_date_index] = array( 0, 1, 0 ); 712 } 713 } 714 $t_last_id = $t_id; 715 } 716 $t_last_date = $t_date; 717 } 718 719 ksort($metrics); 720 721 $metrics_count = count($metrics); 722 $t_last_opened = 0; 723 $t_last_resolved = 0; 724 foreach ($metrics as $i=>$vals) { 725 $t_date = $i * 86400; 726 $t_metrics[$t_date][0] = $t_last_opened = $metrics[$i][0] + $t_last_opened; 727 $t_metrics[$t_date][1] = $t_last_resolved = $metrics[$i][1] + $t_last_resolved; 728 $t_metrics[$t_date][2] = $t_metrics[$t_date][0] - $t_metrics[$t_date][1]; 729 } 730 return $t_metrics; 731 } 732 733 function graph_date_format ($p_date) { 734 return date( config_get( 'short_date_format' ), $p_date ); 735 } 736 737 738 # ---------------------------------------------------- 739 # 740 # Check that there is enough data to create graph 741 # 742 # ---------------------------------------------------- 743 function error_check( $bug_count, $title ) { 744 745 if ( 0 == $bug_count ) { 746 $t_graph_font = graph_get_font(); 747 748 $graph = new CanvasGraph(300,380); 749 750 $txt = new Text( lang_get( 'not_enough_data' ), 150, 100); 751 $txt->Align("center","center","center"); 752 $txt->SetFont( $t_graph_font, FS_BOLD ); 753 $graph->title->Set( $title ); 754 $graph->title->SetFont( $t_graph_font, FS_BOLD ); 755 $graph->AddText($txt); 756 $graph->Stroke(); 757 die(); 758 } 759 } 760 ?>
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 |
![]() |