| [ 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 * @package MantisBT 19 * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org 20 * @copyright Copyright (C) 2002 - 2011 MantisBT Team - mantisbt-dev@lists.sourceforge.net 21 * @link http://www.mantisbt.org 22 */ 23 /** 24 * MantisBT Core API's 25 */ 26 require_once ( 'core.php' ); 27 28 require 'library/ezc/Base/src/base.php'; 29 30 require_once( 'graph_api.php' ); 31 32 access_ensure_project_level( config_get( 'view_summary_threshold' ) ); 33 34 $f_width = gpc_get_int( 'width', 300 ); 35 $t_ar = plugin_config_get( 'bar_aspect' ); 36 37 error_check(0,'foo'); 38 39 $t_metrics = create_cumulative_bydate2(); 40 41 graph_cumulative_bydate2( $t_metrics, $f_width, $f_width * $t_ar ); 42 43 44 function graph_cumulative_bydate2( $p_metrics, $p_graph_width = 300, $p_graph_height = 380 ) { 45 46 $t_graph_font = 'c:\\windows\\fonts\\arial.ttf' ;//graph_get_font(); 47 48 error_check( is_array( $p_metrics ) ? count( $p_metrics ) : 0, plugin_lang_get( 'cumulative' ) . ' ' . lang_get( 'by_date' ) ); 49 50 $graph = new ezcGraphLineChart(); 51 52 $graph->xAxis = new ezcGraphChartElementNumericAxis(); 53 54 55 $graph->data[0] = new ezcGraphArrayDataSet( $p_metrics[0] ); 56 $graph->data[0]->label = plugin_lang_get( 'legend_reported' ); 57 $graph->data[0]->color = '#FF0000'; 58 59 $graph->data[1] = new ezcGraphArrayDataSet( $p_metrics[1] ); 60 $graph->data[1]->label = plugin_lang_get( 'legend_resolved' ); 61 $graph->data[1]->color = '#0000FF'; 62 63 $graph->data[2] = new ezcGraphArrayDataSet( $p_metrics[2] ); 64 $graph->data[2]->label = plugin_lang_get( 'legend_still_open' ); 65 $graph->data[2]->color = '#000000'; 66 67 $graph->additionalAxis[2] = $nAxis = new ezcGraphChartElementNumericAxis(); 68 $nAxis->chartPosition = 1; 69 $nAxis->background = '#005500'; 70 $nAxis->border = '#005500'; 71 $nAxis->position = ezcGraph::BOTTOM; 72 $graph->data[2]->yAxis = $nAxis; 73 74 $graph->xAxis->labelCallback = 'graph_date_format'; 75 $graph->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedLabelRenderer(); 76 $graph->xAxis->axisLabelRenderer->angle = -45; 77 //$graph->xAxis->axisSpace = .8; 78 79 $graph->legend->position = ezcGraph::BOTTOM; 80 $graph->legend->background = '#FFFFFF80'; 81 82 $graph->driver = new ezcGraphGdDriver(); 83 //$graph->driver->options->supersampling = 1; 84 $graph->driver->options->jpegQuality = 100; 85 $graph->driver->options->imageFormat = IMG_JPEG; 86 87 // $graph->img->SetMargin( 40, 40, 40, 170 ); 88 // if( ON == config_get_global( 'jpgraph_antialias' ) ) { 89 // $graph->img->SetAntiAliasing(); 90 // } 91 // $graph->SetScale( 'linlin'); 92 // $graph->yaxis->SetColor("red"); 93 // $graph->SetY2Scale("lin"); 94 // $graph->SetMarginColor( 'white' ); 95 // $graph->SetFrame( false ); 96 97 $graph->title = plugin_lang_get( 'cumulative' ) . ' ' . lang_get( 'by_date' ); 98 $graph->options->font = $t_graph_font ; 99 100 // $graph->title->SetFont( $t_graph_font, FS_BOLD ); 101 102 /* $graph->legend->Pos( 0.05, 0.9, 'right', 'bottom' ); 103 $graph->legend->SetShadow( false ); 104 $graph->legend->SetFillColor( 'white' ); 105 $graph->legend->SetLayout( LEGEND_HOR ); 106 $graph->legend->SetFont( $t_graph_font ); 107 108 $graph->yaxis->scale->ticks->SetDirection( -1 ); 109 $graph->yaxis->SetFont( $t_graph_font ); 110 $graph->y2axis->SetFont( $t_graph_font ); 111 112 if( FF_FONT2 <= $t_graph_font ) { 113 $graph->xaxis->SetLabelAngle( 60 ); 114 } else { 115 $graph->xaxis->SetLabelAngle( 90 ); 116 117 # can't rotate non truetype fonts 118 } 119 $graph->xaxis->SetLabelFormatCallback( 'graph_date_format' ); 120 $graph->xaxis->SetFont( $t_graph_font ); 121 122 $p1 = new LinePlot( $reported_plot, $plot_date ); 123 $p1->SetColor( 'blue' ); 124 $p1->SetCenter(); 125 $graph->AddY2( $p1 ); 126 127 $p3 = new LinePlot( $still_open_plot, $plot_date ); 128 $p3->SetColor( 'red' ); 129 $p3->SetCenter(); 130 $p3->SetLegend( ); 131 $graph->Add( $p3 ); 132 133 $p2 = new LinePlot( $resolved_plot, $plot_date ); 134 $p2->SetColor( 'black' ); 135 $p2->SetCenter(); 136 $p2->SetLegend( ); 137 $graph->AddY2( $p2 ); 138 */ 139 140 /* if( helper_show_query_count() ) { 141 $graph->subtitle->Set( db_count_queries() . ' queries (' . db_time_queries() . 'sec)' ); 142 $graph->subtitle->SetFont( $t_graph_font, FS_NORMAL, 8 ); 143 }*/ 144 145 $graph->renderToOutput( $p_graph_width, $p_graph_height); 146 } 147 148 149 150 function create_cumulative_bydate2() { 151 152 $t_clo_val = CLOSED; 153 $t_res_val = config_get( 'bug_resolved_status_threshold' ); 154 $t_bug_table = db_get_table( 'bug' ); 155 $t_history_table = db_get_table( 'bug_history' ); 156 157 $t_project_id = helper_get_current_project(); 158 $t_user_id = auth_get_current_user_id(); 159 $specific_where = helper_project_specific_where( $t_project_id, $t_user_id ); 160 161 # Get all the submitted dates 162 $query = "SELECT date_submitted 163 FROM $t_bug_table 164 WHERE $specific_where 165 ORDER BY date_submitted"; 166 $result = db_query( $query ); 167 $bug_count = db_num_rows( $result ); 168 169 for( $i = 0;$i < $bug_count;$i++ ) { 170 $row = db_fetch_array( $result ); 171 172 # rationalise the timestamp to a day to reduce the amount of data 173 $t_date = $row['date_submitted']; 174 $t_date = (int)( $t_date / SECONDS_PER_DAY ); 175 176 if( isset( $metrics[$t_date] ) ) { 177 $metrics[$t_date][0]++; 178 } else { 179 $metrics[$t_date] = array( 1, 0, 0, ); 180 } 181 } 182 183 # ## Get all the dates where a transition from not resolved to resolved may have happened 184 # also, get the last updated date for the bug as this may be all the information we have 185 $query = "SELECT $t_bug_table.id, last_updated, date_modified, new_value, old_value 186 FROM $t_bug_table LEFT JOIN $t_history_table 187 ON $t_bug_table.id = $t_history_table.bug_id 188 WHERE $specific_where 189 AND $t_bug_table.status >= '$t_res_val' 190 AND ( ( $t_history_table.new_value >= '$t_res_val' 191 AND $t_history_table.field_name = 'status' ) 192 OR $t_history_table.id is NULL ) 193 ORDER BY $t_bug_table.id, date_modified ASC"; 194 $result = db_query( $query ); 195 $bug_count = db_num_rows( $result ); 196 197 $t_last_id = 0; 198 $t_last_date = 0; 199 200 for( $i = 0;$i < $bug_count;$i++ ) { 201 $row = db_fetch_array( $result ); 202 $t_id = $row['id']; 203 204 # if h_last_updated is NULL, there were no appropriate history records 205 # (i.e. pre 0.18 data), use last_updated from bug table instead 206 if( NULL == $row['date_modified'] ) { 207 $t_date = $row['last_updated']; 208 } else { 209 if( $t_res_val > $row['old_value'] ) { 210 $t_date = $row['date_modified']; 211 } 212 } 213 if( $t_id <> $t_last_id ) { 214 if( 0 <> $t_last_id ) { 215 216 # rationalise the timestamp to a day to reduce the amount of data 217 $t_date_index = (int)( $t_last_date / SECONDS_PER_DAY ); 218 219 if( isset( $metrics[$t_date_index] ) ) { 220 $metrics[$t_date_index][1]++; 221 } else { 222 $metrics[$t_date_index] = array( 223 0, 224 1, 225 0, 226 ); 227 } 228 } 229 $t_last_id = $t_id; 230 } 231 $t_last_date = $t_date; 232 } 233 234 ksort( $metrics ); 235 236 $metrics_count = count( $metrics ); 237 $t_last_opened = 0; 238 $t_last_resolved = 0; 239 foreach( $metrics as $i => $vals ) { 240 $t_date = $i * SECONDS_PER_DAY; 241 $t_metrics[0][$t_date] = $t_last_opened = $metrics[$i][0] + $t_last_opened; 242 $t_metrics[1][$t_date] = $t_last_resolved = $metrics[$i][1] + $t_last_resolved; 243 $t_metrics[2][$t_date] = $t_metrics[0][$t_date] - $t_metrics[1][$t_date]; 244 } 245 return $t_metrics; 246 }
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 |