예제 #1
0
 /**
  * Add a task to a scrum user story
  *
  * @param TBGRequest $request
  */
 public function runScrumAddTask(TBGRequest $request)
 {
     $this->forward403if(TBGContext::getCurrentProject()->isArchived());
     $this->forward403unless($this->_checkProjectPageAccess('project_scrum'));
     $issue = TBGContext::factory()->TBGIssue($request['story_id']);
     try {
         if ($issue instanceof TBGIssue) {
             $this->forward403unless($issue->canAddRelatedIssues());
             $task = new TBGIssue();
             $task->setTitle($request['task_name']);
             $task->setIssuetype(TBGIssuetype::getTask()->getID());
             $task->setProject($issue->getProjectID());
             $task->setMilestone($issue->getMilestone() instanceof TBGMilestone ? $issue->getMilestone()->getID() : null);
             $task->save();
             $comment = $issue->addChildIssue($task);
             $mode = $request->getParameter('mode', 'scrum');
             if ($mode == 'scrum') {
                 return $this->renderJSON(array('failed' => false, 'content' => $this->getTemplateHTML('project/scrumstorytask', array('task' => $task)), 'count' => count($issue->getChildIssues())));
             } elseif ($mode == 'sprint') {
                 return $this->renderJSON(array('failed' => false, 'content' => $this->getTemplateHTML('project/scrumsprintdetailstask', array('task' => $task, 'can_estimate' => $issue->canEditEstimatedTime())), 'count' => count($issue->getChildIssues())));
             } else {
                 return $this->renderJSON(array('failed' => false, 'content' => $this->getTemplateHTML('main/relatedissue', array('issue' => $task)), 'comment' => $comment instanceof TBGComment ? $this->getTemplateHTML('main/comment', array('comment' => $comment, 'theIssue' => $issue)) : false, 'message' => TBGContext::getI18n()->__('The task was added')));
             }
         }
         return $this->renderJSON(array('failed' => true, 'error' => TBGContext::getI18n()->__('Invalid user story')));
     } catch (Exception $e) {
         return $this->renderJSON(array('failed' => true, 'error' => TBGContext::getI18n()->__("An error occured while trying to create a new task: %exception_message", array('%exception_message' => $e->getMessage()))));
     }
 }