From c9eb3da45f9e85993cd8be1a855a8faf8839f5c0 Mon Sep 17 00:00:00 2001 From: wangchunsheng Date: Fri, 27 Nov 2009 02:05:58 +0000 Subject: [PATCH] + add the task count in the project story list page. --- module/project/control.php | 24 +++++++++++++----------- module/project/view/story.html.php | 2 +- module/task/model.php | 29 ++++++++++++++++++++++++++++- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/module/project/control.php b/module/project/control.php index 9e9f121b5f..1dd93353dc 100644 --- a/module/project/control.php +++ b/module/project/control.php @@ -111,7 +111,7 @@ class project extends control /* 加载story, user模块,加载task模块的语言。*/ $this->loadModel('story'); $this->loadModel('user'); - $this->app->loadLang('task'); + $this->loadModel('task'); /* 记录用户当前选择的列表。*/ $this->app->session->set('storyList', $this->app->getURI(true)); @@ -126,18 +126,20 @@ class project extends control /* 分页操作。*/ $this->app->loadClass('pager', $static = true); - $pager = new pager($recTotal, $recPerPage, $pageID); - $stories = $this->story->getProjectStories($projectID, $orderBy, $pager); - $users = $this->user->getPairs($this->app->company->id, 'noletter'); + $pager = new pager($recTotal, $recPerPage, $pageID); + $stories = $this->story->getProjectStories($projectID, $orderBy, $pager); + $storyTasks = $this->task->getStoryTaskCounts(array_keys($stories), $projectID); + $users = $this->user->getPairs($this->app->company->id, 'noletter'); /* 赋值。*/ - $this->assign('header', $header); - $this->assign('position', $position); - $this->assign('stories', $stories); - $this->assign('tabID', 'story'); - $this->assign('pager', $pager->get()); - $this->assign('orderBy', $orderBy); - $this->assign('users', $users); + $this->assign('header', $header); + $this->assign('position', $position); + $this->assign('stories', $stories); + $this->assign('storyTasks', $storyTasks); + $this->assign('tabID', 'story'); + $this->assign('pager', $pager->get()); + $this->assign('orderBy', $orderBy); + $this->assign('users', $users); $this->display(); } diff --git a/module/project/view/story.html.php b/module/project/view/story.html.php index 81d15176bb..8251259716 100644 --- a/module/project/view/story.html.php +++ b/module/project/view/story.html.php @@ -80,7 +80,7 @@ function selectProject(projectID) id)); else printf('%03d', $story->id);?> pri;?> - title;?> + title . ' (' . $storyTasks[$story->id] . ')';?> assignedTo];?> openedBy];?> estimate;?> diff --git a/module/task/model.php b/module/task/model.php index e6895a116f..af3484d133 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -43,7 +43,11 @@ class taskModel extends model ->check('name', 'notempty') ->checkIF($task->estimate != '', 'estimate', 'float') ->exec(); - if(!dao::isError()) return $this->dao->lastInsertID(); + if(!dao::isError()) + { + //$this->dao->update(TABLE_STORY)->set('status')->eq('doing')->where('id')->eq() + return $this->dao->lastInsertID(); + } } /* 更新一个任务。*/ @@ -150,4 +154,27 @@ class taskModel extends model } return $tasks; } + + /* 获得story对应的task id=>name列表。*/ + public function getStoryTaskPairs($storyID, $projectID = 0) + { + $sql = $this->dao->select('name, id') + ->from(TABLE_TASK) + ->where('story')->eq((int)$storyID); + if($projectID > 0) $sql->andwhere('project')->eq((int)$projectID); + return $sql->fetchPairs(); + } + + /* 获得story对应的task数量。*/ + public function getStoryTaskCounts($stories, $projectID = 0) + { + $sql = $this->dao->select('story, COUNT(*) AS tasks') + ->from(TABLE_TASK) + ->where('story')->in($stories); + if($projectID > 0) $sql->andwhere('project')->eq((int)$projectID); + $sql->groupBy('story'); + $taskCounts = $sql->fetchPairs(); + foreach($stories as $storyID) if(!isset($taskCounts[$storyID])) $taskCounts[$storyID] = 0; + return $taskCounts; + } }