[ 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: bug_graph_bystatus.php,v 1.2.2.1 2007-10-13 22:32:41 giallu Exp $ 22 # -------------------------------------------------------- 23 ?> 24 <?php 25 require_once ( 'core.php' ); 26 27 $t_core_path = config_get( 'core_path' ); 28 29 require_once( $t_core_path.'class.period.php' ); 30 require_once( $t_core_path.'graph_api.php' ); 31 32 access_ensure_project_level( config_get( 'view_summary_threshold' ) ); 33 34 $f_width = gpc_get_int( 'width', 600 ); 35 $t_ar = config_get( 'graph_bar_aspect' ); 36 $t_interval = new Period(); 37 $t_interval->set_period_from_selector( 'interval' ); 38 $f_show_as_table = gpc_get_bool( 'show_table', FALSE ); 39 $f_summary = gpc_get_bool( 'summary', FALSE ); 40 41 $t_interval_days = $t_interval->get_elapsed_days(); 42 if ( $t_interval_days <= 14 ) { 43 $t_incr = 60 * 60; // less than 14 days, use hourly 44 } else if ( $t_interval_days <= 92 ) { 45 $t_incr = 24 * 60 * 60; // less than three months, use daily 46 } else { 47 $t_incr = 7 * 24 * 60 * 60; // otherwise weekly 48 } 49 50 $f_page_number = 1; 51 52 $t_per_page = 0; 53 $t_bug_count = null; 54 $t_page_count = 0; 55 56 $t_filter = current_user_get_bug_filter(); 57 $t_filter['_view_type'] = 'advanced'; 58 $t_filter['show_status'] = array(META_FILTER_ANY); 59 $t_filter['sort'] = ''; 60 $rows = filter_get_bug_rows( $f_page_number, $t_per_page, $t_page_count, $t_bug_count, $t_filter, null, null, true ); 61 if ( count($rows) == 0 ) { 62 // no data to graph 63 exit(); 64 } 65 66 $t_bug_table = config_get( 'mantis_bug_table' ); 67 $t_bug_hist_table = config_get( 'mantis_bug_history_table' ); 68 69 $t_marker = array(); 70 $t_data = array(); 71 $t_ptr = 0; 72 $t_end = $t_interval->get_end_timestamp(); 73 $t_start = $t_interval->get_start_timestamp(); 74 75 // grab all status levels 76 $t_status_arr = get_enum_to_array( config_get( 'status_enum_string' ) ); 77 78 $t_bug = array(); 79 80 // walk through all issues and grab their status for 'now' 81 $t_marker[$t_ptr] = time(); 82 foreach ( $t_status_arr as $t_status => $t_label ) { 83 $t_data[$t_ptr][$t_status] = 0; 84 } 85 foreach ($rows as $t_row) { 86 $t_data[$t_ptr][$t_row['status']] ++; 87 $t_bug[] = $t_row['id']; 88 } 89 90 if ($f_show_as_table) { 91 echo '<html><body><table class="width100"><tr><td></td>'; 92 foreach ( $t_status_arr as $t_status => $t_label ) { 93 echo '<th>'.$t_label.' ('.$t_status.')</th>'; 94 } 95 echo '</tr>'; 96 } 97 98 // get the history for these bugs over the interval required to offset the data 99 // type = 0 and field=status are status changes 100 // type = 1 are new bugs 101 $t_select = 'SELECT bug_id, type, old_value, new_value, date_modified FROM '.$t_bug_hist_table. 102 ' WHERE bug_id in ('.implode(',', $t_bug). 103 ') and ( (type='.NORMAL_TYPE.' and field_name=\'status\') 104 or type='.NEW_BUG.' ) and date_modified >= \''.db_date( $t_start ).'\''. 105 ' order by date_modified DESC'; 106 $t_result = db_query( $t_select ); 107 $row = db_fetch_array( $t_result ); 108 109 for ($t_now = time() - $t_incr; $t_now >= $t_start; $t_now -= $t_incr) { 110 // walk through the data points and use the data retrieved to update counts 111 while( ( $row !== false ) && ( db_unixtimestamp($row['date_modified']) >= $t_now ) ) { 112 switch ($row['type']) { 113 case 0: // updated bug 114 $t_data[$t_ptr][$row['new_value']]--; 115 $t_data[$t_ptr][$row['old_value']]++; 116 break; 117 case 1: // new bug 118 $t_data[$t_ptr][NEW_]--; 119 break; 120 } 121 $row = db_fetch_array( $t_result ); 122 } 123 124 if ( $f_show_as_table && ($t_now <= $t_end) ) { 125 echo '<tr class="row-'.($t_ptr%2+1).'"><td>'.$t_ptr.' ('.db_date( $t_now ).')'.'</td>'; 126 foreach ( $t_status_arr as $t_status => $t_label ) { 127 echo '<td>'.$t_data[$t_ptr][$t_status].'</td>'; 128 } 129 echo '</tr>'; 130 } 131 132 if ($t_now <= $t_end) { 133 $t_ptr++; 134 $t_marker[$t_ptr] = $t_now; 135 foreach ( $t_status_arr as $t_status => $t_label ) { 136 $t_data[$t_ptr][$t_status] = $t_data[$t_ptr-1][$t_status]; 137 } 138 } 139 } 140 141 if ($f_show_as_table) { 142 echo '</table></body></html>'; 143 } else { 144 $t_resolved = config_get( 'bug_resolved_status_threshold' ); 145 $t_closed = CLOSED; 146 $t_bin_count = $t_ptr; 147 $t_labels = array(); 148 $i = 0; 149 if ($f_summary) { 150 $t_labels[++$i] = 'open'; 151 $t_labels[++$i] = 'resolved'; 152 $t_labels[++$i] = 'closed'; 153 } else { 154 foreach ( $t_status_arr as $t_status => $t_label ) { 155 $t_labels[++$i] = $t_label; 156 } 157 } 158 // reverse the array and consolidate the data, if necessary 159 $t_metrics = array(); 160 for ($t_ptr=0; $t_ptr<$t_bin_count; $t_ptr++) { 161 $t = $t_bin_count - $t_ptr; 162 $t_metrics[0][$t_ptr] = $t_marker[$t]; 163 if ($f_summary) { 164 $t_metrics[1][$t_ptr] = 0; 165 $t_metrics[2][$t_ptr] = 0; 166 $t_metrics[3][$t_ptr] = 0; 167 foreach ( $t_status_arr as $t_status => $t_label ) { 168 if ( $t_status < $t_resolved ) 169 $t_metrics[1][$t_ptr] += $t_data[$t][$t_status]; 170 else if ( $t_status < $t_closed ) 171 $t_metrics[2][$t_ptr] += $t_data[$t][$t_status]; 172 else 173 $t_metrics[3][$t_ptr] += $t_data[$t][$t_status]; 174 } 175 } else { 176 $i = 0; 177 foreach ( $t_status_arr as $t_status => $t_label ) { 178 $t_metrics[++$i][$t_ptr] = $t_data[$t][$t_status]; 179 } 180 } 181 } 182 graph_bydate( $t_metrics, $t_labels, lang_get( 'by_category' ), $f_width, $f_width * $t_ar ); 183 } 184 ?>
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 |
![]() |