| [ 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_once( 'Period.php' ); 29 require_once( 'graph_api.php' ); 30 31 access_ensure_project_level( config_get( 'view_summary_threshold' ) ); 32 33 $f_width = gpc_get_int( 'width', 600 ); 34 $t_ar = plugin_config_get( 'bar_aspect' ); 35 $t_interval = new Period(); 36 $t_interval->set_period_from_selector( 'interval' ); 37 $f_show_as_table = gpc_get_bool( 'show_table', FALSE ); 38 $f_summary = gpc_get_bool( 'summary', FALSE ); 39 40 $t_interval_days = $t_interval->get_elapsed_days(); 41 if ( $t_interval_days <= 14 ) { 42 $t_incr = 60 * 60; // less than 14 days, use hourly 43 } else if ( $t_interval_days <= 92 ) { 44 $t_incr = 24 * 60 * 60; // less than three month, use daily 45 } else { 46 $t_incr = 7 * 24 * 60 * 60; // otherwise weekly 47 } 48 49 $f_page_number = 1; 50 51 $t_per_page = 0; 52 $t_bug_count = null; 53 $t_page_count = 0; 54 55 $t_filter = current_user_get_bug_filter(); 56 $t_filter['_view_type'] = 'advanced'; 57 $t_filter[FILTER_PROPERTY_STATUS] = array(META_FILTER_ANY); 58 $t_filter[FILTER_PROPERTY_SORT_FIELD_NAME] = ''; 59 $rows = filter_get_bug_rows( $f_page_number, $t_per_page, $t_page_count, $t_bug_count, $t_filter, null, null, true ); 60 if ( count($rows) == 0 ) { 61 // no data to graph 62 exit(); 63 } 64 65 $t_bug_table = db_get_table( 'bug' ); 66 $t_bug_hist_table = db_get_table( 'bug_history' ); 67 68 $t_marker = array(); 69 $t_data = array(); 70 $t_ptr = 0; 71 $t_end = $t_interval->get_end_timestamp(); 72 $t_start = $t_interval->get_start_timestamp(); 73 74 $t_resolved = config_get( 'bug_resolved_status_threshold' ); 75 $t_closed = config_get( 'bug_closed_status_threshold' ); 76 77 $t_bug = array(); 78 $t_bug_cat = array(); // save categoties or bugs to look up resolved ones. 79 $t_category = array(); 80 81 // walk through all issues and grab their category for 'now' 82 $t_marker[$t_ptr] = time(); 83 $t_data[$t_ptr] = array(); 84 foreach ($rows as $t_row) { 85 // the following function can treat the resolved parameter as an array to match 86 $t_cat = category_get_name( $t_row->category_id ); 87 if ($t_cat == '') 88 $t_cat = 'none'; 89 if ( !access_compare_level( $t_row->status, $t_resolved ) ) { 90 if (in_array($t_cat, $t_category)) { 91 $t_data[$t_ptr][$t_cat] ++; 92 } else { 93 $t_data[$t_ptr][$t_cat] = 1; 94 $t_category[] = $t_cat; 95 } 96 } 97 $t_bug[] = $t_row->id; 98 $t_bug_cat[$t_row->id] = $t_cat; 99 } 100 101 // get the history for these bugs over the interval required to offset the data 102 // type = 0 and field=status are status changes 103 // type = 1 are new bugs 104 $t_select = 'SELECT bug_id, type, field_name, old_value, new_value, date_modified FROM '.$t_bug_hist_table. 105 ' WHERE bug_id in ('.implode(',', $t_bug).') and '. 106 '( (type='.NORMAL_TYPE.' and field_name=\'category\') or '. 107 '(type='.NORMAL_TYPE.' and field_name=\'status\') or type='.NEW_BUG.' ) and '. 108 'date_modified >= \''. $t_start .'\''. 109 ' order by date_modified DESC'; 110 $t_result = db_query( $t_select ); 111 $row = db_fetch_array( $t_result ); 112 113 for ($t_now = time() - $t_incr; $t_now >= $t_start; $t_now -= $t_incr) { 114 // walk through the data points and use the data retrieved to update counts 115 while( ( $row !== false ) && ( $row['date_modified'] >= $t_now ) ) { 116 switch ($row['type']) { 117 case 0: // updated bug 118 if ($row['field_name'] == 'category') { 119 $t_cat = $row['new_value']; 120 if ($t_cat == '') 121 $t_cat = 'none'; 122 if (in_array($t_cat, $t_category)) { 123 $t_data[$t_ptr][$t_cat] --; 124 } else { 125 $t_data[$t_ptr][$t_cat] = 0; 126 $t_category[] = $t_cat; 127 } 128 $t_cat = $row['old_value']; 129 if ($t_cat == '') 130 $t_cat = 'none'; 131 if (in_array($t_cat, $t_category)) { 132 $t_data[$t_ptr][$t_cat] ++; 133 } else { 134 $t_data[$t_ptr][$t_cat] = 1; 135 $t_category[] = $t_cat; 136 } 137 // change the category associated with the bug to match in case the bug was 138 // created during the scan 139 $t_bug_cat[$row['bug_id']] = $t_cat; 140 } else { // change of status access_compare_level( $t_row['status'], $t_resolved ) 141 if ( access_compare_level( $row['new_value'], $t_resolved ) && 142 !access_compare_level( $row['old_value'], $t_resolved ) ) { 143 // transition from open to closed 144 $t_cat = $t_bug_cat[$row['bug_id']]; 145 if ($t_cat == '') 146 $t_cat = 'none'; 147 if (in_array($t_cat, $t_category)) { 148 $t_data[$t_ptr][$t_cat] ++; 149 } else { 150 $t_data[$t_ptr][$t_cat] = 1; 151 $t_category[] = $t_cat; 152 } 153 } 154 } 155 break; 156 case 1: // new bug 157 $t_cat = $t_bug_cat[$row['bug_id']]; 158 if ($t_cat == '') 159 $t_cat = 'none'; 160 if (in_array($t_cat, $t_category)) { 161 $t_data[$t_ptr][$t_cat] --; 162 } else { 163 $t_data[$t_ptr][$t_cat] = 0; 164 $t_category[] = $t_cat; 165 } 166 break; 167 } 168 $row = db_fetch_array( $t_result ); 169 } 170 171 if ($t_now <= $t_end) { 172 $t_marker[$t_ptr] = $t_now; 173 $t_ptr++; 174 foreach ( $t_category as $t_cat ) { 175 $t_data[$t_ptr][$t_cat] = $t_data[$t_ptr-1][$t_cat]; 176 } 177 } 178 } 179 $t_bin_count = $t_ptr; 180 // drop any categories that have no counts 181 // These arise when bugs are opened and closed within the data intervals 182 $t_count_cat = count( $t_category ); 183 for ( $t=0; $t<$t_count_cat; $t++ ) { 184 $t_cat = $t_category[ $t ]; 185 $t_not_zero = false; 186 for ($t_ptr=0; $t_ptr<$t_bin_count; $t_ptr++) { 187 if ( isset( $t_data[$t_ptr][$t_cat] ) && ( $t_data[$t_ptr][$t_cat] > 0 ) ) { 188 $t_not_zero = true; 189 break; 190 } 191 } 192 if ( !$t_not_zero ) { 193 unset( $t_category[ $t ] ); 194 } 195 } 196 // sort and display the results 197 sort($t_category); 198 if ($f_show_as_table) { 199 $t_date_format = config_get( 'short_date_format' ); 200 html_begin(); 201 html_head_begin(); 202 html_css(); 203 html_content_type(); 204 html_title( lang_get( 'by_category' ) ); 205 html_head_end(); 206 html_body_begin(); 207 echo '<table class="width100"><tr><td></td>'; 208 foreach ( $t_category as $t_cat ) { 209 echo '<th>'.$t_cat.'</th>'; 210 } 211 echo '</tr>'; 212 for ($t_ptr=0; $t_ptr<$t_bin_count; $t_ptr++) { 213 echo '<tr class="row-'.($t_ptr%2+1).'"><td>'.$t_ptr.' ('. date( $t_date_format, $t_marker[$t_ptr] ) .')'.'</td>'; 214 foreach ( $t_category as $t_cat ) { 215 echo '<td>'.(isset($t_data[$t_ptr][$t_cat]) ? $t_data[$t_ptr][$t_cat] : 0).'</td>'; 216 } 217 echo '</tr>'; 218 } 219 echo '</table>'; 220 html_body_end(); 221 html_end(); 222 } else { 223 // reverse the array and reorder the data, if necessary 224 $t_metrics = array(); 225 for ($t_ptr=0; $t_ptr<$t_bin_count; $t_ptr++) { 226 $t = $t_bin_count - $t_ptr - 1; 227 $t_metrics[0][$t_ptr] = $t_marker[$t]; 228 $i = 0; 229 foreach ( $t_category as $t_cat ) { 230 $t_metrics[++$i][$t_ptr] = isset($t_data[$t][$t_cat]) ? $t_data[$t][$t_cat] : 0; 231 } 232 } 233 array_unshift( $t_category, '' ); // add placeholder 234 graph_bydate( $t_metrics, $t_category, lang_get( 'by_category' ), $f_width, $f_width * $t_ar ); 235 }
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 |