| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: statistics.inc,v 1.1 2009/06/18 03:24:03 dww Exp $ 3 4 /** 5 * Page callback for the issue statistics page. 6 */ 7 function project_issue_statistics($project = NULL) { 8 $states = project_issue_state(); 9 if ($project->nid) { 10 $filter = sprintf(' AND p.pid = %d ', (int)$project->nid); 11 project_project_set_breadcrumb($project, TRUE); 12 } 13 14 $output = '<div class="project-issue">'; 15 16 // Issue lifetime. 17 $header = array(t('Category'), t('Overall'), t('Last month')); 18 $rows = array(); 19 $duration = time() - 30 * 24 * 60 * 60; 20 $result = db_query(db_rewrite_sql('SELECT p.category, SUM(n.changed - n.created) / COUNT(p.category) AS duration FROM {project_issues} p INNER JOIN {node} n ON n.nid = p.nid WHERE n.status = 1%s AND p.sid > 1 GROUP BY p.category'), $filter); 21 while ($stat = db_fetch_object($result)) { 22 $rows[$stat->category][0] = project_issue_category($stat->category); 23 $rows[$stat->category][1] = array('data' => format_interval($stat->duration, 2), 'class' => 'numeric'); 24 $rows[$stat->category][2] = array('data' => t('N/A'), 'class' => 'numeric'); 25 } 26 27 $result = db_query(db_rewrite_sql('SELECT p.category, SUM(n.changed - n.created) / COUNT(p.category) AS duration FROM {project_issues} p INNER JOIN {node} n ON n.nid = p.nid WHERE n.status = 1%s AND p.sid > 1 AND n.created > %d GROUP BY p.category'), $filter, $duration); 28 while ($stat = db_fetch_object($result)) { 29 if ($stat->duration > 0) { 30 $rows[$stat->category][2] = array('data' => format_interval($stat->duration, 2), 'class' => 'numeric'); 31 } 32 } 33 $output .= '<h2>'. t('Average lifetime') .'</h2>'; 34 $output .= theme('table', $header, $rows); 35 36 $header = array( 37 array('data' => t('Status')), 38 array('data' => t('Overall'), 'class' => 'project-issue-numeric'), 39 array('data' => '%', 'class' => 'project-issue-numeric'), 40 array('data' => t('Last month'), 'class' => 'project-issue-numeric'), 41 ); 42 $rows = array(); 43 // Activity overall. 44 $total = db_result(db_query(db_rewrite_sql('SELECT COUNT(p.nid) AS total FROM {project_issues} p INNER JOIN {node} n ON n.nid = p.nid WHERE n.status = 1%s', 'p'), $filter)); 45 $result = db_query(db_rewrite_sql('SELECT COUNT(p.nid) AS total, p.sid FROM {project_issues} p INNER JOIN {node} n ON n.nid = p.nid WHERE n.status = 1%s GROUP BY p.sid', 'p'), $filter); 46 while ($stat = db_fetch_object($result)) { 47 $rows[$stat->sid][0] = check_plain(project_issue_state($stat->sid)); 48 $rows[$stat->sid][1] = array('data' => $stat->total, 'class' => 'project-issue-numeric'); 49 $rows[$stat->sid][2] = array('data' => number_format($stat->total / $total * 100) .'%', 'class' => 'project-issue-numeric-light'); 50 $rows[$stat->sid][3] = array('data' => '0', 'class' => 'project-issue-numeric'); 51 } 52 // Activity this month. 53 $result = db_query(db_rewrite_sql('SELECT COUNT(p.nid) AS total, p.sid FROM {project_issues} p INNER JOIN {node} n ON n.nid = p.nid WHERE n.status = 1%s AND n.changed > %d GROUP BY p.sid', 'p'), $filter, $duration); 54 while ($stat = db_fetch_object($result)) { 55 $rows[$stat->sid][3] = array('data' => $stat->total, 'class' => 'project-issue-numeric'); 56 } 57 $output .= '<h2>'. t('Issue activity') .'</h2>'; 58 $output .= theme('table', $header, $rows); 59 60 // Project overview. 61 if (!$project->nid) { 62 // Even though we don't use the tablesorting logic in the query itself, 63 // we include it anyways because we're going to leverage the $_GET arguments 64 // to build our own tablesorting mechanism. 65 $header = array(); 66 $header['project'] = array('data' => t('Project'), 'field' => 'title'); 67 foreach ($states as $key => $value) { 68 $header[$key] = array('data' => check_plain($value), 'field' => $key); 69 } 70 $header['total'] = array('data' => t('Total'), 'field' => 'total'); 71 // Force sorting arrow to appear on active first. 72 $header[1]['sort'] = 'desc'; 73 $args = array(); 74 75 // Since we're pulling the sid to sort by here individually in the first query 76 // below, we can bastardize the tablesorting logic to get tablesorting. 77 $where = ' AND p.sid = %d'; 78 $column = 'total'; 79 if (isset($_GET['order'])) { 80 switch ($_GET['order']) { 81 case 'Project': 82 $where = ''; 83 $column = 'title'; 84 break; 85 case 'Total': 86 $where = ''; 87 break; 88 default: 89 if ($state = array_search($_GET['order'], $states)) { 90 $args[] = $state; 91 } 92 else { 93 $args[] = 1; 94 } 95 break; 96 } 97 } 98 else { 99 $args[] = 1; 100 } 101 $sort = (isset($_GET['sort']) && $_GET['sort'] == 'desc') || !isset($_GET['sort']) ? 'DESC' : 'ASC'; 102 103 $rows = array(); 104 $projects = pager_query(db_rewrite_sql("SELECT pn.nid, pn.title, COUNT(n.nid) AS total FROM {node} n INNER JOIN {project_issues} p ON n.nid = p.nid INNER JOIN {node} pn ON p.pid = pn.nid WHERE n.status = 1 AND pn.status = 1$where GROUP BY pn.nid, pn.title ORDER BY $column $sort"), 15, 0, db_rewrite_sql("SELECT COUNT(DISTINCT(n.nid)) FROM {node} n INNER JOIN {project_issues} p ON n.nid = p.pid INNER JOIN {node} pin ON p.nid = pin.nid WHERE n.status = 1 AND pin.status = 1$where"), $args); 105 $orig = array('project' => array('data' => 0)); 106 foreach ($states as $key => $value) { 107 $orig[$key] = array('data' => '', 'class' => 'project-issue-numeric'); 108 } 109 $orig['total'] = array('data' => '', 'class' => 'project-issue-numeric'); 110 111 while ($project = db_fetch_object($projects)) { 112 $rows[$project->nid] = $orig; 113 $rows[$project->nid]['project']['data'] = l($project->title, "node/$project->nid"); 114 $stats = db_query("SELECT sid, COUNT(nid) as total FROM {project_issues} WHERE pid = %d GROUP BY sid", $project->nid); 115 while ($stat = db_fetch_object($stats)) { 116 $rows[$project->nid]['total']['data'] += $stat->total; 117 $rows[$project->nid][$stat->sid]['data'] = $stat->total; 118 } 119 } 120 $output .= '<h2>'. t('Project overview') .'</h2>'; 121 $output .= '<div class="project-issue-statistics-overview-table">'; 122 $output .= theme('table', $header, $rows); 123 124 if ($pager = theme('pager', 15, 0)) { 125 $output .= $pager; 126 } 127 $output .= '</div>'; 128 } 129 130 $output .= '</div>'; 131 return $output; 132 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |