示例#1
0
 public function runMilestone(TBGRequest $request)
 {
     if ($request->isPost()) {
         if ($this->getUser()->canManageProject($this->selected_project) || $this->getUser()->canManageProjectReleases($this->selected_project)) {
             try {
                 if (!$request['name']) {
                     throw new Exception($this->getI18n()->__('You must provide a valid milestone name'));
                 }
                 $milestone = new TBGMilestone($request['milestone_id']);
                 $milestone->setName($request['name']);
                 $milestone->setProject($this->selected_project);
                 $milestone->setStarting((bool) $request['is_starting']);
                 $milestone->setScheduled((bool) $request['is_scheduled']);
                 $milestone->setDescription($request['description']);
                 $milestone->setVisibleRoadmap($request['visibility_roadmap']);
                 $milestone->setVisibleIssues($request['visibility_issues']);
                 $milestone->setType($request->getParameter('milestone_type', TBGMilestone::TYPE_REGULAR));
                 if ($request->hasParameter('sch_month') && $request->hasParameter('sch_day') && $request->hasParameter('sch_year')) {
                     $scheduled_date = mktime(23, 59, 59, TBGContext::getRequest()->getParameter('sch_month'), TBGContext::getRequest()->getParameter('sch_day'), TBGContext::getRequest()->getParameter('sch_year'));
                     $milestone->setScheduledDate($scheduled_date);
                 } else {
                     $milestone->setScheduledDate(0);
                 }
                 if ($request->hasParameter('starting_month') && $request->hasParameter('starting_day') && $request->hasParameter('starting_year')) {
                     $starting_date = mktime(0, 0, 1, TBGContext::getRequest()->getParameter('starting_month'), TBGContext::getRequest()->getParameter('starting_day'), TBGContext::getRequest()->getParameter('starting_year'));
                     $milestone->setStartingDate($starting_date);
                 } else {
                     $milestone->setStartingDate(0);
                 }
                 $milestone->save();
                 if ($request['milestone_id']) {
                     $message = TBGContext::getI18n()->__('Milestone updated');
                     $template = 'milestoneboxheader';
                 } else {
                     $message = TBGContext::getI18n()->__('Milestone created');
                     $template = 'milestonebox';
                 }
                 return $this->renderJSON(array('content' => $this->getTemplateHTML($template, array('milestone' => $milestone)), 'milestone_id' => $milestone->getID(), 'milestone_name' => $milestone->getName(), 'available' => $milestone->isVisibleRoadmap(), 'milestone_order' => array_keys($this->selected_project->getMilestonesForRoadmap())));
             } catch (Exception $e) {
                 $this->getResponse()->setHttpStatus(400);
                 return $this->renderJSON(array('error' => $e->getMessage()));
             }
         }
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array("error" => $this->getI18n()->__("You don't have access to modify milestones")));
     }
 }
 /**
  * Add a new sprint type milestone to a project
  *  
  * @param TBGRequest $request
  */
 public function runScrumAddSprint(TBGRequest $request)
 {
     $this->forward403unless($this->_checkProjectPageAccess('project_scrum'));
     if (($sprint_name = $request->getParameter('sprint_name')) && trim($sprint_name) != '') {
         $sprint = new TBGMilestone();
         $sprint->setName($sprint_name);
         $sprint->setType(TBGMilestone::TYPE_SCRUMSPRINT);
         $sprint->setProject($this->selected_project);
         $sprint->setStartingDate(mktime(0, 0, 1, $request->getParameter('starting_month'), $request->getParameter('starting_day'), $request->getParameter('starting_year')));
         $sprint->setScheduledDate(mktime(23, 59, 59, $request->getParameter('scheduled_month'), $request->getParameter('scheduled_day'), $request->getParameter('scheduled_year')));
         $sprint->save();
         return $this->renderJSON(array('failed' => false, 'content' => $this->getTemplateHTML('sprintbox', array('sprint' => $sprint)), 'sprint_id' => $sprint->getID()));
     }
     return $this->renderJSON(array('failed' => true, 'error' => TBGContext::getI18n()->__('Please specify a sprint name')));
 }