. * * @copyright Copyright 2009-2010 Chunsheng Wang * @author Chunsheng Wang * @package task * @version $Id$ * @link http://www.zentao.cn */ ?> striptags('name') ->specialChars('desc') ->cleanFloat('estimate') ->add('project', (int)$projectID) ->setDefault('estimate, left, story', 0) ->setIF($this->post->estimate != false, 'left', $this->post->estimate) ->setIF($this->post->story != false, 'storyVersion', $this->loadModel('story')->getVersion($this->post->story)) ->setDefault('statusCustom', strpos(self::CUSTOM_STATUS_ORDER, $this->post->status) + 1) ->remove('after') ->get(); $this->dao->insert(TABLE_TASK)->data($task) ->autoCheck() ->check('name', 'notempty') ->checkIF($task->estimate != '', 'estimate', 'float') ->exec(); if($this->post->story) $this->loadModel('story')->setStage($this->post->story); if(!dao::isError()) return $this->dao->lastInsertID(); } /* 更新一个任务。*/ public function update($taskID) { $oldTask = $this->getById($taskID); $task = fixer::input('post') ->striptags('name') ->specialChars('desc') ->cleanFloat('estimate, left, consumed') ->setDefault('story, estimate, left, consumed', 0) ->setIF($this->post->story != false and $this->post->story != $oldTask->story, 'storyVersion', $this->loadModel('story')->getVersion($this->post->story)) ->setIF($this->post->status == 'done', 'left', 0) ->setDefault('statusCustom', strpos(self::CUSTOM_STATUS_ORDER, $this->post->status) + 1) ->remove('comment') ->get(); $this->dao->update(TABLE_TASK)->data($task) ->autoCheck() ->check('name', 'notempty') ->checkIF($task->estimate != false, 'estimate', 'float') ->checkIF($task->left != false, 'left', 'float') ->checkIF($task->consumed != false, 'consumed', 'float') ->where('id')->eq((int)$taskID)->exec(); if($this->post->story != false) $this->loadModel('story')->setStage($this->post->story); if(!dao::isError()) return common::createChanges($oldTask, $task); } /* 删除一个任务。*/ public function delete($taskID) { $story = $this->dao->select('*')->from(TABLE_TASK)->where('id')->eq($taskID)->fetch('story'); $this->dao->delete()->from(TABLE_TASK)->where('id')->eq((int)$taskID)->limit(1)->exec(); if($story) $this->loadModel('story')->setStage($story); return; } /* 通过id获取一个任务信息。*/ public function getById($taskID) { return $this->dao->select('t1.*, t2.id AS storyID, t2.title AS storyTitle, 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') ->where('t1.id')->eq((int)$taskID) ->fetch(); } /* 获得某一个项目的任务列表。*/ public function getProjectTasks($projectID, $orderBy = 'status|asc, id|desc', $pager = null) { $orderBy = str_replace('status', 'statusCustom', $orderBy); return $this->dao->select('t1.*, t2.id AS storyID, t2.title AS storyTitle, 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') ->where('t1.project')->eq((int)$projectID) ->orderBy($orderBy) ->page($pager) ->fetchAll(); } /* 获得某一个项目的任务id=>name列表。*/ public function getProjectTaskPairs($projectID, $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') ->where('t1.project')->eq((int)$projectID) ->orderBy($orderBy) ->query(); while($task = $stmt->fetch()) $tasks[$task->id] = "$task->id:$task->ownerRealName:$task->name"; return $tasks; } /* 获得用户的任务列表。*/ public function getUserTasks($account, $status = 'all') { $sql = $this->dao->select('t1.*, t2.id as projectID, t2.name as projectName, t3.id as storyID, t3.title as storyTitle') ->from(TABLE_TASK)->alias('t1') ->leftjoin(TABLE_PROJECT)->alias('t2') ->on('t1.project = t2.id') ->leftjoin(TABLE_STORY)->alias('t3') ->on('t1.story = t3.id') ->where('t1.owner')->eq($account); if($status != 'all') $sql->andwhere('t1.status')->in($status); return $sql->fetchAll(); } /* 获得用户的任务id=>name列表。*/ 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') ->where('t1.owner')->eq($account); if($status != 'all') $sql->andwhere('t1.status')->in($status); $stmt = $sql->query(); while($task = $stmt->fetch()) { $tasks[$task->id] = $task->project . ' / ' . $task->name; } return $tasks; } /* 获得story对应的task id=>name列表。*/ public function getStoryTaskPairs($storyID, $projectID = 0) { $sql = $this->dao->select('id, name') ->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; } }