From 67a880b2467f1422f759010b4f6c1cab2c4bc265 Mon Sep 17 00:00:00 2001 From: wangchunsheng Date: Thu, 18 Nov 2010 02:26:00 +0000 Subject: [PATCH] * rewrite the comment of task module. --- module/task/control.php | 173 +++++++++++++++++++------------ module/task/model.php | 127 ++++++++++++++++++----- module/task/view/create.html.php | 10 +- 3 files changed, 217 insertions(+), 93 deletions(-) diff --git a/module/task/control.php b/module/task/control.php index ab8dec3460..66b857e53d 100644 --- a/module/task/control.php +++ b/module/task/control.php @@ -11,7 +11,12 @@ */ class task extends control { - /* 构造函数。*/ + /** + * Construct function, load model of project and story modules. + * + * @access public + * @return void + */ public function __construct() { parent::__construct(); @@ -19,25 +24,36 @@ class task extends control $this->loadModel('story'); } - /* 添加任务。*/ + /** + * Create a task. + * + * @param int $projectID + * @param int $storyID + * @access public + * @return void + */ public function create($projectID = 0, $storyID = 0) { $project = $this->project->getById($projectID); $browseProjectLink = $this->createLink('project', 'browse', "projectID=$projectID&tab=task"); - /* 设置菜单。*/ + /* Set menu. */ $this->project->setMenu($this->project->getPairs(), $project->id); if(!empty($_POST)) { $tasksID = $this->task->create($projectID); if(dao::isError()) die(js::error(dao::getError())); + + /* Create actions. */ $this->loadModel('action'); foreach($tasksID as $taskID) { $actionID = $this->action->create('task', $taskID, 'Opened', ''); $this->sendmail($taskID, $actionID); } + + /* Locate the browser. */ if($this->post->after == 'continueAdding') { echo js::alert($this->lang->task->successSaved . $this->lang->task->afterChoices['continueAdding']); @@ -70,7 +86,13 @@ class task extends control $this->display(); } - /* 公共的操作。*/ + /** + * Common actions of task module. + * + * @param int $taskID + * @access public + * @return void + */ public function commonAction($taskID) { $this->view->task = $this->task->getByID($taskID); @@ -79,16 +101,21 @@ class task extends control $this->view->users = $this->loadModel('user')->getPairs('noletter, noclosed, nodeleted'); $this->view->actions = $this->loadModel('action')->getList('task', $taskID); - /* 设置菜单。*/ + /* Set menu. */ $this->project->setMenu($this->project->getPairs(), $this->view->project->id); $this->view->position[] = html::a($this->createLink('project', 'browse', "project={$this->view->task->project}"), $this->view->project->name); } - /* 编辑任务。*/ + /** + * Edit a task. + * + * @param int $taskID + * @access public + * @return void + */ public function edit($taskID) { - /* 执行公共的操作。*/ $this->commonAction($taskID); if(!empty($_POST)) @@ -110,7 +137,6 @@ class task extends control die(js::locate($this->createLink('task', 'view', "taskID=$taskID"), 'parent')); } - /* 赋值。*/ $this->view->header->title = $this->lang->task->edit; $this->view->position[] = $this->lang->task->edit; $this->view->stories = $this->story->getProjectStoryPairs($this->view->project->id); @@ -119,48 +145,20 @@ class task extends control $this->display(); } - /* 记录工时。*/ - public function logEfforts($taskID) - { - /* 执行公共的操作。*/ - $this->commonAction($taskID); - - if(!empty($_POST)) - { - $this->loadModel('action'); - $changes = $this->task->update($taskID); - if(dao::isError()) die(js::error(dao::getError())); - $files = $this->loadModel('file')->saveUpload('task', $taskID); - - if($this->post->comment != '' or !empty($changes) or !empty($files)) - { - $action = !empty($changes) ? 'Edited' : 'Commented'; - $fileAction = ''; - if(!empty($files)) $fileAction = $this->lang->addFiles . join(',', $files) . "\n" ; - $actionID = $this->action->create('task', $taskID, $action, $fileAction . $this->post->comment); - $this->action->logHistory($actionID, $changes); - $this->sendmail($taskID, $actionID); - } - die(js::locate($this->createLink('task', 'view', "taskID=$taskID"), 'parent')); - } - - /* 导航信息。*/ - $this->view->header->title = $this->lang->task->logEfforts; - $this->view->position[] = $this->lang->task->logEfforts; - - $this->display(); - } - - /* 查看任务。*/ + /** + * View a task. + * + * @param int $taskID + * @access public + * @return void + */ public function view($taskID) { - $this->loadModel('action'); $task = $this->task->getById($taskID); if(!$task) die(js::error($this->lang->notFound) . js::locate('back')); + /* Set menu. */ $project = $this->project->getById($task->project); - - /* 设置菜单。*/ $this->project->setMenu($this->project->getPairs(), $project->id); $header['title'] = $project->name . $this->lang->colon . $this->lang->task->view; @@ -171,12 +169,18 @@ class task extends control $this->view->position = $position; $this->view->project = $project; $this->view->task = $task; - $this->view->actions = $this->action->getList('task', $taskID); + $this->view->actions = $this->loadModel('action')->getList('task', $taskID); $this->view->users = $this->loadModel('user')->getPairs('noletter'); $this->display(); } - /* 确认需求变动。*/ + /** + * Confirm story change + * + * @param int $taskID + * @access public + * @return void + */ public function confirmStoryChange($taskID) { $task = $this->task->getById($taskID); @@ -185,10 +189,15 @@ class task extends control die(js::reload('parent')); } - /* 开始一个任务。*/ + /** + * Start a task. + * + * @param int $taskID + * @access public + * @return void + */ public function start($taskID) { - /* 执行公共的操作。*/ $this->commonAction($taskID); if(!empty($_POST)) @@ -207,16 +216,20 @@ class task extends control die(js::locate($this->createLink('task', 'view', "taskID=$taskID"), 'parent')); } - /* 赋值。*/ $this->view->header->title = $this->view->project->name . $this->lang->colon .$this->lang->task->start; $this->view->position[] = $this->lang->task->start; $this->display(); } - /* 完成一个任务。*/ + /** + * Complete a task. + * + * @param int $taskID + * @access public + * @return void + */ public function complete($taskID) { - /* 执行公共的操作。*/ $this->commonAction($taskID); if(!empty($_POST)) @@ -235,17 +248,21 @@ class task extends control die(js::locate($this->createLink('task', 'view', "taskID=$taskID"), 'parent')); } - /* 赋值。*/ $this->view->header->title = $this->view->project->name . $this->lang->colon .$this->lang->task->complete; $this->view->position[] = $this->lang->task->complete; $this->display(); } - /* 取消一个任务。*/ + /** + * Cancel a task. + * + * @param int $taskID + * @access public + * @return void + */ public function cancel($taskID) { - /* 执行公共的操作。*/ $this->commonAction($taskID); if(!empty($_POST)) @@ -264,14 +281,21 @@ class task extends control die(js::locate($this->createLink('task', 'view', "taskID=$taskID"), 'parent')); } - /* 赋值。*/ $this->view->header->title = $this->view->project->name . $this->lang->colon .$this->lang->task->cancel; $this->view->position[] = $this->lang->task->cancel; $this->display(); } - /* 删除一个任务。*/ + /** + * Delete a task. + * + * @param int $projectID + * @param int $taskID + * @param string $confirm yes|no + * @access public + * @return void + */ public function delete($projectID, $taskID, $confirm = 'no') { if($confirm == 'no') @@ -287,14 +311,21 @@ class task extends control } } - /* 发送邮件。*/ + /** + * Send email. + * + * @param int $taskID + * @param int $actionID + * @access private + * @return void + */ private function sendmail($taskID, $actionID) { - /* 设定toList和ccList。*/ + /* Set toList and ccList. */ $task = $this->task->getByID($taskID); $toList = $task->owner; - $ccList = trim($task->mailto, ','); + if($toList == '') { if($ccList == '') return; @@ -311,23 +342,30 @@ class task extends control } } - /* 获得action信息。*/ + /* Get action info. */ $action = $this->action->getById($actionID); $history = $this->action->getHistory($actionID); $action->history = isset($history[$actionID]) ? $history[$actionID] : array(); - /* 赋值,获得邮件内容。*/ + /* Create the email content. */ $this->view->task = $task; $this->view->action = $action; $this->clear(); $mailContent = $this->parse($this->moduleName, 'sendmail'); - /* 发信。*/ + /* Send emails. */ $this->loadModel('mail')->send($toList, 'TASK#' . $task->id . $this->lang->colon . $task->name, $mailContent, $ccList); if($this->mail->isError()) echo js::error($this->mail->getError()); } - /* Ajax请求: 返回用户任务的下拉列表框。*/ + /** + * AJAX: return tasks of a user in html select. + * + * @param string $account + * @param string $status + * @access public + * @return string + */ public function ajaxGetUserTasks($account = '', $status = 'wait,doing') { if($account == '') $account = $this->app->user->account; @@ -335,7 +373,14 @@ class task extends control die(html::select('task', $tasks, '', 'class=select-1')); } - /* Ajax请求: 返回项目任务的下拉列表框。*/ + /** + * AJAX: return project tasks in html select. + * + * @param int $projectID + * @param int $taskID + * @access public + * @return string + */ public function ajaxGetProjectTasks($projectID, $taskID = 0) { $tasks = $this->task->getProjectTaskPairs((int)$projectID); diff --git a/module/task/model.php b/module/task/model.php index 04eb275f32..df42811a81 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -15,7 +15,13 @@ class taskModel extends model { const CUSTOM_STATUS_ORDER = 'wait,doing,done,cancel'; - /* 新增一个任务。*/ + /** + * Create a task. + * + * @param int $projectID + * @access public + * @return void + */ public function create($projectID) { $tasksID = array(); @@ -50,7 +56,13 @@ class taskModel extends model return $tasksID; } - /* 更新一个任务。*/ + /** + * Update a task. + * + * @param int $taskID + * @access public + * @return void + */ public function update($taskID) { $oldTask = $this->getById($taskID); @@ -77,7 +89,13 @@ class taskModel extends model if(!dao::isError()) return common::createChanges($oldTask, $task); } - /* 改变一个任务的状态。*/ + /** + * Change status of a task and return the diff info. + * + * @param int $taskID + * @access public + * @return array the diff info. + */ public function changeStatus($taskID) { $oldTask = $this->getById($taskID); @@ -100,7 +118,13 @@ class taskModel extends model if(!dao::isError()) return common::createChanges($oldTask, $task); } - /* 通过id获取一个任务信息。*/ + /** + * Get task info by Id. + * + * @param int $taskID + * @access public + * @return object|bool + */ public function getById($taskID) { $task = $this->dao->select('t1.*, t2.id AS storyID, t2.title AS storyTitle, t2.version AS latestStoryVersion, t2.status AS storyStatus, t3.realname AS ownerRealName') @@ -114,7 +138,7 @@ class taskModel extends model if(!$task) return false; if($task->mailto) { - $task->mailto = ltrim(trim($task->mailto), ','); // 去掉开始的,。 + $task->mailto = ltrim(trim($task->mailto), ','); // remove the first , $task->mailto = str_replace(' ', '', $task->mailto); $task->mailto = rtrim($task->mailto, ',') . ','; $task->mailto = str_replace(',', ', ', $task->mailto); @@ -123,16 +147,23 @@ class taskModel extends model return $this->processTask($task); } - /* 获得某一个项目的任务列表。*/ + /** + * Get tasks of a project. + * + * @param int $projectID + * @param string $status all|needConfirm|wait|doing|done|cancel + * @param string $orderBy + * @param object $pager + * @access public + * @return array|bool + */ public function getProjectTasks($projectID, $status = 'all', $orderBy = 'status_asc, id_desc', $pager = null) { $orderBy = str_replace('status', 'statusCustom', $orderBy); $tasks = $this->dao->select('t1.*, t2.id AS storyID, t2.title AS storyTitle, t2.version AS latestStoryVersion, t2.status AS storyStatus, t3.realname AS ownerRealName') ->from(TABLE_TASK)->alias('t1') - ->leftJoin(TABLE_STORY)->alias('t2') - ->on('t1.story = t2.id') - ->leftJoin(TABLE_USER)->alias('t3') - ->on('t1.owner = t3.account') + ->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story = t2.id') + ->leftJoin(TABLE_USER)->alias('t3')->on('t1.owner = t3.account') ->where('t1.project')->eq((int)$projectID) ->andWhere('t1.deleted')->eq(0) ->beginIF($status == 'needConfirm')->andWhere('t2.version > t1.storyVersion')->andWhere("t2.status = 'active'")->fi() @@ -144,14 +175,21 @@ class taskModel extends model return false; } - /* 获得某一个项目的任务id=>name列表。*/ + /** + * Get project taskes paris.1 + * + * @param int $projectID + * @param string $status + * @param string $orderBy + * @access public + * @return array + */ public function getProjectTaskPairs($projectID, $status = 'all', $orderBy = 'id_desc') { $tasks = array('' => ''); $stmt = $this->dao->select('t1.id, t1.name, t2.realname AS ownerRealName') ->from(TABLE_TASK)->alias('t1') - ->leftJoin(TABLE_USER)->alias('t2') - ->on('t1.owner = t2.account') + ->leftJoin(TABLE_USER)->alias('t2')->on('t1.owner = t2.account') ->where('t1.project')->eq((int)$projectID) ->andWhere('t1.deleted')->eq(0) ->beginIF($status != 'all')->andWhere('t1.status')->in($status)->fi() @@ -161,7 +199,14 @@ class taskModel extends model return $tasks; } - /* 获得用户的任务列表。*/ + /** + * Get tasks of a user. + * + * @param string $account + * @param string $status + * @access public + * @return array + */ public function getUserTasks($account, $status = 'all') { $tasks = $this->dao->select('t1.*, t2.id as projectID, t2.name as projectName, t3.id as storyID, t3.title as storyTitle, t3.status AS storyStatus, t3.version AS latestStoryVersion') @@ -178,14 +223,20 @@ class taskModel extends model return array(); } - /* 获得用户的任务id=>name列表。*/ + /** + * Get tasks pairs of a user. + * + * @param string $account + * @param string $status + * @access public + * @return array + */ public function getUserTaskPairs($account, $status = 'all') { $tasks = array(); $sql = $this->dao->select('t1.id, t1.name, t2.name as project') ->from(TABLE_TASK)->alias('t1') - ->leftjoin(TABLE_PROJECT)->alias('t2') - ->on('t1.project = t2.id') + ->leftjoin(TABLE_PROJECT)->alias('t2')->on('t1.project = t2.id') ->where('t1.owner')->eq($account) ->andWhere('t1.deleted')->eq(0); if($status != 'all') $sql->andwhere('t1.status')->in($status); @@ -197,7 +248,14 @@ class taskModel extends model return $tasks; } - /* 获得story对应的task id=>name列表。*/ + /** + * Get task pairs of a story. + * + * @param int $storyID + * @param int $projectID + * @access public + * @return array + */ public function getStoryTaskPairs($storyID, $projectID = 0) { return $this->dao->select('id, name') @@ -208,7 +266,14 @@ class taskModel extends model ->fetchPairs(); } - /* 获得story对应的task数量。*/ + /** + * Get counts of some stories's taskes. + * + * @param array $stories + * @param int $projectID + * @access public + * @return int + */ public function getStoryTaskCounts($stories, $projectID = 0) { $taskCounts = $this->dao->select('story, COUNT(*) AS tasks') @@ -222,13 +287,19 @@ class taskModel extends model return $taskCounts; } - /* 计算一组任务的相关状态。*/ + /** + * Batch process taskes. + * + * @param int $tasks + * @access private + * @return void + */ private function processTasks($tasks) { $today = helper::today(); foreach($tasks as $task) { - /* 计算是否延期。*/ + /* Delayed or not. */ if($task->status !== 'done' and $task->status !== 'cancel') { if($task->deadline != '0000-00-00') @@ -238,7 +309,7 @@ class taskModel extends model } } - /* 判断需求是否变更。*/ + /* Story changed or not. */ $task->needConfirm = false; if($task->storyStatus == 'active' and $task->latestStoryVersion > $task->storyVersion) { @@ -248,12 +319,18 @@ class taskModel extends model return $tasks; } - /* 计算一个任务的相关状态。*/ + /** + * Process a task, judge it's status. + * + * @param object $task + * @access private + * @return object + */ private function processTask($task) { $today = helper::today(); - /* 计算是否延期。*/ + /* Delayed or not?. */ if($task->status !== 'done' and $task->status !== 'cancel') { if($task->deadline != '0000-00-00') @@ -263,7 +340,7 @@ class taskModel extends model } } - /* 判断需求是否变更。*/ + /* Story changed or not. */ $task->needConfirm = false; if($task->storyStatus == 'active' and $task->latestStoryVersion > $task->storyVersion) { diff --git a/module/task/view/create.html.php b/module/task/view/create.html.php index ec5ecb4872..0dc6e5c683 100644 --- a/module/task/view/create.html.php +++ b/module/task/view/create.html.php @@ -16,14 +16,15 @@