[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/plugins/MantisGraph/pages/ -> bug_graph_bystatus.php (source)

   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 months, 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      if( $t_end == false || $t_start == false ) {
  75          return;
  76      }
  77      // grab all status levels
  78      $t_status_arr  = MantisEnum::getAssocArrayIndexedByValues( config_get( 'status_enum_string' ) );
  79      $t_status_labels  = MantisEnum::getAssocArrayIndexedByValues( lang_get( 'status_enum_string' ) );
  80      $t_default_bug_status = config_get( 'bug_submit_status' );
  81  
  82      $t_bug = array();
  83      $t_view_status = array();
  84  
  85      // walk through all issues and grab their status for 'now'
  86      $t_marker[$t_ptr] = time();
  87      foreach ($rows as $t_row) {
  88          if ( isset( $t_data[$t_ptr][$t_row->status] ) ) {
  89              $t_data[$t_ptr][$t_row->status] ++;
  90          } else {
  91              $t_data[$t_ptr][$t_row->status] = 1;
  92              $t_view_status[$t_row->status] =
  93                  isset($t_status_arr[$t_row->status]) ? $t_status_arr[$t_row->status] : '@'.$t_row->status.'@';
  94          }
  95          $t_bug[] = $t_row->id;
  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 >= \''. $t_start .'\''.
 105          ' order by date_modified DESC';
 106      $t_result = db_query( $t_select );
 107      $t_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( ( $t_row !== false ) && ( $t_row['date_modified'] >= $t_now ) ) {
 112              switch ($t_row['type']) {
 113                  case 0: // updated bug
 114                      if ( isset( $t_data[$t_ptr][$t_row['new_value']] ) ) {
 115                          if ( $t_data[$t_ptr][$t_row['new_value']] > 0 )
 116                              $t_data[$t_ptr][$t_row['new_value']] --;
 117                      } else {
 118                          $t_data[$t_ptr][$t_row['new_value']] = 0;
 119                          $t_view_status[$t_row['new_value']] =
 120                              isset($t_status_arr[$t_row['new_value']]) ? $t_status_arr[$t_row['new_value']] : '@'.$t_row['new_value'].'@';
 121                      }
 122                      if ( isset( $t_data[$t_ptr][$t_row['old_value']] ) ) {
 123                          $t_data[$t_ptr][$t_row['old_value']] ++;
 124                      } else {
 125                          $t_data[$t_ptr][$t_row['old_value']] = 1;
 126                          $t_view_status[$t_row['old_value']] =
 127                              isset($t_status_arr[$t_row['old_value']]) ? $t_status_arr[$t_row['old_value']] : '@'.$t_row['old_value'].'@';
 128                      }
 129                      break;
 130                  case 1: // new bug
 131                      if ( isset( $t_data[$t_ptr][$t_default_bug_status] ) ) {
 132                          if ( $t_data[$t_ptr][$t_default_bug_status] > 0 )
 133                              $t_data[$t_ptr][$t_default_bug_status] --;
 134                      } else {
 135                          $t_data[$t_ptr][$t_default_bug_status] = 0;
 136                          $t_view_status[$t_default_bug_status] =
 137                              isset( $t_status_arr[$t_default_bug_status] ) ? $t_status_arr[$t_default_bug_status] : '@' . $t_default_bug_status . '@';
 138                      }
 139                      break;
 140              }
 141              $t_row = db_fetch_array( $t_result );
 142          }
 143  
 144          if ($t_now <= $t_end) {
 145              $t_ptr++;
 146              $t_marker[$t_ptr] = $t_now;
 147              foreach ( $t_view_status as $t_status => $t_label ) {
 148                  $t_data[$t_ptr][$t_status] = $t_data[$t_ptr-1][$t_status];
 149              }
 150          }
 151      }
 152  
 153      ksort($t_view_status);
 154      /* @todo - these should probably be separate strings, but in the summary page context,
 155          the string is used as the title for all columns */
 156      $t_label_string = lang_get('orct'); //use the (open/resolved/closed/total) label
 157      $t_label_strings = explode('/', utf8_substr($t_label_string, 1, strlen($t_label_string)-2));
 158  
 159      // add headers for table
 160      if ($f_show_as_table) {
 161          $t_date_format = config_get( 'short_date_format' );
 162          html_begin();
 163          html_head_begin();
 164          html_css();
 165          html_content_type();
 166          html_title( lang_get( 'by_status' ) );
 167          html_head_end();
 168          html_body_begin();
 169          echo '<table class="width100"><tr><td></td>';
 170          if ($f_summary) {
 171              echo '<th>' . $t_label_strings[0] . '</th>';
 172              echo '<th>' . $t_label_strings[1] . '</th>';
 173              echo '<th>' . $t_label_strings[2] . '</th>';
 174          } else {
 175              foreach ( $t_view_status as $t_status => $t_label ) {
 176                  echo '<th>'.$t_label.' ('.$t_status.')</th>';
 177              }
 178          }
 179          echo '</tr>';
 180      }
 181  
 182      $t_resolved = config_get( 'bug_resolved_status_threshold' );
 183      $t_closed = config_get( 'bug_closed_status_threshold' );
 184      $t_bin_count = $t_ptr;
 185      $t_labels = array();
 186      $i = 0;
 187      if ($f_summary) {
 188  
 189          $t_labels[++$i] = $t_label_strings[0];
 190          $t_labels[++$i] = $t_label_strings[1];
 191          $t_labels[++$i] = $t_label_strings[2];
 192      } else {
 193          foreach ( $t_view_status as $t_status => $t_label ) {
 194              $t_labels[++$i] = isset($t_status_labels[$t_status]) ? $t_status_labels[$t_status] : lang_get_defaulted($t_label);
 195          }
 196      }
 197      $t_label_count = $i;
 198  
 199      // reverse the array and consolidate the data, if necessary
 200      $t_metrics = array();
 201      for ($t_ptr=0; $t_ptr<$t_bin_count; $t_ptr++) {
 202          $t = $t_bin_count - $t_ptr;
 203          $t_metrics[0][$t_ptr] = $t_marker[$t];
 204          if ($f_summary) {
 205              $t_metrics[1][$t_ptr] = 0;
 206              $t_metrics[2][$t_ptr] = 0;
 207              $t_metrics[3][$t_ptr] = 0;
 208              foreach ( $t_view_status as $t_status => $t_label ) {
 209                  if ( isset( $t_data[$t][$t_status] ) ) {
 210                      if ( $t_status < $t_resolved )
 211                          $t_metrics[1][$t_ptr] += $t_data[$t][$t_status];
 212                      else if ( $t_status < $t_closed )
 213                          $t_metrics[2][$t_ptr] += $t_data[$t][$t_status];
 214                      else
 215                          $t_metrics[3][$t_ptr] += $t_data[$t][$t_status];
 216                  }
 217              }
 218          } else {
 219              $i = 0;
 220              foreach ( $t_view_status as $t_status => $t_label ) {
 221                  if ( isset( $t_data[$t][$t_status] ) )
 222                      $t_metrics[++$i][$t_ptr] = $t_data[$t][$t_status];
 223                  else
 224                      $t_metrics[++$i][$t_ptr] = 0;
 225              }
 226          }
 227          if ( $f_show_as_table ) {
 228              echo '<tr class="row-'.($t_ptr%2+1).'"><td>'.$t_ptr.' ('. date( $t_date_format, $t_metrics[0][$t_ptr] ) .')'.'</td>';
 229              for ( $i=1; $i<=$t_label_count; $i++ ) {
 230                  echo '<td>'.$t_metrics[$i][$t_ptr].'</td>';
 231              }
 232              echo '</tr>';
 233          }
 234  
 235      }
 236      if ($f_show_as_table) {
 237          echo '</table>';
 238          html_body_end();
 239          html_end();
 240      } else {
 241          graph_bydate( $t_metrics, $t_labels, lang_get( 'by_status' ), $f_width, $f_width * $t_ar );
 242      }


Generated: Thu Jul 28 15:48:31 2011 Cross-referenced by PHPXref 0.7