From 8a7ba33735d2a4b3587aa421dd2465f97395a9fb Mon Sep 17 00:00:00 2001 From: zhujinyong Date: Mon, 25 Feb 2013 05:59:38 +0000 Subject: [PATCH] * compute task estimate. --- module/task/control.php | 57 +++++++++- module/task/css/common.css | 1 + module/task/lang/en.php | 24 ++-- module/task/lang/zh-cn.php | 24 ++-- module/task/model.php | 145 ++++++++++++++++++++++--- module/task/view/batchcreate.html.php | 2 +- module/task/view/editestimate.html.php | 29 +++++ module/task/view/record.html.php | 50 ++++++--- 8 files changed, 275 insertions(+), 57 deletions(-) create mode 100644 module/task/css/common.css create mode 100644 module/task/view/editestimate.html.php diff --git a/module/task/control.php b/module/task/control.php index ba4a74ec21..3cc63bfbb6 100644 --- a/module/task/control.php +++ b/module/task/control.php @@ -438,17 +438,66 @@ class task extends control if(!empty($_POST)) { - $changes = $this->task->record($taskID); - $actionID = $this->action->create('task', $taskID, 'Recorded', $this->post->comment, (float)$this->post->consumed); - $this->action->logHistory($actionID, $changes); + $this->task->record($taskID); if(isonlybody()) die(js::reload('parent.parent')); die(js::locate($this->createLink('task', 'view', "taskID=$taskID"), 'parent')); } - $this->view->title = $this->lang->task->record; + $this->session->set('estimateList', $this->app->getURI(true)); + + $this->view->estimates = $this->task->getTaskEstimate($taskID); + $this->view->title = $this->lang->task->record; $this->display(); } + /** + * Edit consumed and estimate. + * + * @param int $estimateID + * @access public + * @return void + */ + public function editEstimate($estimateID) + { + $estimate = $this->task->getEstimateById($estimateID); + if(!empty($_POST)) + { + $this->task->updateEstimate($estimateID); + if(dao::isError()) die(js::error(dao::getError())); + + $url = $this->session->estimateList ? $this->session->estimateList : inlink('record', "taskID={$estimate->task}"); + die(js::locate($url, 'parent')); + } + + $estimate = $this->task->getEstimateById($estimateID); + + $this->view->title = $this->lang->task->editEstimate; + $this->view->position[] = $this->lang->task->editEstimate; + $this->view->estimate = $estimate; + $this->display(); + } + + /** + * Delete estimate. + * + * @param int $estimateID + * @param string $confirm + * @access public + * @return void + */ + public function deleteEstimate($estimateID, $confirm = 'no') + { + if($confirm == 'no') + { + die(js::confirm($this->lang->task->confirmDeleteEstimate, $this->createLink('task', 'deleteEstimate', "estimateID=$estimateID&confirm=yes"))); + } + else + { + $this->task->deleteEstimate($estimateID); + die(js::reload('parent')); + } + } + /** * Finish a task. * diff --git a/module/task/css/common.css b/module/task/css/common.css new file mode 100644 index 0000000000..c8f1cfb54e --- /dev/null +++ b/module/task/css/common.css @@ -0,0 +1 @@ +.text-6{width:75%;} diff --git a/module/task/lang/en.php b/module/task/lang/en.php index c217973252..fc58fb4b11 100644 --- a/module/task/lang/en.php +++ b/module/task/lang/en.php @@ -51,6 +51,7 @@ $lang->task->beforeConsumed = 'Before consumed'; $lang->task->consumedThisTime = 'This time consumed'; $lang->task->estStarted = 'Estimate start'; $lang->task->realStarted = 'Real start'; +$lang->task->date = 'Date'; $lang->task->deadline = 'Deadline'; $lang->task->deadlineAB = 'Deadline'; $lang->task->status = 'Status'; @@ -77,6 +78,8 @@ $lang->task->closedReason = 'Closed Reason'; $lang->task->lastEditedBy = 'Last Edited By'; $lang->task->lastEditedDate = 'Last Edited Date'; $lang->task->lastEdited = 'Last Edited'; +$lang->task->editEstimate = 'Edit estimate'; +$lang->task->deleteEstimate = 'Delete estimate'; $lang->task->ditto = 'Ditto'; @@ -127,16 +130,17 @@ $lang->task->legendLife = 'Lifetime'; $lang->task->legendDesc = 'Desc'; $lang->task->legendAction = 'Action'; -$lang->task->ajaxGetUserTasks = "API:My tasks"; -$lang->task->ajaxGetProjectTasks = "API:Project tasks"; -$lang->task->confirmDelete = "Are you sure you want to delete this task?"; -$lang->task->copyStoryTitle = "Same as story"; -$lang->task->afterSubmit = "After created"; -$lang->task->successSaved = "Successfully saved"; -$lang->task->delayWarning = " Postponed %s days "; -$lang->task->remindBug = "This task from Bug, update the Bug:%s or not?"; -$lang->task->confirmChangeProject = 'Change project will change module, story and assignedTo also, are you sure?'; -$lang->task->confirmFinish = '"Left" is 0, this task will be done. Are you sure?'; +$lang->task->ajaxGetUserTasks = "API:My tasks"; +$lang->task->ajaxGetProjectTasks = "API:Project tasks"; +$lang->task->confirmDelete = "Are you sure you want to delete this task?"; +$lang->task->confirmDeleteEstimate = "Are you sure you want to delete this estimate?"; +$lang->task->copyStoryTitle = "Same as story"; +$lang->task->afterSubmit = "After created"; +$lang->task->successSaved = "Successfully saved"; +$lang->task->delayWarning = " Postponed %s days "; +$lang->task->remindBug = "This task from Bug, update the Bug:%s or not?"; +$lang->task->confirmChangeProject = 'Change project will change module, story and assignedTo also, are you sure?'; +$lang->task->confirmFinish = '"Left" is 0, this task will be done. Are you sure?'; $lang->task->error = new stdclass(); $lang->task->error->consumed = '"Consumed" must be number'; diff --git a/module/task/lang/zh-cn.php b/module/task/lang/zh-cn.php index eea2f30bf0..16b1250753 100644 --- a/module/task/lang/zh-cn.php +++ b/module/task/lang/zh-cn.php @@ -51,6 +51,7 @@ $lang->task->beforeConsumed = '之前消耗'; $lang->task->consumedThisTime = '本次消耗'; $lang->task->estStarted = '预计开始'; $lang->task->realStarted = '实际开始'; +$lang->task->date = '日期'; $lang->task->deadline = '截止日期'; $lang->task->deadlineAB = '截止'; $lang->task->status = '任务状态'; @@ -77,6 +78,8 @@ $lang->task->closedReason = '关闭原因'; $lang->task->lastEditedBy = '最后修改'; $lang->task->lastEditedDate = '最后修改日期'; $lang->task->lastEdited = '最后编辑'; +$lang->task->editEstimate = '编辑工时'; +$lang->task->deleteEstimate = '删除工时'; $lang->task->ditto = '同上'; @@ -127,16 +130,17 @@ $lang->task->legendLife = '任务的一生'; $lang->task->legendDesc = '任务描述'; $lang->task->legendAction = '操作'; -$lang->task->ajaxGetUserTasks = "接口:我的任务"; -$lang->task->ajaxGetProjectTasks = "接口:项目任务"; -$lang->task->confirmDelete = "您确定要删除这个任务吗?"; -$lang->task->copyStoryTitle = "同需求"; -$lang->task->afterSubmit = "添加之后"; -$lang->task->successSaved = "成功添加,"; -$lang->task->delayWarning = " 延期%s天 "; -$lang->task->remindBug = "该任务为Bug转化得到,是否更新Bug:%s ?"; -$lang->task->confirmChangeProject = '修改项目会导致相应的所属模块、相关需求和指派人发生变化,确定吗?'; -$lang->task->confirmFinish = '"预计剩余"为0,确认将任务状态改为"已完成"吗?'; +$lang->task->ajaxGetUserTasks = "接口:我的任务"; +$lang->task->ajaxGetProjectTasks = "接口:项目任务"; +$lang->task->confirmDelete = "您确定要删除这个任务吗?"; +$lang->task->confirmDeleteEstimate = "您确定要删除这个记录吗?"; +$lang->task->copyStoryTitle = "同需求"; +$lang->task->afterSubmit = "添加之后"; +$lang->task->successSaved = "成功添加,"; +$lang->task->delayWarning = " 延期%s天 "; +$lang->task->remindBug = "该任务为Bug转化得到,是否更新Bug:%s ?"; +$lang->task->confirmChangeProject = '修改项目会导致相应的所属模块、相关需求和指派人发生变化,确定吗?'; +$lang->task->confirmFinish = '"预计剩余"为0,确认将任务状态改为"已完成"吗?'; $lang->task->error = new stdclass(); $lang->task->error->consumed = '"已经消耗"必须为数字'; diff --git a/module/task/model.php b/module/task/model.php index d68353e0c1..635a33507d 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -431,26 +431,42 @@ class taskModel extends model */ public function record($taskID) { - $oldTask = $this->getById($taskID); - $estimate = fixer::input('post') - ->setDefault('account', $this->app->user->account) - ->setDefault('task', $taskID) - ->setDefault('date', date(DT_DATE1)) - ->cleanFloat('consumed, left') - ->remove('comment') - ->get(); - $this->dao->insert(TABLE_TASKESTIMATE)->data($estimate) - ->autoCheck() - ->exec(); + $record = fixer::input('post')->get(); + $estimates = array(); + $task = $this->getById($taskID); + foreach(array_keys($record->id) as $id) + { + if($record->dates[$id]) + { + if(!$record->consumed[$id]) die(js::alert('ii')); + $estimates[$id]->date = $record->dates[$id]; + $estimates[$id]->task = $taskID; + $estimates[$id]->consumed = $record->consumed[$id]; + $estimates[$id]->left = $record->left[$id]; + $estimates[$id]->comment = $record->comment[$id]; + } + } + + $consumed = 0; + $left = 0; + foreach($estimates as $estimate) + { + $consumed += $estimate->consumed; + $left = $estimate->left; + $comment = $estimate->comment; + unset($estimate->comment); + $this->dao->insert(TABLE_TASKESTIMATE)->data($estimate) + ->autoCheck() + ->exec(); + $estimateID = $this->dao->lastInsertID(); + $this->loadModel('action')->create('task', $taskID, 'Recorded', $comment, $estimateID); + } - $consumed = $oldTask->consumed + $estimate->consumed; $this->dao->update(TABLE_TASK) - ->set('consumed')->eq($consumed) - ->set('`left`')->eq($estimate->left) + ->set('consumed')->eq($task->consumed + $consumed) + ->set('`left`')->eq($left) ->where('id')->eq($taskID) ->exec(); - $task = $this->getById($taskID); - if(!dao::isError()) return common::createChanges($oldTask, $task); } /** @@ -808,6 +824,103 @@ class taskModel extends model return $taskCounts; } + /** + * Get task estimate. + * + * @param int $taskID + * @access public + * @return object + */ + public function getTaskEstimate($taskID) + { + $estimates = $this->dao->select('*') + ->from(TABLE_TASKESTIMATE) + ->where('task')->eq($taskID) + ->fetchAll(); + $comments = $this->dao->select('extra, comment') + ->from(TABLE_ACTION) + ->where('objectType')->eq('task') + ->andWhere('objectID')->eq($taskID) + ->andWhere('action')->eq('recorded') + ->fetchPairs('extra'); + foreach($estimates as $estimate) + { + $estimate->comment = $comments[$estimate->id]; + } + return $estimates; + } + + /** + * Get estimate by id. + * + * @param int $estimateID + * @access public + * @return object. + */ + public function getEstimateById($estimateID) + { + $estimate = $this->dao->select('*') + ->from(TABLE_TASKESTIMATE) + ->where('id')->eq($estimateID) + ->fetch(); + $comment = $this->dao->select('comment') + ->from(TABLE_ACTION) + ->where('objectType')->eq('task') + ->andWhere('action')->eq('recorded') + ->andWhere('extra')->eq($estimateID) + ->orderBy('id desc') + ->fetch(); + $estimate->comment = $comment->comment; + return $estimate; + } + + /** + * Update estimate. + * + * @param int $estimateID + * @access public + * @return void + */ + public function updateEstimate($estimateID) + { + $oldEstimate = $this->getEstimateById($estimateID); + $estimate = fixer::input('post')->remove('comment')->get(); + $task = $this->getById($oldEstimate->task); + $this->dao->update(TABLE_TASKESTIMATE)->data($estimate) + ->autoCheck() + ->check('consumed', 'notempty') + ->where('id')->eq((int)$estimateID) + ->exec(); + $this->loadModel('action')->create('task', $oldEstimate->task, 'Recorded', $this->post->comment, $estimateID); + $consumed = $task->estimate + $estimate->consumed - $oldEstimate->consumed; + $lastEstimate = $this->dao->select('*')->from(TABLE_TASKESTIMATE)->where('task')->eq($task->id)->orderBy('id desc')->fetch(); + if($lastEstimate and $estimateID == $lastEstimate->id) + { + $left = $estimate->left; + } + else + { + $left = $task->left; + } + $this->dao->update(TABLE_TASK) + ->set('consumed')->eq($consumed) + ->set('`left`')->eq($left) + ->where('id')->eq($task->id) + ->exec(); + } + + /** + * Delete estimate. + * + * @param int $estimateID + * @access public + * @return void + */ + public function deleteEstimate($estimateID) + { + $this->dao->delete()->from(TABLE_TASKESTIMATE)->where('id')->eq($estimateID)->exec(); + } + /** * Batch process tasks. * diff --git a/module/task/view/batchcreate.html.php b/module/task/view/batchcreate.html.php index aaa753ed1f..f686bc109e 100644 --- a/module/task/view/batchcreate.html.php +++ b/module/task/view/batchcreate.html.php @@ -43,7 +43,7 @@ task->priList, $pri, 'class=select-1');?> - + diff --git a/module/task/view/editestimate.html.php b/module/task/view/editestimate.html.php new file mode 100644 index 0000000000..fb38bfca34 --- /dev/null +++ b/module/task/view/editestimate.html.php @@ -0,0 +1,29 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + +
task->editEstimate;?>
task->date;?>date, 'class="select-3 date"');?>
task->consumed;?>consumed, 'class="select-3"');?>
task->left;?>left, 'class="select-3"');?>
comment;?>comment, "class=text-5");?>
+ +
+
+ diff --git a/module/task/view/record.html.php b/module/task/view/record.html.php index 2ea33d1e31..85c72ebdd0 100644 --- a/module/task/view/record.html.php +++ b/module/task/view/record.html.php @@ -11,30 +11,48 @@ */ ?> + task->confirmFinish);?> -
+ - - - - - - - - - - + + + + + + - - - + + + + + + + + + + + + + + + + + + + + - +
name;?>
task->beforeConsumed;?>consumed . ' ' . $lang->task->hour;?>
task->consumedThisTime;?>task->hour;?>
task->left;?>task->hour;?>idAB;?>task->date;?>task->consumed;?>task->left;?>comment;?>actions;?>
comment;?>
id;?>date;?>consumed;?>left;?>comment;?> + id", '', 'list', '', '', '', true); + common::printIcon('task', 'deleteEstimate', "estimateID=$estimate->id", '', 'list', '', 'hiddenwin'); + ?> +
-