Ejemplo n.º 1
0
 /**
  * @param sfWebRequest $request
  * @return sfView
  * @throws Doctrine_Collection_Exception
  * @throws sfError404Exception
  */
 public function executeImportFromTrello(sfWebRequest $request)
 {
     $decision_id = $request->getParameter('decision_id', false);
     $decision = DecisionTable::getInstance()->getDecisionForUser($this->getUser()->getGuardUser(), $decision_id);
     $this->forward404Unless(is_object($decision));
     $decision->setExternalId($request->getParameter('board_id'));
     $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();
     return $this->renderText(json_encode(array('status' => 'success')));
 }
Ejemplo n.º 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())))));
 }