예제 #1
0
 /**
  * @param sfWebRequest $request
  * @return string
  */
 public function executeDecisionModalSave(sfWebRequest $request)
 {
     $decision_id = $this->getUser()->getAttribute('decision_id', null, 'sfGuardSecurityUser');
     if (!empty($decision_id)) {
         $decision = DecisionTable::getInstance()->getDecisionForUser($this->getUser()->getGuardUser(), $decision_id);
     }
     if (empty($decision) || !is_object($decision)) {
         if (!DecisionTable::getInstance()->verifyAvailableName($this->getUser()->getGuardUser(), $request->getParameter('name'))) {
             return $this->renderText(json_encode(array('status' => 'error', 'message' => 'A project with that name already exists')));
         }
         $decision = new Decision();
         $folder = FolderTable::getInstance()->getNotDeletableForUser($this->getUser()->getGuardUser(), Folder::TYPE_PROJECT);
         if (!empty($folder)) {
             $decision->setFolderId($folder->getId());
         }
         // Create log
         $log = new Log();
         $log->setAction('project_create');
         $log->setUserId($this->getUser()->getGuardUser()->id);
         $log->setInformation(json_encode(array('decision_name' => $request->getParameter('name'), 'decision_type' => $request->getParameter('type_id'), 'decision_template' => $request->getParameter('template_id'))));
         $log->save();
     }
     $decision->setName($request->getParameter('name', ''));
     $decision->setTypeId($request->getParameter('type_id'));
     $decision->setTemplateId($request->getParameter('template_id'));
     $decision->save();
     $this->getUser()->setAttribute('decision_id', $decision->getId(), 'sfGuardSecurityUser');
     return $this->renderText(json_encode(array('status' => 'success', 'dashboard_url' => $this->generateUrl('dashboard', array('decision_id' => $decision->getId())))));
 }
예제 #2
0
 /**
  * @param sfWebRequest $request
  * @return sfView
  */
 public function executeImportFromTrello(sfWebRequest $request)
 {
     $this->forward404Unless($request->isXmlHttpRequest());
     if (!DecisionTable::getInstance()->verifyAvailableName($this->getUser()->getGuardUser(), $request->getParameter('board_name'))) {
         return $this->renderText(json_encode(array('status' => 'error', 'message' => 'A project with that name already exists')));
     }
     $decision = new Decision();
     $decision->setName($request->getParameter('board_name'));
     $decision->setUserId($this->getUser()->getGuardUser()->getId());
     $decision->setExternalId($request->getParameter('board_id'));
     $decision->setTypeId(2);
     $type_template = TypeTemplate::getInstance()->createQuery('t')->where('t.user_id is NULL')->andWhere('t.type_id = ?', 2)->andWhere('t.name = ?', 'Default')->fetchOne();
     $decision->setTemplateId($type_template->getId());
     // Default template
     $decision->setFolderId(FolderTable::getInstance()->getNotDeletableForUser($this->getUser()->getGuardUser(), Folder::TYPE_PROJECT)->getId());
     $decision->save();
     $dashboard_role = $decision->getDashboardRole();
     foreach (json_decode($request->getParameter('cards', '{}')) as $card) {
         $alternative = new Alternative();
         $alternative->setName($card->name);
         $alternative->setDecisionId($decision->getId());
         $alternative->setAdditionalInfo($card->desc);
         $alternative->setNotes($card->notes);
         $alternative->setExternalId($card->id);
         $alternative->setCreatedBy($request->getParameter('full_name') . ' (via Trello)');
         $alternative->setUpdatedBy($request->getParameter('full_name') . ' (via Trello)');
         if ($card->due) {
             $date = DateTime::createFromFormat('Y-m-d\\TH:i:s.000Z', $card->due);
             $alternative->setDueDate($date->format('Y-m-d H:i:s'));
             $alternative->setNotifyDate($date->format('Y-m-d H:i:s'));
         }
         $alternative->save();
         foreach ($card->labels as $label) {
             Tag::newTag($this->getUser()->getGuardUser(), $alternative->getId(), $label, 'alternative');
         }
         if ($dashboard_role) {
             foreach ($decision->getCriterion() as $criterion) {
                 $planned_alternative_measurement = new PlannedAlternativeMeasurement();
                 $planned_alternative_measurement->setAlternative($alternative);
                 $planned_alternative_measurement->setCriterion($criterion);
                 $dashboard_role->PlannedAlternativeMeasurement->add($planned_alternative_measurement);
             }
         }
     }
     $dashboard_role->PlannedAlternativeMeasurement->save();
     if ($request->getParameter('wizard')) {
         $user = $this->getUser()->getGuardUser();
         $user->setWizard(false);
         $user->save();
     }
     // Create log
     $log = new Log();
     $log->setAction('project_create');
     $log->setUserId($this->getUser()->getGuardUser()->id);
     $log->setInformation(json_encode(array('decision_name' => $decision->getName(), 'decision_type' => $decision->getTypeId(), 'decision_template' => $decision->getTemplateId(), 'imported' => 'Trello')));
     $log->save();
     return $this->renderText(json_encode(array('status' => 'success', 'dashboard_url' => $this->generateUrl('dashboard', array('decision_id' => $decision->getId())))));
 }