From c51f44ec8c833daaadfe7c1e6f59f8fe24607548 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 19 Jan 2016 16:39:26 +0000 Subject: [PATCH] changing the site home to show issue counts --- codepot/src/codepot/controllers/site.php | 27 +++++++++++++++----- codepot/src/codepot/models/issuemodel.php | 31 +++++++++++++++++++++++ codepot/src/codepot/views/site_home.php | 22 ++++++++++++++-- 3 files changed, 71 insertions(+), 9 deletions(-) diff --git a/codepot/src/codepot/controllers/site.php b/codepot/src/codepot/controllers/site.php index 6a6e11ff..093f2b35 100644 --- a/codepot/src/codepot/controllers/site.php +++ b/codepot/src/codepot/controllers/site.php @@ -24,7 +24,6 @@ class Site extends Controller $this->lang->load ('common', CODEPOT_LANG); $this->lang->load ('site', CODEPOT_LANG); - $this->load->library ('IssueHelper', 'issuehelper'); $this->lang->load ('issue', CODEPOT_LANG); } @@ -86,11 +85,24 @@ class Site extends Controller // get the issue for all users $issues = $this->issues->getMyIssues ( - /*$login['id']*/ "", $this->issuehelper->_get_open_status_array($this->lang)); + /*$login['id']*/ '', $this->issuehelper->_get_open_status_array($this->lang)); $recently_resolved_issues = $this->issues->getMyIssues ( - "", $this->issuehelper->_get_resolved_status_array($this->lang), 168); + '', $this->issuehelper->_get_resolved_status_array($this->lang), 168); - if ($issues === FALSE || $recently_resolved_issues === FALSE) + $open_issue_counts_per_project = $this->issues->countIssuesPerProject ( + '', $this->issuehelper->_get_open_status_array($this->lang), 0); + + if ($login['id'] == '') + { + $your_open_issue_counts_per_project = array (); + } + else + { + $your_open_issue_counts_per_project = $this->issues->countIssuesPerProject ( + $login['id'], $this->issuehelper->_get_open_status_array($this->lang), 0); + } + + if ($issues === FALSE || $recently_resolved_issues === FALSE || $open_issue_counts_per_project === FALSE) { $data['login'] = $login; $data['message'] = 'DATABASE ERROR'; @@ -98,13 +110,14 @@ class Site extends Controller return; } - $data['login'] = $login; $data['latest_projects'] = $latest_projects; $data['log_entries'] = $log_entries; $data['site'] = $site; $data['issues'] = $issues; $data['recently_resolved_issues'] = $recently_resolved_issues; + $data['open_issue_counts_per_project'] = $open_issue_counts_per_project; + $data['your_open_issue_counts_per_project'] = $your_open_issue_counts_per_project; $data['issue_type_array'] = $this->issuehelper->_get_type_array($this->lang); $data['issue_status_array'] = $this->issuehelper->_get_status_array($this->lang); $data['issue_priority_array'] = $this->issuehelper->_get_priority_array($this->lang); @@ -401,7 +414,7 @@ class Site extends Controller $this->load->model ('LogModel', 'logs'); $this->load->model ('SiteModel', 'sites'); - $site = $this->sites->get ($this->config->config['language']); + $site = $this->sites->get ($this->config->config['language']); if ($site === FALSE) { $data['login'] = $login; @@ -411,7 +424,7 @@ class Site extends Controller } if ($site === NULL && CODEPOT_DEFAULT_SITE_LANGUAGE != '') { - $site = $this->sites->get (CODEPOT_DEFAULT_SITE_LANGUAGE); + $site = $this->sites->get (CODEPOT_DEFAULT_SITE_LANGUAGE); if ($site === FALSE) { $data['login'] = $login; diff --git a/codepot/src/codepot/models/issuemodel.php b/codepot/src/codepot/models/issuemodel.php index 38a4010e..e5765863 100644 --- a/codepot/src/codepot/models/issuemodel.php +++ b/codepot/src/codepot/models/issuemodel.php @@ -197,6 +197,37 @@ class IssueModel extends Model return $result[0]->issue_count; } + function countIssuesPerProject ($userid, $status_filter, $hour_limit = 0) + { + $this->db->trans_begin (); + if (strlen($userid) > 0) $this->db->where ('owner', $userid); + + if (is_array($status_filter)) + { + $this->db->where_in ('status', array_keys($status_filter)); + } + + if ($hour_limit > 0) + { + //$this->db->where ("updatedon >= SYSDATE() - INTERVAL {$hour_limit} HOUR"); + $this->db->where ("updatedon >= CURRENT_TIMESTAMP - INTERVAL '{$hour_limit}' HOUR"); + } + + $this->db->select ('projectid, COUNT(id) AS issue_count'); + $this->db->group_by ('projectid'); + $query = $this->db->get ('issue'); + if ($this->db->trans_status() === FALSE) + { + $this->errmsg = $this->db->_error_message(); + $this->db->trans_rollback (); + return FALSE; + } + + $this->db->trans_commit(); + + return $query->result (); + } + function getFile ($userid, $project, $issueid, $filename) { $this->db->trans_start (); diff --git a/codepot/src/codepot/views/site_home.php b/codepot/src/codepot/views/site_home.php index c30a2d8e..d8583160 100644 --- a/codepot/src/codepot/views/site_home.php +++ b/codepot/src/codepot/views/site_home.php @@ -290,17 +290,34 @@ foreach ($latest_projects as $project)
lang->line('Open issues')?>
+ + +