From d5eddfdbbf954c7e4dd71765f65028e5f187dcf3 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Thu, 6 Sep 2018 16:48:27 +0800 Subject: [PATCH] * finish task #4765. --- module/block/control.php | 68 ++++++++------------------- module/block/model.php | 99 ++++++++++++++++++++++++++++++++++------ 2 files changed, 104 insertions(+), 63 deletions(-) diff --git a/module/block/control.php b/module/block/control.php index 671ae36898..b8665325e9 100644 --- a/module/block/control.php +++ b/module/block/control.php @@ -741,29 +741,20 @@ class block extends control if(!empty($this->params->type) and preg_match('/[^a-zA-Z0-9_]/', $this->params->type)) die(); $status = isset($this->params->type) ? $this->params->type : ''; - $orderBy = isset($this->params->orderBy) ? $this->params->orderBy : 'id_asc'; - /* Get products. */ - $products = $this->loadModel('product')->getList($status); - foreach($products as $productID => $product) - { - if(!$this->product->checkPriv($product)) unset($products[$productID]); - } - $productIDList = array_keys($products); - if(!$productIDList) + $products = $this->block->getProductsLikeDropMenu($status); + $productIdList = array_keys($products); + + if(empty($products)) { $this->view->products = $products; return false; } - $products = $this->dao->select('*')->from(TABLE_PRODUCT) - ->where('id')->in($productIDList) - ->orderBy($orderBy) - ->fetchAll('id'); /* Get stories. */ $stories = $this->dao->select('product, stage, COUNT(status) AS count')->from(TABLE_STORY) ->where('deleted')->eq(0) - ->andWhere('product')->in($productIDList) + ->andWhere('product')->in($productIdList) ->groupBy('product, stage') ->fetchGroup('product', 'stage'); /* Padding the stories to sure all status have records. */ @@ -779,7 +770,7 @@ class block extends control /* Get plans. */ $plans = $this->dao->select('product, end')->from(TABLE_PRODUCTPLAN) ->where('deleted')->eq(0) - ->andWhere('product')->in($productIDList) + ->andWhere('product')->in($productIdList) ->fetchGroup('product'); foreach($plans as $product => $productPlans) { @@ -802,7 +793,7 @@ class block extends control /* Get projects. */ $projects = $this->dao->select('t1.product, t2.status, t2.end')->from(TABLE_PROJECTPRODUCT)->alias('t1') ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project=t2.id') - ->where('t1.product')->in($productIDList) + ->where('t1.product')->in($productIdList) ->andWhere('t2.deleted')->eq(0) ->fetchGroup('product'); foreach($projects as $product => $productProjects) @@ -829,7 +820,7 @@ class block extends control /* Get releases. */ $releases = $this->dao->select('product, status, COUNT(*) AS count')->from(TABLE_RELEASE) ->where('deleted')->eq(0) - ->andWhere('product')->in($productIDList) + ->andWhere('product')->in($productIdList) ->groupBy('product, status') ->fetchGroup('product', 'status'); foreach($releases as $product => $release) @@ -843,7 +834,7 @@ class block extends control /* Get last releases. */ $lastReleases = $this->dao->select('product, COUNT(*) AS count')->from(TABLE_RELEASE) ->where('date')->eq(date('Y-m-d', strtotime('-1 day'))) - ->andWhere('product')->in($productIDList) + ->andWhere('product')->in($productIdList) ->groupBy('product') ->fetchPairs(); @@ -879,33 +870,23 @@ class block extends control $this->app->loadLang('bug'); $status = isset($this->params->type) ? $this->params->type : ''; - $orderBy = isset($this->params->orderBy) ? $this->params->orderBy : 'id_asc'; $num = isset($this->params->num) ? (int)$this->params->num : 0; /* Get projects. */ - $projects = $this->loadModel('project')->getList($status); - foreach($projects as $projectID => $project) - { - if(!$this->project->checkPriv($project)) unset($projects[$projectID]); - } - $projectIDList = array_keys($projects); - if(!$projectIDList) + $projects = $this->block->getProjectsLikeDropMenu($status); + if(empty($projects)) { $this->view->projects = $projects; return false; } - $projects = $this->dao->select('*')->from(TABLE_PROJECT) - ->where('id')->in($projectIDList) - ->orderBy($orderBy) - ->beginIF($this->viewType != 'json')->limit($num)->fi() - ->fetchAll('id'); - $projectIDList = array_keys($projects); + + $projectIdList = array_keys($projects); /* Get tasks. */ $yesterday = date('Y-m-d', strtotime('-1 day')); $tasks = $this->dao->select("project, count(id) as totalTasks, count(status in ('wait','doing','pause') or null) as undoneTasks, count(finishedDate like '{$yesterday}%' or null) as yesterdayFinished, sum(if(status != 'cancel', estimate, 0)) as totalEstimate, sum(consumed) as totalConsumed, sum(if(status != 'cancel', `left`, 0)) as totalLeft")->from(TABLE_TASK) - ->where('project')->in($projectIDList) + ->where('project')->in($projectIdList) ->andWhere('deleted')->eq(0) ->andWhere('parent')->eq(0) ->groupBy('project') @@ -923,7 +904,7 @@ class block extends control /* Get stories. */ $stories = $this->dao->select("t1.project, count(t2.status) as totalStories, count(t2.status != 'closed' or null) as unclosedStories, count(t2.stage = 'released' or null) as releasedStories")->from(TABLE_PROJECTSTORY)->alias('t1') ->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story = t2.id') - ->where('t1.project')->in($projectIDList) + ->where('t1.project')->in($projectIdList) ->andWhere('t2.deleted')->eq(0) ->groupBy('project') ->fetchAll('project'); @@ -939,7 +920,7 @@ class block extends control /* Get bugs. */ $bugs = $this->dao->select("project, status, count(status) as totalBugs, count(status = 'active' or null) as activeBugs, count(resolvedDate like '{$yesterday}%' or null) as yesterdayResolved")->from(TABLE_BUG) - ->where('project')->in($projectIDList) + ->where('project')->in($projectIdList) ->andWhere('deleted')->eq(0) ->groupBy('project') ->fetchAll('project'); @@ -997,24 +978,15 @@ class block extends control if(!empty($this->params->type) and preg_match('/[^a-zA-Z0-9_]/', $this->params->type)) die(); $status = isset($this->params->type) ? $this->params->type : ''; - $orderBy = isset($this->params->orderBy) ? $this->params->orderBy : 'id_asc'; - /* Get products. */ - $products = $this->loadModel('product')->getList($status); - foreach($products as $productID => $product) - { - if(!$this->product->checkPriv($product)) unset($products[$productID]); - } - $productIDList = array_keys($products); - if(!$productIDList) + $products = $this->block->getProductsLikeDropMenu($status); + $productIdList = array_keys($products); + + if(empty($products)) { $this->view->products = $products; return false; } - $products = $this->dao->select('*')->from(TABLE_PRODUCT) - ->where('id')->in($productIDList) - ->orderBy($orderBy) - ->fetchAll('id'); $testedBuilds = $this->dao->select('build')->from(TABLE_TESTTASK)->where('product')->in(array_keys($products))->andWhere('project')->ne(0)->andWhere('deleted')->eq(0)->fetchPairs(); $builds = $this->dao->select('id, product, name, bugs')->from(TABLE_BUILD)->where('id')->in($testedBuilds)->andWhere('deleted')->eq(0)->fetchGroup('product', 'id'); diff --git a/module/block/model.php b/module/block/model.php index 6bfa893c47..c57e60d91c 100644 --- a/module/block/model.php +++ b/module/block/model.php @@ -471,11 +471,6 @@ class blockModel extends model $params->type['options'] = $this->lang->block->typeList->product; $params->type['control'] = 'select'; - $params->orderBy['name'] = $this->lang->block->orderBy; - $params->orderBy['default'] = 'id_desc'; - $params->orderBy['options'] = $this->lang->block->orderByList->product; - $params->orderBy['control'] = 'select'; - return json_encode($params); } @@ -492,11 +487,6 @@ class blockModel extends model $params->type['options'] = $this->lang->block->typeList->project; $params->type['control'] = 'select'; - $params->orderBy['name'] = $this->lang->block->orderBy; - $params->orderBy['default'] = 'id_desc'; - $params->orderBy['options'] = $this->lang->block->orderByList->project; - $params->orderBy['control'] = 'select'; - return json_encode($params); } @@ -513,11 +503,6 @@ class blockModel extends model $params->type['options'] = $this->lang->block->typeList->product; $params->type['control'] = 'select'; - $params->orderBy['name'] = $this->lang->block->orderBy; - $params->orderBy['default'] = 'id_desc'; - $params->orderBy['options'] = $this->lang->block->orderByList->product; - $params->orderBy['control'] = 'select'; - return json_encode($params); } @@ -645,4 +630,88 @@ class blockModel extends model return $key == $hash; } + + /** + * Get products like drop menu order + * + * @param strint $status + * @access public + * @return array + */ + public function getProductsLikeDropMenu($status) + { + $products = $this->loadModel('product')->getList($status); + if(empty($products)) return $products; + + $lines = $this->loadModel('tree')->getLinePairs(); + $productList = array(); + foreach($lines as $id => $name) + { + foreach($products as $key => $product) + { + if($product->line == $id) + { + $product->name = $name . '/' . $product->name; + $productList[] = $product; + unset($products[$key]); + } + } + } + $productList = array_merge($productList, $products); + + $products = $mineProducts = $otherProducts = $closedProducts = array(); + foreach($productList as $product) + { + if(!$this->app->user->admin and !$this->product->checkPriv($product)) continue; + if($product->status == 'normal' and $product->PO == $this->app->user->account) + { + $mineProducts[$product->id] = $product; + } + elseif($product->status == 'normal' and $product->PO != $this->app->user->account) + { + $otherProducts[$product->id] = $product; + } + elseif($product->status == 'closed') + { + $closedProducts[$product->id] = $product; + } + } + $products = $mineProducts + $otherProducts + $closedProducts; + + return $products; + } + + /** + * Get projects like drop menu order + * + * @param string $status + * @access public + * @return array + */ + public function getProjectsLikeDropMenu($status) + { + $projectList = $this->loadModel('project')->getList($status); + if(empty($projectList)) return $projectList; + + $projects = $mineProjects = $otherProjects = $closedProjects = array(); + foreach($projectList as $project) + { + if(!$this->app->user->admin and !$this->project->checkPriv($project->id)) continue; + if($project->status != 'done' and $project->status != 'closed' and $project->PM == $this->app->user->account) + { + $mineProjects[$project->id] = $project; + } + elseif($project->status != 'done' and $project->status != 'closed' and !($project->PM == $this->app->user->account)) + { + $otherProjects[$project->id] = $project; + } + elseif($project->status == 'done' or $project->status == 'closed') + { + $closedProjects[$project->id] = $project; + } + } + $projects = $mineProjects + $otherProjects + $closedProjects; + + return $projects; + } }