| [ 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_bycategory.php,v 1.2.2.1 2007-10-13 22:32:40 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 month, 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 $t_resolved = config_get( 'bug_resolved_status_threshold' ); 76 $t_closed = CLOSED; 77 78 $t_bug = array(); 79 $t_bug_cat = array(); // save categoties or bugs to look up resolved ones. 80 $t_category = array(); 81 82 // walk through all issues and grab their category for 'now' 83 $t_marker[$t_ptr] = time(); 84 $t_data[$t_ptr] = array(); 85 foreach ($rows as $t_row) { 86 // the following function can treat the resolved parameter as an array to match 87 $t_cat = $t_row['category']; 88 if ($t_cat == '') 89 $t_cat = 'none'; 90 if ( !access_compare_level( $t_row['status'], $t_resolved ) ) { 91 if (in_array($t_cat, $t_category)) { 92 $t_data[$t_ptr][$t_cat] ++; 93 } else { 94 $t_data[$t_ptr][$t_cat] = 1; 95 $t_category[] = $t_cat; 96 } 97 } 98 $t_bug[] = $t_row['id']; 99 $t_bug_cat[$t_row['id']] = $t_cat; 100 } 101 102 // get the history for these bugs over the interval required to offset the data 103 // type = 0 and field=status are status changes 104 // type = 1 are new bugs 105 $t_select = 'SELECT bug_id, type, field_name, old_value, new_value, date_modified FROM '.$t_bug_hist_table. 106 ' WHERE bug_id in ('.implode(',', $t_bug).') and '. 107 '( (type='.NORMAL_TYPE.' and field_name=\'category\') or '. 108 '(type='.NORMAL_TYPE.' and field_name=\'status\') or type='.NEW_BUG.' ) and '. 109 'date_modified >= \''.db_date( $t_start ).'\''. 110 ' order by date_modified DESC'; 111 $t_result = db_query( $t_select ); 112 $row = db_fetch_array( $t_result ); 113 114 for ($t_now = time() - $t_incr; $t_now >= $t_start; $t_now -= $t_incr) { 115 // walk through the data points and use the data retrieved to update counts 116 while( ( $row !== false ) && ( db_unixtimestamp($row['date_modified']) >= $t_now ) ) { 117 switch ($row['type']) { 118 case 0: // updated bug 119 if ($row['field_name'] == 'category') { 120 $t_cat = $row['new_value']; 121 if ($t_cat == '') 122 $t_cat = 'none'; 123 if (in_array($t_cat, $t_category)) { 124 $t_data[$t_ptr][$t_cat] --; 125 } else { 126 $t_data[$t_ptr][$t_cat] = 0; 127 $t_category[] = $t_cat; 128 } 129 $t_cat = $row['old_value']; 130 if ($t_cat == '') 131 $t_cat = 'none'; 132 if (in_array($t_cat, $t_category)) { 133 $t_data[$t_ptr][$t_cat] ++; 134 } else { 135 $t_data[$t_ptr][$t_cat] = 1; 136 $t_category[] = $t_cat; 137 } 138 // change the category associated with the bug to match in case the bug was 139 // created during the scan 140 $t_bug_cat[$row['bug_id']] = $t_cat; 141 } else { // change of status access_compare_level( $t_row['status'], $t_resolved ) 142 if ( access_compare_level( $row['new_value'], $t_resolved ) && 143 !access_compare_level( $row['old_value'], $t_resolved ) ) { 144 // transition from open to closed 145 $t_cat = $t_bug_cat[$row['bug_id']]; 146 if ($t_cat == '') 147 $t_cat = 'none'; 148 if (in_array($t_cat, $t_category)) { 149 $t_data[$t_ptr][$t_cat] ++; 150 } else { 151 $t_data[$t_ptr][$t_cat] = 1; 152 $t_category[] = $t_cat; 153 } 154 } 155 } 156 break; 157 case 1: // new bug 158 $t_cat = $t_bug_cat[$row['bug_id']]; 159 if ($t_cat == '') 160 $t_cat = 'none'; 161 if (in_array($t_cat, $t_category)) { 162 $t_data[$t_ptr][$t_cat] --; 163 } else { 164 $t_data[$t_ptr][$t_cat] = 0; 165 $t_category[] = $t_cat; 166 } 167 break; 168 } 169 $row = db_fetch_array( $t_result ); 170 } 171 172 if ($t_now <= $t_end) { 173 $t_marker[$t_ptr] = $t_now; 174 $t_ptr++; 175 foreach ( $t_category as $t_cat ) { 176 $t_data[$t_ptr][$t_cat] = $t_data[$t_ptr-1][$t_cat]; 177 } 178 } 179 } 180 $t_bin_count = $t_ptr; 181 // drop any categories that have no counts 182 // These arise when bugs are opened and closed within the data intervals 183 $t_count_cat = count( $t_category ); 184 for ( $t=0; $t<$t_count_cat; $t++ ) { 185 $t_cat = $t_category[ $t ]; 186 $t_not_zero = false; 187 for ($t_ptr=0; $t_ptr<$t_bin_count; $t_ptr++) { 188 if ( isset( $t_data[$t_ptr][$t_cat] ) && ( $t_data[$t_ptr][$t_cat] > 0 ) ) { 189 $t_not_zero = true; 190 break; 191 } 192 } 193 if ( !$t_not_zero ) { 194 unset( $t_category[ $t ] ); 195 } 196 } 197 // sort and display the results 198 sort($t_category); 199 if ($f_show_as_table) { 200 echo '<html><body><table class="width100"><tr><td></td>'; 201 foreach ( $t_category as $t_cat ) { 202 echo '<th>'.$t_cat.'</th>'; 203 } 204 echo '</tr>'; 205 for ($t_ptr=0; $t_ptr<$t_bin_count; $t_ptr++) { 206 echo '<tr class="row-'.($t_ptr%2+1).'"><td>'.$t_ptr.' ('.db_date( $t_marker[$t_ptr] ).')'.'</td>'; 207 foreach ( $t_category as $t_cat ) { 208 echo '<td>'.(isset($t_data[$t_ptr][$t_cat]) ? $t_data[$t_ptr][$t_cat] : 0).'</td>'; 209 } 210 echo '</tr>'; 211 } 212 echo '</table></body></html>'; 213 } else { 214 // reverse the array and reorder the data, if necessary 215 $t_metrics = array(); 216 for ($t_ptr=0; $t_ptr<$t_bin_count; $t_ptr++) { 217 $t = $t_bin_count - $t_ptr - 1; 218 $t_metrics[0][$t_ptr] = $t_marker[$t]; 219 $i = 0; 220 foreach ( $t_category as $t_cat ) { 221 $t_metrics[++$i][$t_ptr] = isset($t_data[$t][$t_cat]) ? $t_data[$t][$t_cat] : 0; 222 } 223 } 224 array_unshift( $t_category, '' ); // add placeholder 225 graph_bydate( $t_metrics, $t_category, lang_get( 'by_category' ), $f_width, $f_width * $t_ar ); 226 } 227 ?>
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 |
|