/** * print bug counts by project * @todo check p_cache - static? * * @param array $p_projects Array of project id's. * @param integer $p_level Indicates the depth of the project within the sub-project hierarchy. * @param array $p_cache Summary cache. * @return void */ function summary_print_by_project(array $p_projects = array(), $p_level = 0, array $p_cache = null) { $t_project_id = helper_get_current_project(); if (empty($p_projects)) { if (ALL_PROJECTS == $t_project_id) { $p_projects = current_user_get_accessible_projects(); } else { $p_projects = array($t_project_id); } } # Retrieve statistics one time to improve performance. if (null === $p_cache) { $t_query = 'SELECT project_id, status, COUNT( status ) AS bugcount FROM {bug} GROUP BY project_id, status'; $t_result = db_query($t_query); $p_cache = array(); $t_resolved_val = config_get('bug_resolved_status_threshold'); $t_closed_val = config_get('bug_closed_status_threshold'); while ($t_row = db_fetch_array($t_result)) { $t_project_id = $t_row['project_id']; $t_status = $t_row['status']; $t_bugcount = $t_row['bugcount']; if ($t_closed_val <= $t_status) { if (isset($p_cache[$t_project_id]['closed'])) { $p_cache[$t_project_id]['closed'] += $t_bugcount; } else { $p_cache[$t_project_id]['closed'] = $t_bugcount; } } else { if ($t_resolved_val <= $t_status) { if (isset($p_cache[$t_project_id]['resolved'])) { $p_cache[$t_project_id]['resolved'] += $t_bugcount; } else { $p_cache[$t_project_id]['resolved'] = $t_bugcount; } } else { if (isset($p_cache[$t_project_id]['open'])) { $p_cache[$t_project_id]['open'] += $t_bugcount; } else { $p_cache[$t_project_id]['open'] = $t_bugcount; } } } } } foreach ($p_projects as $t_project) { $t_name = str_repeat('» ', $p_level) . project_get_name($t_project); $t_pdata = isset($p_cache[$t_project]) ? $p_cache[$t_project] : array('open' => 0, 'resolved' => 0, 'closed' => 0); $t_bugs_open = isset($t_pdata['open']) ? $t_pdata['open'] : 0; $t_bugs_resolved = isset($t_pdata['resolved']) ? $t_pdata['resolved'] : 0; $t_bugs_closed = isset($t_pdata['closed']) ? $t_pdata['closed'] : 0; $t_bugs_total = $t_bugs_open + $t_bugs_resolved + $t_bugs_closed; summary_helper_print_row(string_display_line($t_name), $t_bugs_open, $t_bugs_resolved, $t_bugs_closed, $t_bugs_total); if (count(project_hierarchy_get_subprojects($t_project)) > 0) { $t_subprojects = current_user_get_accessible_subprojects($t_project); if (count($t_subprojects) > 0) { summary_print_by_project($t_subprojects, $p_level + 1, $p_cache); } } } }
<td class="form-title" colspan="2"> <?php echo lang_get( 'summary_title' ) ?> </td> </tr> <tr> <td width="50%"> <?php # PROJECT # if ( 1 < count( $t_project_ids ) ) { ?> <table class="width100" cellspacing="1"> <tr> <td class="form-title" colspan="1"> <?php echo lang_get( 'by_project' ) ?> </td> <?php echo $t_orcttab ?> </tr> <?php summary_print_by_project(); ?> </table> <br /> <?php } ?> <table class="width100" cellspacing="1"> <tr> <td class="form-title" colspan="1"> <?php echo lang_get( 'by_status' ) ?> </td> <?php echo $t_orcttab ?> </tr> <?php summary_print_by_enum( 'status' ) ?> </table>
?> <!-- BY PROJECT --> <table> <thead> <tr class="row-category2"> <th><?php echo lang_get('by_project'); ?> </th> <?php echo $t_orcttab; ?> </tr> </thead> <?php summary_print_by_project(); ?> </table> <?php } ?> <!-- BY STATUS --> <table> <thead> <tr class="row-category2"> <th><?php echo lang_get('by_status'); ?> </th> <?php
function summary_print_by_project($p_projects = null, $p_level = 0, $p_cache = null) { $t_mantis_bug_table = config_get('mantis_bug_table'); $t_mantis_project_table = config_get('mantis_project_table'); $t_project_id = helper_get_current_project(); if (null == $p_projects) { if (ALL_PROJECTS == $t_project_id) { $p_projects = current_user_get_accessible_projects(); } else { $p_projects = array($t_project_id); } } # Retrieve statistics one time to improve performance. if (null === $p_cache) { $query = "SELECT project_id, status, COUNT( status ) AS count\n\t\t\t\t\tFROM {$t_mantis_bug_table}\n\t\t\t\t\tGROUP BY project_id, status"; $result = db_query($query); $p_cache = array(); $t_resolved_val = RESOLVED; $t_closed_val = CLOSED; while ($row = db_fetch_array($result)) { extract($row, EXTR_PREFIX_ALL, 'v'); if ($t_closed_val <= $v_status) { if (isset($p_cache[$v_project_id]['closed'])) { $p_cache[$v_project_id]['closed'] += $v_count; } else { $p_cache[$v_project_id]['closed'] = $v_count; } } else { if ($t_resolved_val <= $v_status) { if (isset($p_cache[$v_project_id]['resolved'])) { $p_cache[$v_project_id]['resolved'] += $v_count; } else { $p_cache[$v_project_id]['resolved'] = $v_count; } } else { if (isset($p_cache[$v_project_id]['open'])) { $p_cache[$v_project_id]['open'] += $v_count; } else { $p_cache[$v_project_id]['open'] = $v_count; } } } } } foreach ($p_projects as $t_project) { $t_name = str_repeat("» ", $p_level) . project_get_name($t_project); $t_pdata = isset($p_cache[$t_project]) ? $p_cache[$t_project] : array('open' => 0, 'resolved' => 0, 'closed' => 0); $t_bugs_open = isset($t_pdata['open']) ? $t_pdata['open'] : 0; $t_bugs_resolved = isset($t_pdata['resolved']) ? $t_pdata['resolved'] : 0; $t_bugs_closed = isset($t_pdata['closed']) ? $t_pdata['closed'] : 0; $t_bugs_total = $t_bugs_open + $t_bugs_resolved + $t_bugs_closed; summary_helper_print_row($t_name, $t_bugs_open, $t_bugs_resolved, $t_bugs_closed, $t_bugs_total); $t_subprojects = current_user_get_accessible_subprojects($t_project); if (count($t_subprojects) > 0) { summary_print_by_project($t_subprojects, $p_level + 1, $p_cache); } } }