From: Glenn H. <thr...@us...> - 2004-12-16 22:41:38
|
Update of /cvsroot/mantisbt/mantisbt/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26714/core Modified Files: constant_inc.php graph_api.php tokens_api.php Log Message: fix for 0003512: I have alot of categories and several category graphs show up very small with illegible text. fix for 0003922: Add in ability to have certain graphs in large size fix for 0004651: Legend of two summary graphs not properly set-up fix for 0004929: Inscriptions on the graphs on Apache for Microsoft Windows for CP1251 do not hatch. fix for 0004986: Graphs should cache data - New Config: $g_graph_font - truetype font for graphs - New Config: $g_graph_window_width - window width is used to scale the graphs - New Config: $g_graph_bar_aspect - bar graph aspect ration (height / width) - New Config: $g_graph_summary_graphs_per_row - graphs to put in each row in the advanced summary page Index: graph_api.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/graph_api.php,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -r1.27 -r1.28 --- graph_api.php 14 Dec 2004 22:16:07 -0000 1.27 +++ graph_api.php 16 Dec 2004 22:41:27 -0000 1.28 @@ -18,230 +18,150 @@ require_once( $t_jpgraph_path.'jpgraph_pie.php' ); require_once( $t_jpgraph_path.'jpgraph_pie3d.php' ); require_once( $t_jpgraph_path.'jpgraph_canvas.php' ); - } - - ### Graph API ### - # -------------------- - # Function which gives the absolute values according to the status (opened/closed/resolved) - function enum_bug_group( $p_enum_string, $p_enum ) { - global $g_mantis_bug_table, $enum_name, $enum_name_count; - #these vars are set global so that the other functions can use them - global $open_bug_count, $closed_bug_count, $resolved_bug_count; + } - $enum_name = null; - $enum_name_count = null; + function graph_get_font() { + $t_font_map = array( + 'arial' => FF_ARIAL, + 'verdana' => FF_VERDANA, + 'courier' => FF_COURIER, + 'book' => FF_BOOK, + 'comic' => FF_COMIC, + 'times' => FF_TIMES, + 'georgia' => FF_GEORGIA, + 'trebuche' => FF_TREBUCHE, + 'vera' => FF_VERA, + 'veramono' => FF_VERAMONO, + 'veraserif' => FF_VERASERIF ); - $t_project_id = helper_get_current_project(); - $t_bug_table = config_get( 'mantis_bug_table' ); - $t_user_id = auth_get_current_user_id(); + $t_font = config_get( 'graph_font', ''); + if ( isset( $t_font_map[$t_font] ) ) { + return $t_font_map[$t_font]; + } else { + return FF_FONT1; + } + } - $t_arr = explode_enum_string( $p_enum_string ); - $enum_count = count( $t_arr ); - for ( $i=0; $i < $enum_count; $i++) { - $t_s = explode( ':', $t_arr[$i] ); - $enum_name[] = get_enum_to_string( $p_enum_string, $t_s[0] ); + ### Graph API ### + # -------------------- + # graphing routines + # -------------------- + function graph_bar( $p_metrics, $p_title='', $p_graph_width = 350, $p_graph_height = 400 ){ - if ( ALL_PROJECTS == $t_project_id ) { - # Only projects to which the user have access - $t_accessible_projects_array = user_get_accessible_projects( $t_user_id ); - $specific_where = ' AND (project_id='. implode( ' OR project_id=', $t_accessible_projects_array ).')'; - } else { - $specific_where = " AND project_id='$t_project_id'"; - } + $t_graph_font = graph_get_font(); - # Calculates the number of bugs with $p_enum and puts the results in a table - $query = "SELECT COUNT(*) - FROM $t_bug_table - WHERE $p_enum='$t_s[0]' $specific_where"; - $result = db_query( $query ); - $enum_name_count[]= db_result( $result, 0); + error_check( array_sum( $p_metrics ), $p_title ); + + $graph = new Graph( $p_graph_width, $p_graph_height ); + $graph->img->SetMargin(40,40,40,170); + $graph->img->SetAntiAliasing(); + $graph->SetScale('textlin'); + $graph->SetMarginColor('white'); + $graph->SetFrame(false); + $graph->title->Set($p_title); + $graph->title->SetFont( $t_graph_font, FS_BOLD ); + $graph->xaxis->SetTickLabels( array_keys( $p_metrics ) ); + if ( FF_FONT2 <= $t_graph_font ) { + $graph->xaxis->SetLabelAngle(60); + } else { + $graph->xaxis->SetLabelAngle(90); # can't rotate non truetype fonts + } + $graph->xaxis->SetFont( $t_graph_font ); - $t_res_val = config_get( 'bug_resolved_status_threshold' ); - $t_clo_val = CLOSED; + $graph->legend->SetFont( $t_graph_font ); - # Calculates the number of bugs opened and puts the results in a table - $query = "SELECT COUNT(*) - FROM $t_bug_table - WHERE $p_enum='$t_s[0]' AND - status<'$t_res_val' $specific_where"; - $result2 = db_query( $query ); - $open_bug_count[] = db_result( $result2, 0, 0); + $graph->yaxis->scale->ticks->SetDirection(-1); + $graph->yaxis->SetFont( $t_graph_font ); - # Calculates the number of bugs closed and puts the results in a table - $query = "SELECT COUNT(*) - FROM $t_bug_table - WHERE $p_enum='$t_s[0]' AND - status='$t_clo_val' $specific_where"; - $result2 = db_query( $query ); + $p1 = new BarPlot( array_values( $p_metrics ) ); + $p1->SetFillColor('yellow'); + $p1->SetWidth(0.8); + $graph->Add($p1); + if ( ON == config_get( 'show_queries_count' ) ) { + $graph->subtitle->Set( db_count_queries() . ' queries (' . db_count_unique_queries() . ' unique) (' . db_time_queries() . 'sec)' ); + $graph->subtitle->SetFont( $t_graph_font, FS_NORMAL, 8 ); + } - $closed_bug_count[] = db_result( $result2, 0, 0); + $graph->Stroke(); - # Calculates the number of bugs resolved and puts the results in a table - $query = "SELECT COUNT(*) - FROM $t_bug_table - WHERE $p_enum='$t_s[0]' AND - status>='$t_res_val' AND - status<'$t_clo_val' $specific_where"; - $result2 = db_query( $query ); - $resolved_bug_count[] = db_result( $result2, 0, 0); - } ### end for } - # -------------------- # Function which displays the charts using the absolute values according to the status (opened/closed/resolved) - function graph_group( $p_title='' ){ - global $enum_name, $enum_name_count; - global $open_bug_count, $closed_bug_count, $resolved_bug_count,$height; + function graph_group( $p_metrics, $p_title='', $p_graph_width = 350, $p_graph_height = 400, $p_baseline = 100 ){ + # $p_metrics is an array of three arrays + # $p_metrics['open'] = array( 'enum' => value, ...) + # $p_metrics['resolved'] + # $p_metrics['closed'] + + $t_graph_font = graph_get_font(); - error_check( $open_bug_count + $closed_bug_count + $resolved_bug_count, $p_title ); + error_check( array_sum( $p_metrics['open'] ) + array_sum( $p_metrics['resolved'] ) + array_sum( $p_metrics['closed'] ), $p_title ); + + # calculate totals + $total = graph_total_metrics( $p_metrics ); #defines margin according to height - $graph = new Graph(350,400); - $graph->img->SetMargin(35,35,35,$height); + $graph = new Graph( $p_graph_width, $p_graph_height ); + $graph->img->SetMargin( 45, 35, 35, $p_baseline ); $graph->img->SetAntiAliasing(); $graph->SetScale('textlin'); $graph->SetMarginColor('white'); $graph->SetFrame(false); + $graph->title->SetFont( $t_graph_font, FS_BOLD ); $graph->title->Set($p_title); - $graph->xaxis->SetTickLabels($enum_name); - $graph->xaxis->SetLabelAngle(90); + $graph->xaxis->SetTickLabels( array_keys( $p_metrics['open'] ) ); + if ( FF_FONT2 <= $t_graph_font ) { + $graph->xaxis->SetLabelAngle(60); + } else { + $graph->xaxis->SetLabelAngle(90); # can't rotate non truetype fonts + } + $graph->xaxis->SetFont( $t_graph_font ); $graph->legend->Pos(0.05, 0.08); + $graph->legend->SetFont( $t_graph_font ); $graph->yaxis->scale->ticks->SetDirection(-1); + $graph->yaxis->SetFont( $t_graph_font ); $graph->yscale->SetGrace(10); #adds on the same graph - $tot = new BarPlot($enum_name_count); + $tot = new BarPlot( array_values( $total ) ); $tot->SetFillColor('lightblue'); $tot->SetWidth(0.7); $tot->SetLegend( lang_get( 'legend_total' ) ); $graph->Add($tot); - $p1 = new BarPlot($open_bug_count); + $p1 = new BarPlot( array_values( $p_metrics['open'] ) ); $p1->SetFillColor('yellow'); $p1->SetWidth(1); $p1->SetLegend( lang_get( 'legend_opened' ) ); - $p2 = new BarPlot($closed_bug_count); + $p2 = new BarPlot( array_values( $p_metrics['closed'] ) ); $p2->SetFillColor('blue'); $p2->SetWidth(1); $p2->SetLegend( lang_get( 'legend_closed' ) ); - $p3 = new BarPlot($resolved_bug_count); + $p3 = new BarPlot( array_values( $p_metrics['resolved'] ) ); $p3->SetFillColor('red'); $p3->SetWidth(1); $p3->SetLegend( lang_get( 'legend_resolved' ) ); $gbplot = new GroupBarPlot(array($p1,$p3,$p2)); $graph->Add($gbplot); + if ( ON == config_get( 'show_queries_count' ) ) { $graph->subtitle->Set( db_count_queries() . ' queries (' . db_count_unique_queries() . ' unique) (' . db_time_queries() . 'sec)' ); + $graph->subtitle->SetFont( $t_graph_font, FS_NORMAL, 8 ); } + $graph->Stroke(); } # -------------------- - # Function which finds the % according to the status - function enum_bug_group_pct( $p_enum_string, $p_enum ) { - global $enum_name, $enum_name_count; - global $open_bug_count, $closed_bug_count, $resolved_bug_count; - $enum_name = Null; - $enum_name_count = Null; - - $t_project_id = helper_get_current_project(); - $t_bug_table = config_get( 'mantis_bug_table' ); - $t_user_id = auth_get_current_user_id(); - - #calculation per status - $t_res_val = config_get( 'bug_resolved_status_threshold' ); - $t_clo_val = CLOSED; - - if ( ALL_PROJECTS == $t_project_id ) { - # Only projects to which the user have access - $t_accessible_projects_array = user_get_accessible_projects( $t_user_id ); - $specific_where = ' AND (project_id='. implode( ' OR project_id=', $t_accessible_projects_array ).')'; - } else { - $specific_where = " AND project_id='$t_project_id'"; - } - - $query = "SELECT COUNT(*) - FROM $t_bug_table - WHERE status<'$t_res_val' $specific_where"; - $result = db_query( $query ); - $total_open = db_result( $result, 0); - - - # Bugs closed - $query = "SELECT COUNT(*) - FROM $t_bug_table - WHERE status='$t_clo_val' $specific_where"; - $result = db_query( $query ); - $total_close= db_result( $result, 0); - - - # Bugs resolved - $query = "SELECT COUNT(*) - FROM $t_bug_table - WHERE status>='$t_res_val' AND - status<'$t_clo_val' $specific_where"; - $result = db_query( $query ); - $total_resolved = db_result( $result, 0); - - - $t_arr = explode_enum_string( $p_enum_string ); - $enum_count = count( $t_arr ); - for ($i=0;$i<$enum_count;$i++) { - $t_s = explode( ':', $t_arr[$i] ); - $enum_name[] = get_enum_to_string( $p_enum_string, $t_s[0] ); - - $query = "SELECT COUNT(*) - FROM $t_bug_table - WHERE $p_enum='$t_s[0]' $specific_where"; - $result = db_query( $query ); - $t_enum_count[]= db_result( $result, 0 ); - - $query = "SELECT COUNT(*) - FROM $t_bug_table - WHERE $p_enum='$t_s[0]' AND - status<'$t_res_val' $specific_where"; - $result2 = db_query( $query ); - if ( 0 < $total_open ) { - $open_bug_count[] = db_result( $result2, 0, 0) / $total_open * 100; - }else{ - $open_bug_count[] = 0; - } - - $query = "SELECT COUNT(*) - FROM $t_bug_table - WHERE $p_enum='$t_s[0]' AND - status='$t_clo_val' $specific_where"; - $result2 = db_query( $query ); - if ( 0 < $total_close ) { - $closed_bug_count[] = db_result( $result2, 0, 0) / $total_close * 100; - }else{ - $closed_bug_count[] = 0; - } - - $query = "SELECT COUNT(*) - FROM $t_bug_table - WHERE $p_enum='$t_s[0]' AND - status>='$t_res_val' AND - status<'$t_clo_val' $specific_where"; - $result2 = db_query( $query ); - if ( 0 < $total_resolved ) { - $resolved_bug_count[] = db_result( $result2, 0, 0) / $total_resolved * 100; - }else{ - $resolved_bug_count[] = 0; - } - - } ### end for - } - - # -------------------- # Function that displays charts in % according to the status - function graph_group_pct( $p_title='' ){ + # @@@ this function is not used... + function graph_group_pct( $p_title='', $p_graph_width = 350, $p_graph_height = 400 ){ global $enum_name, $enum_name_count; global $open_bug_count, $closed_bug_count, $resolved_bug_count; @@ -284,231 +204,211 @@ } # -------------------- - # Function which gets the values in % - function create_bug_enum_summary_pct( $p_enum_string, $p_enum ) { - global $enum_name, $enum_name_count, $total; - $enum_name = Null; - $enum_name_count = Null; - - $t_project_id = helper_get_current_project(); - $t_bug_table = config_get( 'mantis_bug_table' ); - $t_user_id = auth_get_current_user_id(); - - if ( ALL_PROJECTS == $t_project_id ) { - # Only projects to which the user have access - $t_accessible_projects_array = user_get_accessible_projects( $t_user_id ); - $specific_where = ' (project_id='. implode( ' OR project_id=', $t_accessible_projects_array ).')'; - } else { - $specific_where = " project_id='$t_project_id'"; - } - - $query = "SELECT COUNT(*) - FROM $t_bug_table - WHERE $specific_where"; - $result = db_query( $query ); - $total = db_result( $result, 0 ); - if ( 0 == $total ) { - return; - } - - $t_arr = explode_enum_string( $p_enum_string ); - $enum_count = count( $t_arr ); - for ($i=0;$i<$enum_count;$i++) { - $t_s = explode( ':', $t_arr[$i] ); - $enum_name[] = get_enum_to_string( $p_enum_string, $t_s[0] ); - - $query = "SELECT COUNT(*) - FROM $t_bug_table - WHERE $p_enum='$t_s[0]' AND $specific_where"; - - $result = db_query( $query ); - $enum_name_count[] = db_result( $result, 0 ) / $total * 100; - } ### end for - } - - # -------------------- # Function that displays pie charts - function graph_bug_enum_summary_pct( $p_title=''){ - global $enum_name, $enum_name_count, $center, $poshorizontal, $posvertical; + function graph_pie( $p_metrics, $p_title='', + $p_graph_width = 500, $p_graph_height = 350, $p_center = 0.4, $p_poshorizontal = 0.10, $p_posvertical = 0.09 ){ - error_check( $enum_name_count, $p_title ); + $t_graph_font = graph_get_font(); + + error_check( array_sum( $p_metrics ), $p_title ); - if ( 0 == count($enum_name) ) { - return; - } - $graph = new PieGraph(500,350); + $graph = new PieGraph( $p_graph_width, $p_graph_height); $graph->img->SetMargin(40,40,40,100); $graph->title->Set($p_title); + $graph->title->SetFont( $t_graph_font, FS_BOLD ); $graph->SetMarginColor('white'); $graph->SetFrame(false); - $graph->legend->Pos($poshorizontal, $posvertical); + $graph->legend->Pos($p_poshorizontal, $p_posvertical); + $graph->legend->SetFont( $t_graph_font ); - $p1 = new PiePlot3d($enum_name_count); + $p1 = new PiePlot3d( array_values( $p_metrics ) ); $p1->SetTheme('earth'); #$p1->SetTheme("sand"); - $p1->SetCenter($center); + $p1->SetCenter($p_center); $p1->SetAngle(60); - $p1->SetLegends($enum_name); + $p1->SetLegends( array_keys( $p_metrics ) ); # Label format $p1->value->SetFormat('%2.0f'); $p1->value->Show(); + $p1->value->SetFont( $t_graph_font ); $graph->Add($p1); if ( ON == config_get( 'show_queries_count' ) ) { - $graph->subtitle->Set( db_count_queries() . ' queries (' . db_count_unique_queries() . ' unique)' ); + $graph->subtitle->Set( db_count_queries() . ' queries (' . db_count_unique_queries() . ' unique) (' . db_time_queries() . 'sec)' ); + $graph->subtitle->SetFont( $t_graph_font, FS_NORMAL, 8 ); } $graph->Stroke(); } # -------------------- - function create_category_summary_pct() { - global $category_name, $category_bug_count; - - $t_project_id = helper_get_current_project(); - $t_bug_table = config_get( 'mantis_bug_table' ); - $t_cat_table = config_get( 'mantis_project_category_table' ); - $t_user_id = auth_get_current_user_id(); - - if ( ALL_PROJECTS == $t_project_id ) { - # Only projects to which the user have access - $t_accessible_projects_array = user_get_accessible_projects( $t_user_id ); - $specific_where = ' (t.project_id='. implode( ' OR t.project_id=', $t_accessible_projects_array ).')'; - } else { - $specific_where = " t.project_id='$t_project_id'"; - } + function graph_cumulative_bydate( $p_metrics, $p_graph_width = 300, $p_graph_height = 380 ){ - $query = "SELECT COUNT(*) - FROM $t_bug_table as t - WHERE $specific_where"; - $result = db_query( $query ); - $total = db_result( $result, 0 ); - if ( 0 == $total ) { - return; + $t_graph_font = graph_get_font(); + error_check( count($p_metrics), lang_get( 'cumulative' ) . ' ' . lang_get( 'by_date' ) ); + + foreach ($p_metrics as $i=>$vals) { + if ( $i > 0 ) { + $plot_date[] = $i; + $reported_plot[] = $p_metrics[$i][0]; + $resolved_plot[] = $p_metrics[$i][1]; + $still_open_plot[] = $p_metrics[$i][2]; + } } - $query = "SELECT t.category, t.project_id, count(b.id) as bugs - FROM $t_cat_table as t LEFT JOIN $t_bug_table as b - ON t.category = b.category AND t.project_id = b.project_id - WHERE $specific_where - GROUP BY project_id, category - ORDER BY project_id, category"; - $result = db_query( $query ); - $category_count = db_num_rows( $result ); + $graph = new Graph( $p_graph_width, $p_graph_height ); + $graph->img->SetMargin(40,40,40,170); + $graph->img->SetAntiAliasing(); + $graph->SetScale('linlin'); + $graph->SetMarginColor('white'); + $graph->SetFrame(false); + $graph->title->Set( lang_get( 'cumulative' ) . ' ' . lang_get( 'by_date' ) ); + $graph->title->SetFont( $t_graph_font, FS_BOLD ); - for ($i=0;$i<$category_count;$i++) { - $row = db_fetch_array( $result ); - $category_name[] = $row['category']; - $category_bug_count[] = $row['bugs'] / $total * 100; - } ### end for - } + $graph->legend->Pos(0.05,0.9,'right','bottom'); + $graph->legend->SetShadow(false); + $graph->legend->SetFillColor('white'); + $graph->legend->SetLayout(LEGEND_HOR); + $graph->legend->SetFont( $t_graph_font ); - # -------------------- - # Pie chart which dispays by categories - function graph_category_summary_pct( $p_title=''){ - global $category_name, $category_bug_count; + $graph->yaxis->scale->ticks->SetDirection(-1); + $graph->yaxis->SetFont( $t_graph_font ); - error_check( $category_bug_count, $p_title ); - - if ( 0 == count( $category_bug_count) ) { - return; + if ( FF_FONT2 <= $t_graph_font ) { + $graph->xaxis->SetLabelAngle(60); + } else { + $graph->xaxis->SetLabelAngle(90); # can't rotate non truetype fonts } - $graph = new PieGraph(600,450); - $graph->img->SetMargin(40,40,40,100); - $graph->title->Set($p_title); + $graph->xaxis->SetLabelFormatCallback('graph_date_format'); + $graph->xaxis->SetFont( $t_graph_font ); - $graph->SetMarginColor('white'); - $graph->SetFrame(false); - $graph->legend->Pos(0.10,0.09); + $p1 = new LinePlot($reported_plot, $plot_date); + $p1->SetColor('blue'); + $p1->SetCenter(); + $p1->SetLegend( lang_get( 'legend_reported' ) ); + $graph->Add($p1); - $p1 = new PiePlot3d($category_bug_count); - $p1->SetTheme('earth'); - $p1->SetCenter(0.3); - $p1->SetAngle(60); - $p1->SetLegends($category_name); - $p1->SetSize(0.27); + $p3 = new LinePlot($still_open_plot, $plot_date); + $p3->SetColor('red'); + $p3->SetCenter(); + $p3->SetLegend( lang_get( 'legend_still_open' ) ); + $graph->Add($p3); - # Label format - $p1->value->SetFormat('%2.0f'); - $p1->value->Show(); + $p2 = new LinePlot($resolved_plot, $plot_date); + $p2->SetColor('black'); + $p2->SetCenter(); + $p2->SetLegend( lang_get( 'legend_resolved' ) ); + $graph->Add($p2); - $graph->Add($p1); if ( ON == config_get( 'show_queries_count' ) ) { - $graph->subtitle->Set( db_count_queries() . ' queries (' . db_count_unique_queries() . ' unique)' ); + $graph->subtitle->Set( db_count_queries() . ' queries (' . db_count_unique_queries() . ' unique) (' . db_time_queries() . 'sec)' ); + $graph->subtitle->SetFont( $t_graph_font, FS_NORMAL, 8 ); } $graph->Stroke(); + } + # -------------------- + # utilities + # -------------------- + function graph_total_metrics( $p_metrics ){ + foreach ( $p_metrics['open'] as $t_enum => $t_value ) { + $total[$t_enum] = $t_value + $p_metrics['resolved'][$t_enum] + $p_metrics['closed'][$t_enum]; + } + return $total; } + + # -------------------- + # Data Extractions + # -------------------- + # -------------------- + # summarize metrics by a single field in the bug table function create_bug_enum_summary( $p_enum_string, $p_enum ) { - global $enum_name, $enum_name_count; - $enum_name = Null; - $enum_name_count = Null; - $t_project_id = helper_get_current_project(); $t_bug_table = config_get( 'mantis_bug_table' ); $t_user_id = auth_get_current_user_id(); + if ( ALL_PROJECTS == $t_project_id ) { + # Only projects to which the user have access + $t_accessible_projects_array = user_get_accessible_projects( $t_user_id ); + $specific_where = ' AND (project_id='. implode( ' OR project_id=', $t_accessible_projects_array ).')'; + } else { + $specific_where = " AND project_id='$t_project_id'"; + } $t_arr = explode_enum_string( $p_enum_string ); $enum_count = count( $t_arr ); for ($i=0;$i<$enum_count;$i++) { $t_s = explode_enum_arr( $t_arr[$i] ); $c_s[0] = addslashes($t_s[0]); - $enum_name[] = get_enum_to_string( $p_enum_string, $t_s[0] ); - - if ( ALL_PROJECTS == $t_project_id ) { - # Only projects to which the user have access - $t_accessible_projects_array = user_get_accessible_projects( $t_user_id ); - $specific_where = ' AND (project_id='. implode( ' OR project_id=', $t_accessible_projects_array ).')'; - } else { - $specific_where = " AND project_id='$t_project_id'"; - } + $t_key = get_enum_to_string( $p_enum_string, $t_s[0] ); $query = "SELECT COUNT(*) FROM $t_bug_table WHERE $p_enum='$c_s[0]' $specific_where"; $result = db_query( $query ); - $enum_name_count[] = db_result( $result, 0 ); + $t_metrics[$t_key] = db_result( $result, 0 ); } # end for + return $t_metrics; } - # -------------------- - function graph_bug_enum_summary( $p_title='' ){ - global $enum_name, $enum_name_count; - - error_check( $enum_name_count, $p_title ); - - $graph = new Graph(300,380); - $graph->img->SetMargin(40,40,40,170); - $graph->img->SetAntiAliasing(); - $graph->SetScale('textlin'); - $graph->SetMarginColor('white'); - $graph->SetFrame(false); - $graph->title->Set($p_title); - $graph->xaxis->SetTickLabels($enum_name); - $graph->xaxis->SetLabelAngle(90); + # Function which gives the absolute values according to the status (opened/closed/resolved) + function enum_bug_group( $p_enum_string, $p_enum ) { + $t_bug_table = config_get( 'mantis_bug_table' ); - $graph->yaxis->scale->ticks->SetDirection(-1); + $t_project_id = helper_get_current_project(); + $t_bug_table = config_get( 'mantis_bug_table' ); + $t_user_id = auth_get_current_user_id(); + $t_res_val = config_get( 'bug_resolved_status_threshold' ); + $t_clo_val = CLOSED; - $p1 = new BarPlot($enum_name_count); - $p1->SetFillColor('yellow'); - $p1->SetWidth(0.8); - $graph->Add($p1); - if ( ON == config_get( 'show_queries_count' ) ) { - $graph->subtitle->Set( db_count_queries() . ' queries (' . db_count_unique_queries() . ' unique)' ); + if ( ALL_PROJECTS == $t_project_id ) { + # Only projects to which the user have access + $t_accessible_projects_array = user_get_accessible_projects( $t_user_id ); + $specific_where = ' AND (project_id='. implode( ' OR project_id=', $t_accessible_projects_array ).')'; + } else { + $specific_where = " AND project_id='$t_project_id'"; } - $graph->Stroke(); + $t_arr = explode_enum_string( $p_enum_string ); + $enum_count = count( $t_arr ); + for ( $i=0; $i < $enum_count; $i++) { + $t_s = explode( ':', $t_arr[$i] ); + $t_key = get_enum_to_string( $p_enum_string, $t_s[0] ); + + # Calculates the number of bugs opened and puts the results in a table + $query = "SELECT COUNT(*) + FROM $t_bug_table + WHERE $p_enum='$t_s[0]' AND + status<'$t_res_val' $specific_where"; + $result2 = db_query( $query ); + $t_metrics['open'][$t_key] = db_result( $result2, 0, 0); + # Calculates the number of bugs closed and puts the results in a table + $query = "SELECT COUNT(*) + FROM $t_bug_table + WHERE $p_enum='$t_s[0]' AND + status='$t_clo_val' $specific_where"; + $result2 = db_query( $query ); + $t_metrics['closed'][$t_key] = db_result( $result2, 0, 0); + + # Calculates the number of bugs resolved and puts the results in a table + $query = "SELECT COUNT(*) + FROM $t_bug_table + WHERE $p_enum='$t_s[0]' AND + status>='$t_res_val' AND + status<'$t_clo_val' $specific_where"; + $result2 = db_query( $query ); + $t_metrics['resolved'][$t_key] = db_result( $result2, 0, 0); + } ### end for + + return $t_metrics; } # -------------------- function create_developer_summary() { - global $developer_name, $open_bug_count, - $resolved_bug_count, $total_bug_count; $t_project_id = helper_get_current_project(); $t_user_table = config_get( 'mantis_user_table' ); @@ -538,16 +438,21 @@ if ( !isset( $t_handler_arr[$row['handler_id']] ) ) { $t_handler_arr[$row['handler_id']]['res'] = 0; $t_handler_arr[$row['handler_id']]['open'] = 0; + $t_handler_arr[$row['handler_id']]['close'] = 0; } if ( $row['status'] >= $t_res_val ) { - $t_handler_arr[$row['handler_id']]['res']++; + if ( $row['status'] >= $t_clo_val ) { + $t_handler_arr[$row['handler_id']]['close']++; + } else { + $t_handler_arr[$row['handler_id']]['res']++; + } } else { $t_handler_arr[$row['handler_id']]['open']++; } } if ( count( $t_handler_arr ) == 0 ) { - return; + return array( 'open' => array() ); } $t_imploded_handlers = implode( ',', array_keys( $t_handler_arr ) ); @@ -562,64 +467,11 @@ $row = db_fetch_array( $result ); extract( $row, EXTR_PREFIX_ALL, 'v' ); - $open_buff = $t_handler_arr[$v_id]['open']; - $resolved_buff = $t_handler_arr[$v_id]['res']; - - if (($resolved_buff+$open_buff)>0) { - $open_bug_count[]=$open_buff; - $resolved_bug_count[]=$resolved_buff; - $total_bug_count[]=$resolved_buff+$open_buff; - $developer_name[]=$v_username; - } + $t_metrics['open'][$v_username] = $t_handler_arr[$v_id]['open']; + $t_metrics['resolved'][$v_username] = $t_handler_arr[$v_id]['res']; + $t_metrics['closed'][$v_username] = $t_handler_arr[$v_id]['close']; } # end for - } - - # -------------------- - function graph_developer_summary( ){ - global $developer_name, $total_bug_count, $open_bug_count, $resolved_bug_count; - - error_check( count($developer_name), lang_get( 'by_developer' ) ); - - if ( 0 == count($developer_name) ) { - return; - } - - $graph = new Graph(300,380); - $graph->img->SetMargin(40,40,40,170); - $graph->img->SetAntiAliasing(); - $graph->SetScale('textlin'); - $graph->SetMarginColor('white'); - $graph->SetFrame(false); - $graph->title->Set( lang_get( 'by_developer' ) ); - $graph->xaxis->SetTickLabels($developer_name); - $graph->xaxis->SetLabelAngle(90); - $graph->yaxis->scale->ticks->SetDirection(-1); - - $graph->legend->Pos(0,0.8,'right','top'); - $graph->legend->SetShadow(false); - $graph->legend->SetFillColor('white'); - $graph->legend->SetLayout(LEGEND_HOR); - - $p1 = new BarPlot($open_bug_count); - $p1->SetFillColor('red'); - $p1->SetLegend( lang_get( 'legend_still_open' ) ); - - $p2 = new BarPlot($resolved_bug_count); - $p2->SetFillColor('yellow'); - $p2->SetLegend( lang_get( 'legend_resolved' ) ); - - $p3 = new BarPlot($total_bug_count); - $p3->SetFillColor('blue'); - $p3->SetLegend( lang_get( 'legend_assigned' ) ); - - $gbplot = new GroupBarPlot( array($p1, $p2, $p3)); - $graph->Add($gbplot); - if ( ON == config_get( 'show_queries_count' ) ) { - $graph->subtitle->Set( db_count_queries() . ' queries (' . db_count_unique_queries() . ' unique)' ); - } - - $graph->Stroke(); - + return $t_metrics; } # -------------------- @@ -658,7 +510,7 @@ } if ( count( $t_reporter_arr ) == 0 ) { - return; + return array(); } $t_imploded_reporters = implode( ',', array_keys( $t_reporter_arr ) ); @@ -673,43 +525,9 @@ $row = db_fetch_array( $result ); extract( $row, EXTR_PREFIX_ALL, 'v' ); - if ( $t_reporter_arr[$v_id] > 0){ - $reporter_name[] = $v_username; - $reporter_count[] = $t_reporter_arr[$v_id]; - } + $t_metrics[$v_username] = $t_reporter_arr[$v_id]; } # end for - } - - # -------------------- - function graph_reporter_summary( ){ - global $reporter_name, $reporter_count; - - error_check( count($reporter_name), lang_get( 'by_reporter' ) ); - - if ( 0 == count($reporter_name) ) { - return; - } - $graph = new Graph(300,380); - $graph->img->SetMargin(40,40,40,170); - $graph->img->SetAntiAliasing(); - $graph->SetScale('textlin'); - $graph->SetMarginColor('white'); - $graph->SetFrame(false); - $graph->title->Set( lang_get( 'by_reporter' ) ); - $graph->xaxis->SetTickLabels($reporter_name); - $graph->xaxis->SetLabelAngle(90); - $graph->yaxis->scale->ticks->SetDirection(-1); - - $p1 = new BarPlot($reporter_count); - $p1->SetFillColor('yellow'); - $p1->SetWidth(0.8); - $graph->Add($p1); - - if ( ON == config_get( 'show_queries_count' ) ) { - $graph->subtitle->Set( db_count_queries() . ' queries (' . db_count_unique_queries() . ' unique)' ); - } - $graph->Stroke(); - + return $t_metrics; } # -------------------- @@ -735,48 +553,21 @@ ORDER BY category"; $result = db_query( $query ); $category_count = db_num_rows( $result ); + if ( 0 == $category_count ) { + return array(); + } for ($i=0;$i<$category_count;$i++) { $row = db_fetch_array( $result ); - $category_name[] = $row['category']; - $c_category_name = addslashes($category_name[$i]); - + $t_cat_name = $row['category']; + $c_category_name = addslashes($t_cat_name); $query = "SELECT COUNT(*) FROM $t_bug_table WHERE category='$c_category_name' AND $specific_where"; $result2 = db_query( $query ); - $category_bug_count[] = db_result( $result2, 0, 0 ); - + $t_metrics[$t_cat_name] = db_result( $result2, 0, 0 ); } # end for - } - - # -------------------- - function graph_category_summary(){ - global $category_name, $category_bug_count; - - error_check( $category_bug_count, lang_get( 'by_category' ) ); - - $graph = new Graph(300,380); - $graph->img->SetMargin(40,40,40,170); - $graph->img->SetAntiAliasing(); - $graph->SetScale('textlin'); - $graph->SetMarginColor('white'); - $graph->SetFrame(false); - $graph->title->Set( lang_get( 'by_category' ) ); - $graph->xaxis->SetTickLabels($category_name); - $graph->xaxis->SetLabelAngle(90); - $graph->yaxis->scale->ticks->SetDirection(-1); - - - $p1 = new BarPlot($category_bug_count); - $p1->SetFillColor('yellow'); - $p1->SetWidth(0.8); - $graph->Add($p1); - - if ( ON == config_get( 'show_queries_count' ) ) { - $graph->subtitle->Set( db_count_queries() . ' queries (' . db_count_unique_queries() . ' unique)' ); - } - $graph->Stroke(); + return $t_metrics; } # -------------------- @@ -802,7 +593,6 @@ # -------------------- function create_cumulative_bydate(){ - global $metrics; $t_clo_val = CLOSED; $t_res_val = config_get( 'bug_resolved_status_threshold' ); @@ -890,72 +680,18 @@ $t_last_opened = 0; $t_last_resolved = 0; foreach ($metrics as $i=>$vals) { - $metrics[$i][0] = $metrics[$i][0] + $t_last_opened; - $metrics[$i][1] = $metrics[$i][1] + $t_last_resolved; - $metrics[$i][2] = $metrics[$i][0] - $metrics[$i][1]; - $t_last_opened = $metrics[$i][0]; - $t_last_resolved = $metrics[$i][1]; + $t_date = $i * 86400; + $t_metrics[$t_date][0] = $t_last_opened = $metrics[$i][0] + $t_last_opened; + $t_metrics[$t_date][1] = $t_last_resolved = $metrics[$i][1] + $t_last_resolved; + $t_metrics[$t_date][2] = $t_metrics[$t_date][0] - $t_metrics[$t_date][1]; } + return $t_metrics; } function graph_date_format ($p_date) { return date( config_get( 'short_date_format' ), $p_date ); } - # -------------------- - function graph_cumulative_bydate(){ - global $metrics; - - error_check( count($metrics), lang_get( 'cumulative' ) . ' ' . lang_get( 'by_date' ) ); - - foreach ($metrics as $i=>$vals) { - if ( $i > 0 ) { - $plot_date[] = $i * 86400; - $reported_plot[] = $metrics[$i][0]; - $resolved_plot[] = $metrics[$i][1]; - $still_open_plot[] = $metrics[$i][2]; - } - } - - $graph = new Graph(300,380); - $graph->img->SetMargin(40,40,40,170); - $graph->img->SetAntiAliasing(); - $graph->SetScale('linlin'); - $graph->SetMarginColor('white'); - $graph->SetFrame(false); - $graph->title->Set( lang_get( 'cumulative' ) . ' ' . lang_get( 'by_date' ) ); - $graph->legend->Pos(0,0.8,'right','bottom'); - $graph->legend->SetShadow(false); - $graph->legend->SetFillColor('white'); - $graph->legend->SetLayout(LEGEND_HOR); - $graph->yaxis->scale->ticks->SetDirection(-1); -# $graph->xaxis->Hide(); - $graph->xaxis->SetLabelAngle(90); - $graph->xaxis->SetLabelFormatCallback('graph_date_format'); - - $p1 = new LinePlot($reported_plot, $plot_date); - $p1->SetColor('blue'); - $p1->SetCenter(); - $p1->SetLegend( lang_get( 'legend_reported' ) ); - $graph->Add($p1); - - $p3 = new LinePlot($still_open_plot, $plot_date); - $p3->SetColor('red'); - $p3->SetCenter(); - $p3->SetLegend( lang_get( 'legend_still_open' ) ); - $graph->Add($p3); - - $p2 = new LinePlot($resolved_plot, $plot_date); - $p2->SetColor('black'); - $p2->SetCenter(); - $p2->SetLegend( lang_get( 'legend_resolved' ) ); - $graph->Add($p2); - - if ( ON == config_get( 'show_queries_count' ) ) { - $graph->subtitle->Set( db_count_queries() . ' queries (' . db_count_unique_queries() . ' unique) (' . db_time_queries() . 'sec)'); - } - $graph->Stroke(); - } # ---------------------------------------------------- # Index: constant_inc.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/constant_inc.php,v retrieving revision 1.34 retrieving revision 1.35 diff -u -d -r1.34 -r1.35 --- constant_inc.php 11 Dec 2004 20:20:12 -0000 1.34 +++ constant_inc.php 16 Dec 2004 22:41:27 -0000 1.35 @@ -306,5 +306,6 @@ # token types define( 'TOKEN_UNKNOWN', 0 ); define( 'TOKEN_FILTER', 1 ); + define( 'TOKEN_GRAPH', 2 ); ?> Index: tokens_api.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/tokens_api.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- tokens_api.php 12 Dec 2004 00:30:44 -0000 1.2 +++ tokens_api.php 16 Dec 2004 22:41:27 -0000 1.3 @@ -1,127 +1,173 @@ -<?php - # Mantis - a php based bugtracking system - # Copyright (C) 2000 - 2002 Kenzaburo Ito - ke...@30... - # Copyright (C) 2002 - 2004 Mantis Team - man...@li... - # This program is distributed under the terms and conditions of the GPL - # See the README and LICENSE files for details - - # -------------------------------------------------------- - # $Id$ - # -------------------------------------------------------- - - ### TOKENS API ### +<?php + # Mantis - a php based bugtracking system + # Copyright (C) 2000 - 2002 Kenzaburo Ito - ke...@30... + # Copyright (C) 2002 - 2004 Mantis Team - man...@li... + # This program is distributed under the terms and conditions of the GPL + # See the README and LICENSE files for details + + # -------------------------------------------------------- + # $Id$ + # -------------------------------------------------------- + + ### TOKENS API ### + + # This implements temporary storage of strings. + # DB schema: id, type, owner, timestamp, value + + # TODO + # 1. add constant for user token types TOKEN_USER. users can define token_my_type = token_user, token_other = token_user + 1 etc + # TOKEN_USER = 1000 + # 2. Implement Token_touch + # 3. Test token_ensure_owner + # 4. Add index on type + owner to DB + # 5. remove 'timestamp' from dbschema? + # 6. Replace generic errors + # 7. add an 'expiry' param to token_add + # 8. rework ts_purge_expired not to be called on every get. Maybe call it if token is found to be expired. + # 9. return 'default param' from token_add is token not found - # This implements temporary storage of strings. - # DB schema: id, type, owner, timestamp, value - - # TODO - # 1. add constant for user token types TOKEN_USER. users can define token_my_type = token_user, token_other = token_user + 1 etc - # TOKEN_USER = 1000 - # 2. Implement Token_touch - # 3. Test token_ensure_owner - # 4. Add index on type + owner to DB - # 5. remove 'timestamp' from dbschema? - # 6. Replace generic errors - # 7. add an 'expiry' param to token_add - # 8. rework ts_purge_expired not to be called on every get. Maybe call it if token is found to be expired. - # 9. return 'default param' from token_add is token not found - # -------------------- - function token_ensure_owner( $p_token_id, $p_owner_id ) { - $c_token_id = db_prepare_int( $p_token_id ); - $t_tokens_table = config_get( 'mantis_tokens_table' ); - - $query = "SELECT owner - FROM $t_tokens_table - WHERE id='$c_token_id'"; - $result = db_query( $query ); - - if( db_result( $result ) != $p_owner_id ) { - trigger_error( ERROR_GENERIC, ERROR ); - } - - return true; - } - + function token_ensure_owner( $p_token_id, $p_owner_id ) { + $c_token_id = db_prepare_int( $p_token_id ); + $t_tokens_table = config_get( 'mantis_tokens_table' ); + + $query = "SELECT owner + FROM $t_tokens_table + WHERE id='$c_token_id'"; + $result = db_query( $query ); + + if( db_result( $result ) != $p_owner_id ) { + trigger_error( ERROR_GENERIC, ERROR ); + } + + return true; + } + # -------------------- - function token_touch( $p_token_id, $p_expiry_delay ) { - } - + function token_touch( $p_token_id, $p_expiry_delay ) { + } + # -------------------- - function token_delete_by_owner( $p_owner_owner ) { - $c_token_owner = db_prepare_int( $p_token_owner ); - - $t_tokens_table = config_get( 'mantis_tokens_table' ); - - # Remove - $query = "DELETE FROM $t_tokens_table - WHERE owner='$c_token_owner'"; - db_query( $query ); - - return true; - } - + function token_delete_by_owner( $p_owner_owner ) { + $c_token_owner = db_prepare_int( $p_token_owner ); + + $t_tokens_table = config_get( 'mantis_tokens_table' ); + + # Remove + $query = "DELETE FROM $t_tokens_table + WHERE owner='$c_token_owner'"; + db_query( $query ); + + return true; + } + # -------------------- - function token_delete_by_type( $p_token_type ) { - $c_token_type = db_prepare_int( $p_token_type ); - - $t_tokens_table = config_get( 'mantis_tokens_table' ); - - # Remove - $query = "DELETE FROM $t_tokens_table - WHERE type='$c_token_type'"; - db_query( $query ); - - return true; - } - + function token_delete_by_type( $p_token_type ) { + $c_token_type = db_prepare_int( $p_token_type ); + + $t_tokens_table = config_get( 'mantis_tokens_table' ); + + # Remove + $query = "DELETE FROM $t_tokens_table + WHERE type='$c_token_type'"; + db_query( $query ); + + return true; + } + # -------------------- - function token_exists( $p_token_id ) { - $c_token_id = db_prepare_int( $p_token_id ); - $t_tokens_table = config_get( 'mantis_tokens_table' ); - - $query = "SELECT id - FROM $t_tokens_table - WHERE id='$c_token_id'"; - $result = db_query( $query, 1 ); - - return( 1 == db_result( $result ) ); - } - + function token_delete_by_type_owner( $p_token_type, $p_token_owner ) { + $c_token_type = db_prepare_int( $p_token_type ); + $c_token_owner = db_prepare_int( $p_token_owner ); + + $t_tokens_table = config_get( 'mantis_tokens_table' ); + + # Remove + $query = "DELETE FROM $t_tokens_table + WHERE type='$c_token_type' and owner='$c_token_owner'"; + db_query( $query ); + + return true; + } + # -------------------- - function token_ensure_exists( $p_token_id ) { - if ( !token_exists( $p_token_id ) ) { - trigger_error( ERROR_GENERIC, ERROR ); - } - - return true; - } - + function token_exists( $p_token_id ) { + $c_token_id = db_prepare_int( $p_token_id ); + $t_tokens_table = config_get( 'mantis_tokens_table' ); + + $query = "SELECT id + FROM $t_tokens_table + WHERE id='$c_token_id'"; + $result = db_query( $query, 1 ); + + return( 1 == db_result( $result ) ); + } + # -------------------- - function token_add( $p_token_value, $p_token_type = TOKEN_UNKNOWN, $p_token_owner = null ) { - $c_token_type = db_prepare_int( $p_token_type ); - $c_token_value = db_prepare_string ( $p_token_value ); + function token_ensure_exists( $p_token_id ) { + if ( !token_exists( $p_token_id ) ) { + trigger_error( ERROR_GENERIC, ERROR ); + } + + return true; + } - if( $p_token_owner == null ) { $c_token_owner = auth_get_current_user_id(); } else { $c_token_owner = db_prepare_int( $p_token_owner ); } - $t_tokens_table = config_get( 'mantis_tokens_table' ); - # insert $query = "INSERT INTO $t_tokens_table ( type, owner, timestamp, value ) VALUES ( $c_token_type, $c_token_owner, " . db_now(). ",'$c_token_value' )"; - db_query( $query ); - return db_insert_id( $t_tokens_table ); } # -------------------- - # This method does not generate an error if the token does not exist, # e.g. if we try to delete an expired token function token_delete( $p_token_id ) { $c_token_id = db_prepare_int( $p_token_id ); $t_tokens_table = config_get( 'mantis_tokens_table' ); - # Remove $query = "DELETE FROM $t_tokens_table WHERE id='$c_token_id'"; db_query( $query, 1 ); - return true; } + function token_add( $p_token_value, $p_token_type = TOKEN_UNKNOWN, $p_token_owner = null ) { + $c_token_type = db_prepare_int( $p_token_type ); + $c_token_value = db_prepare_string ( $p_token_value ); + + if( $p_token_owner == null ) { + $c_token_owner = auth_get_current_user_id(); + } else { + $c_token_owner = db_prepare_int( $p_token_owner ); + } + $t_tokens_table = config_get( 'mantis_tokens_table' ); + # insert + $query = "INSERT INTO $t_tokens_table + ( type, owner, timestamp, value ) + VALUES + ( $c_token_type, $c_token_owner, " . db_now(). ",'$c_token_value' )"; + db_query( $query ); + return db_insert_id( $t_tokens_table ); + } # -------------------- - function token_get_value( $p_token_id ) { $c_token_id = db_prepare_int( $p_token_id ); $c_token_owner = auth_get_current_user_id(); - $t_tokens_table = config_get( 'mantis_tokens_table' ); - token_purge_expired(); - token_ensure_owner( $c_token_id, $c_token_owner ) ; - $query = "SELECT value FROM $t_tokens_table WHERE id='$c_token_id'"; - $result = db_query( $query ); - return db_result( $result ); } + # This method does not generate an error if the token does not exist, + # e.g. if we try to delete an expired token + function token_delete( $p_token_id ) { + $c_token_id = db_prepare_int( $p_token_id ); + + $t_tokens_table = config_get( 'mantis_tokens_table' ); + # Remove + $query = "DELETE FROM $t_tokens_table + WHERE id='$c_token_id'"; + db_query( $query, 1 ); + return true; + } # -------------------- - function token_purge_expired( $p_token_type = NULL ) { $t_tokens_table = config_get( 'mantis_tokens_table' ); - # Remove $query = "DELETE FROM $t_tokens_table WHERE "; if ( !is_null( $p_token_type ) ) { $c_token_type = db_prepare_int( $p_token_type ); $query .= " type='$c_token_type' AND "; } - $query .= db_helper_compare_days( db_now(), 'timestamp', ">= '1'" ); - db_query( $query ); - return true; } ?> \ No newline at end of file + function token_get_value( $p_token_id ) { + $c_token_id = db_prepare_int( $p_token_id ); + $c_token_owner = auth_get_current_user_id(); + $t_tokens_table = config_get( 'mantis_tokens_table' ); + token_purge_expired(); + token_ensure_owner( $c_token_id, $c_token_owner ) ; + $query = "SELECT value + FROM $t_tokens_table + WHERE id='$c_token_id'"; + $result = db_query( $query ); + return db_result( $result ); + } + # -------------------- + function token_purge_expired( $p_token_type = NULL ) { + $t_tokens_table = config_get( 'mantis_tokens_table' ); + # Remove + $query = "DELETE FROM $t_tokens_table WHERE "; + if ( !is_null( $p_token_type ) ) { + $c_token_type = db_prepare_int( $p_token_type ); + $query .= " type='$c_token_type' AND "; + } + $query .= db_helper_compare_days( db_now(), 'timestamp', ">= '1'" ); + db_query( $query ); + return true; + } +?> \ No newline at end of file |