From 283acfe49f466cae4323f2cb9cc1d569df0bede4 Mon Sep 17 00:00:00 2001 From: Yagami <976204163@qq.com> Date: Fri, 28 Aug 2020 11:37:40 +0800 Subject: [PATCH] * Fix code style. --- module/block/control.php | 53 ++++++++++--- module/block/model.php | 81 ++++++++++---------- module/block/view/scrumprojectblock.html.php | 10 ++- module/design/control.php | 49 +++++------- module/design/lang/zh-cn.php | 52 +++++++------ 5 files changed, 138 insertions(+), 107 deletions(-) diff --git a/module/block/control.php b/module/block/control.php index ab14560695..c1a81aa1d3 100644 --- a/module/block/control.php +++ b/module/block/control.php @@ -206,10 +206,19 @@ class block extends control { if($this->loadModel('user')->isLogon()) $this->session->set('blockModule', $module); $blocks = $this->block->getBlockList($module, $type); - $inited = empty($this->config->$module->common->blockInited) ? '' : $this->config->$module->common->blockInited; + if($module == 'program') + { + $program = $this->loadModel('project')->getByID($this->app->session->program); + $common = $program->template . 'common'; + $inited = empty($this->config->$module->$common->blockInited) ? '' : $this->config->$module->$common->blockInited; + } + else + { + $inited = empty($this->config->$module->common->blockInited) ? '' : $this->config->$module->common->blockInited; + } /* Init block when vist index first. */ - if((empty($blocks) and !$inited and !defined('TUTORIAL')) || (empty($blocks) and $module == 'program')) + if((empty($blocks) and !$inited and !defined('TUTORIAL'))) { if($this->block->initBlock($module, $type)) die(js::reload()); } @@ -1127,7 +1136,7 @@ class block extends control { $products = $this->loadModel('product')->getPairs(); $productID = isset($this->session->product) ? 0 : $this->session->product; - if(!$productID || !array_key_exists($productID, $products)) $productID = array_key_first($products); + if(!$productID) $productID = key($products); $this->view->plans = $this->loadModel('programplan')->getDataForGantt($this->session->program, $productID, 0, 'task', false); $this->view->products = $products; @@ -1262,12 +1271,19 @@ class block extends control */ public function printScrumproductBlock() { - $products = $this->dao->select('id,name')->from(TABLE_PRODUCT)->where('program')->eq($this->session->program)->limit(15)->fetchPairs(); - $productID = array_keys($products); + $stories = array(); + $bugs = array(); + $releases = array(); - $stories = empty($productID) ? array() : $this->dao->select('count(*) as total, product')->from(TABLE_STORY)->where('product')->in($productID)->andWhere('deleted')->eq('0')->groupBy('product')->fetchPairs('product', 'total'); - $bugs = empty($productID) ? array() : $this->dao->select('count(*) as total, product')->from(TABLE_BUG)->where('product')->in($productID)->andWhere('deleted')->eq('0')->groupBy('product')->fetchPairs('product', 'total'); - $releases = empty($productID) ? array() : $this->dao->select('count(*) as total, product')->from(TABLE_RELEASE)->where('product')->in($productID)->andWhere('deleted')->eq('0')->groupBy('product')->fetchPairs('product', 'total'); + $products = $this->dao->select('id, name')->from(TABLE_PRODUCT)->where('program')->eq($this->session->program)->limit(15)->fetchPairs(); + $productIdList = array_keys($products); + if(!empty($productIdList)) + { + $fields = 'product, count(*) as total'; + $stories = $this->dao->select($fields)->from(TABLE_STORY)->where('product')->in($productIdList)->andWhere('deleted')->eq('0')->groupBy('product')->fetchPairs(); + $bugs = $this->dao->select($fields)->from(TABLE_BUG)->where('product')->in($productIdList)->andWhere('deleted')->eq('0')->groupBy('product')->fetchPairs(); + $releases = $this->dao->select($fields)->from(TABLE_RELEASE)->where('product')->in($productIdList)->andWhere('deleted')->eq('0')->groupBy('product')->fetchPairs(); + } $this->view->products = $products; $this->view->stories = $stories; @@ -1283,10 +1299,23 @@ class block extends control */ public function printScrumprojectBlock() { - $this->view->summary = $this->dao->select('count(*) as total, count(if(status="doing", id, null)) as doing, count(if(status="closed", id, null)) as finish')->from(TABLE_PROJECT) - ->where('program')->eq($this->session->program) - ->andWhere('deleted')->eq('0') - ->fetch(); + $status = $this->dao->select('status, count(*) as count')->from(TABLE_PROJECT) + ->where('deleted')->eq(0) + ->andWhere('program')->eq($this->session->program) + ->groupBy('status') + ->fetchPairs(); + + $summary = new stdclass(); + $summary->total = array_sum($status); + $summary->doing = zget($status, 'doing', 0); + $summary->closed = zget($status, 'closed', 0); + + $progress = new stdclass(); + $progress->doing = $summary->total == 0 ? 0 : round($summary->doing / $summary->total, 3); + $progress->closed = $summary->total == 0 ? 0 : round($summary->closed / $summary->total, 3); + + $this->view->summary = $summary; + $this->view->progress = $progress; } /** diff --git a/module/block/model.php b/module/block/model.php index df11cfcb06..51167f39f9 100644 --- a/module/block/model.php +++ b/module/block/model.php @@ -212,6 +212,31 @@ class blockModel extends model return $data; } + /** + * Get contribute block data. + * + * @access public + * @return array + */ + public function getContributeBlockData() + { + $account = $this->app->user->account; + $count = 'count(*) AS count'; + + $data = array(); + $data['todos'] = $this->dao->select($count)->from(TABLE_TODO)->where('account')->eq($account)->fetch('count'); + $data['stories'] = $this->dao->select($count)->from(TABLE_STORY)->where('openedBy')->eq($account)->andWhere('deleted')->eq('0')->fetch('count'); + $data['bugs'] = $this->dao->select($count)->from(TABLE_BUG)->where('resolvedBy')->eq($account)->andWhere('deleted')->eq('0')->fetch('count'); + $data['cases'] = $this->dao->select($count)->from(TABLE_CASE)->where('openedBy')->eq($account)->andWhere('deleted')->eq('0')->andWhere('product')->ne(0)->fetch('count'); + $data['tasks'] = $this->dao->select($count)->from(TABLE_TASK)->where('deleted')->eq('0') + ->andWhere('finishedBy', true)->eq($account) + ->orWhere('finishedList')->like("%,{$account},%") + ->markRight(1) + ->fetch('count'); + + return $data; + } + /** * Init block when account use first. * @@ -223,11 +248,23 @@ class blockModel extends model { $flow = isset($this->config->global->flow) ? $this->config->global->flow : 'full'; $account = $this->app->user->account; - if($module == 'program') $blocks = $this->lang->block->default[$type]['program']; - else $blocks = $module == 'my' ? $this->lang->block->default[$flow][$module] : $this->lang->block->default[$module]; + if($module == 'program') + { + $blocks = $this->lang->block->default[$type]['program']; + $programID = $this->session->program; + $program = $this->loadModel('project')->getByID($programID); + + /* Mark program block has init. */ + $this->loadModel('setting')->setItem("$account.$module.{$program->template}common.blockInited", true); + } + else + { + $blocks = $module == 'my' ? $this->lang->block->default[$flow][$module] : $this->lang->block->default[$module]; + + /* Mark this app has init. */ + $this->loadModel('setting')->setItem("$account.$module.common.blockInited", true); + } - /* Mark this app has init. */ - $this->loadModel('setting')->setItem("$account.$module.common.blockInited", true); $this->loadModel('setting')->setItem("$account.$module.block.initVersion", $this->config->block->version); foreach($blocks as $index => $block) { @@ -756,42 +793,6 @@ class blockModel extends model return $blockPairs; } - /** - * Get contribute block data. - * - * @access public - * @return array - */ - public function getContributeBlockData() - { - $data = array(); - - $data['todos'] = $this->dao->select('count(*) AS count')->from(TABLE_TODO) - ->where('account')->eq($this->app->user->account) - ->fetch('count'); - $data['stories'] = $this->dao->select('count(*) AS count')->from(TABLE_STORY) - ->where('openedBy')->eq($this->app->user->account) - ->andWhere('deleted')->eq('0') - ->fetch('count'); - $data['tasks'] = $this->dao->select('count(*) AS count')->from(TABLE_TASK) - ->where('deleted')->eq('0') - ->andWhere('finishedBy')->eq($this->app->user->account) - ->orWhere('finishedList')->like("%,{$this->app->user->account},%") - ->fetch('count'); - $data['bugs'] = $this->dao->select('count(*) AS count')->from(TABLE_BUG) - ->where('resolvedBy')->eq($this->app->user->account) - ->andWhere('deleted')->eq('0') - ->fetch('count'); - $data['cases'] = $this->dao->select('count(*) AS count')->from(TABLE_CASE) - ->where('openedBy')->eq($this->app->user->account) - ->andWhere('deleted')->eq('0') - ->andWhere('product')->ne(0) - ->andWhere('auto')->ne('unit') - ->fetch('count'); - - return $data; - } - /** * Build number params. * diff --git a/module/block/view/scrumprojectblock.html.php b/module/block/view/scrumprojectblock.html.php index f31e1dc657..f658723c6e 100644 --- a/module/block/view/scrumprojectblock.html.php +++ b/module/block/view/scrumprojectblock.html.php @@ -10,7 +10,7 @@ * @link http://www.zentao.net */ ?> - +total): ?>