From 6d55602ef38c50d748afa83ee305cc1f78a8c743 Mon Sep 17 00:00:00 2001 From: William MARTIN Date: Wed, 15 Jun 2011 17:30:23 +0200 Subject: [PATCH] Add IDF_Project::getIssueCountByOwner and use it into IDF_Views_Issue::summary --- src/IDF/Project.php | 41 +++++++++++++++++++++++++++++++++++++++++ src/IDF/Views/Issue.php | 20 +++++++++----------- 2 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/IDF/Project.php b/src/IDF/Project.php index 2f09219..14f66c7 100644 --- a/src/IDF/Project.php +++ b/src/IDF/Project.php @@ -132,6 +132,47 @@ class IDF_Project extends Pluf_Model } return $projects[0]; } + + /** + * Returns the number of open/closed issues. + * + * @param string Status ('open'), 'closed' + * @param IDF_Tag Subfilter with a label (null) + * @return int Count + */ + public function getIssueCountByOwner($status='open') + { + switch ($status) { + case 'open': + $tags = implode(',', $this->getTagIdsByStatus('open')); + break; + case 'closed': + default: + $tags = implode(',', $this->getTagIdsByStatus('closed')); + break; + } + $sqlIssueTable = Pluf::factory('IDF_Issue')->getSqlTable(); + $query = <<<"QUERY" +SELECT uid AS id,COUNT(uid) AS nb +FROM ( + SELECT COALESCE(owner, -1) AS uid + FROM $sqlIssueTable + WHERE status IN ($tags) + ) AS ff +GROUP BY uid +QUERY; + $db = Pluf::db(); + $dbData = $db->select($query); + $ownerStatistics = array(); + foreach ($dbData as $k => $v) { + $key = ($v['id'] === '-1') ? null : $v['id']; + $ownerStatistics[$key] = (int)$v['nb']; + } + + arsort($ownerStatistics); + + return $ownerStatistics; + } /** * Returns the number of open/closed issues. diff --git a/src/IDF/Views/Issue.php b/src/IDF/Views/Issue.php index 22c1e2e..fc9d7b4 100644 --- a/src/IDF/Views/Issue.php +++ b/src/IDF/Views/Issue.php @@ -105,17 +105,15 @@ class IDF_Views_Issue if ($opened > 0) { // Issue owner statistics - $sqlIssueTable = Pluf::factory('IDF_Issue')->getSqlTable(); - $sqlUsersTable = Pluf::factory('Pluf_User')->getSqlTable(); - $otags = implode(',', $prj->getTagIdsByStatus('open')); - $query = <<<"QUERY" -SELECT CONCAT(first_name, " ", last_name) as name, nb FROM (SELECT uid as id,count(uid) as nb FROM (SELECT coalesce(owner, -1) as uid FROM $sqlIssueTable WHERE status IN ($otags)) as ff group by uid) AS ff LEFT JOIN $sqlUsersTable using(id) -QUERY; - $db = Pluf::db(); - $dbData = $db->select($query); - foreach ($dbData as $k => $v) { - $key = ($v['name'] === null) ? __('Not assigned') : $v['name']; - $ownerStatistics[$key] = array($v['nb'], (int)(100 * $v['nb'] / $opened)); + $owners = $prj->getIssueCountByOwner('open'); + foreach ($owners as $user => $nb) { + if ($user === '') { + $key = __('Not assigned'); + } else { + $obj = Pluf::factory('Pluf_User')->getOne(array('filter'=>'id='.$user)); + $key = $obj->first_name . ' ' . $obj->last_name; + } + $ownerStatistics[$key] = array($nb, (int)(100 * $nb / $opened)); } // Issue class tag statistics