Ejemplo n.º 1
0
 public function advancedImport()
 {
     foreach ($this->prepareData() as $item) {
         $alternative = null;
         if (array_key_exists('id', $item) && !empty($item['id'])) {
             $alternative = AlternativeTable::getInstance()->createQuery('a')->leftJoin('a.Decision d')->leftJoin('d.User u')->leftJoin('u.TeamMember tm')->whereIn('d.user_id', sfGuardUserTable::getInstance()->getUsersInTeamIDs($this->guard_user))->andWhere('a.item_id = ?', $item['id'])->andWhere('d.id = ?', $this->decision->getId())->fetchOne();
         }
         if (!is_object($alternative)) {
             $alternative = new Alternative();
             $alternative->setDecision($this->decision);
             $alternative->setCreatedBy($this->created_and_updated_by);
             $alternative->setUpdatedBy($this->created_and_updated_by);
         }
         $alternative->setName($item['name']);
         foreach (array('status', 'work progress', 'additional info', 'notes', 'due date', 'notify date') as $prop) {
             if (array_key_exists($prop, $item) && !empty($item[$prop])) {
                 $alternative->{str_replace(' ', '_', $prop)} = $item[$prop];
             }
         }
         if (array_key_exists('tags', $item)) {
             // Process tags
             $tags_request = array_map('trim', explode(',', $item['tags']));
             $tags = array();
             foreach ($alternative->getTagAlternative() as $tag) {
                 $tags[] = $tag->Tag->name;
             }
             foreach (array_diff($tags_request, $tags) as $result) {
                 Tag::newTag($this->guard_user, $alternative->getId(), $result, 'alternative');
             }
             foreach (array_diff($tags, $tags_request) as $result) {
                 Tag::removeTag($this->guard_user, $alternative->getId(), $result, 'alternative');
             }
         }
         $alternative->save();
     }
 }
Ejemplo n.º 2
0
 public function createDashboard()
 {
     $role = new Role();
     $role->setDecisionId($this->id);
     $role->setName('Collect everything');
     $role->setComment('Collect everything is linked to the Overview -page reporting table. <br><br>If you delete this survey your responses on the overview page will be removed.');
     $role->setUpdateable(true);
     $role->setDashboard(true);
     $role->setActive(true);
     $response = new Response();
     $response->setDecisionId($this->id);
     $response->setIpAddress('127.0.0.1');
     $response->setEmailAddress('dashboard');
     $role->Response->add($response);
     $role->Response->save();
     if ($this->Template->name == 'Default') {
         $role_estimates = new Role();
         $role_estimates->setDecisionId($this->id);
         $role_estimates->setName('Collect Estimates');
         $role_estimates->setUpdateable(false);
         $role_estimates->setActive(true);
         $role_estimates->save();
         $role_value = new Role();
         $role_value->setDecisionId($this->id);
         $role_value->setName('Collect input on Value');
         $role_value->setUpdateable(false);
         $role_value->setActive(true);
         $role_value->save();
         $role_usability = new Role();
         $role_usability->setDecisionId($this->id);
         $role_usability->setName('Collect input on Usability');
         $role_usability->setUpdateable(false);
         $role_usability->setActive(true);
         $role_usability->save();
         $role_feasibility = new Role();
         $role_feasibility->setDecisionId($this->id);
         $role_feasibility->setName('Collect input on Feasibility');
         $role_feasibility->setUpdateable(false);
         $role_feasibility->setActive(true);
         $role_feasibility->save();
         // create the default item for project
         $alternative = new Alternative();
         $alternative->setDecisionId($this->id);
         $alternative->setName('Sample item');
         $alternative->setStatus('Reviewed');
         $alternative->save();
         $popularCriteria = PopularCriterionTable::getInstance()->getDashboardDefaultList();
         foreach ($popularCriteria as $popularCriterion) {
             $criterion = new Criterion();
             $criterion->setName($popularCriterion->name);
             $criterion->setMeasurement($popularCriterion->measurement);
             $criterion->setDescription($popularCriterion->description);
             $criterion->setVariableType($popularCriterion->variable_type);
             $criterion->setDecisionId($this->id);
             $criterion->save();
             // set default response as 3 for default item
             if ($popularCriterion->measurement == 'five point scale') {
                 $alternative_measurement = new AlternativeMeasurement();
                 $alternative_measurement->setAlternativeHeadId($alternative->id);
                 $alternative_measurement->setScore(3);
                 $alternative_measurement->setResponseId($response->id);
                 $alternative_measurement->setRatingMethod($criterion->getMeasurement());
                 $alternative_measurement->setCriterionId($criterion->id);
                 $alternative_measurement->save();
             }
             // show by default in the Survey (create default matrix of the default roles)
             $array = array('Hour Estimate' => $role_estimates->id, 'Feasibility' => $role_feasibility->id, 'Usability' => $role_usability->id, 'Value' => $role_value->id);
             if (isset($array[$popularCriterion->name])) {
                 $planned = new PlannedAlternativeMeasurement();
                 $planned->setRoleId($array[$popularCriterion->name]);
                 $planned->setAlternativeId($alternative->id);
                 $planned->setCriterionId($criterion->id);
                 $planned->save();
                 $cplanned = new PlannedCriterionPrioritization();
                 $cplanned->setCriterionId($criterion->id);
                 $cplanned->setRoleId($array[$popularCriterion->name]);
                 $cplanned->save();
             }
         }
     } else {
         foreach ($this->Template->CriteriaTemplate as $criterionTemplate) {
             $criterion = new Criterion();
             $criterion->setDecisionId($this->id);
             $criterion->setName($criterionTemplate->name);
             $criterion->setMeasurement($criterionTemplate->measurement);
             $criterion->setVariableType($criterionTemplate->variable_type);
             $criterion->save();
         }
         foreach ($this->Template->RoleTemplate as $roleTemplate) {
             $role = new Role();
             $role->setDecisionId($this->id);
             $role->setName($roleTemplate->name);
             $role->save();
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * @param sfWebRequest $request
  * @return string
  */
 public function executeAlternativeModalSave(sfWebRequest $request)
 {
     $this->forward404Unless($request->isXmlHttpRequest());
     $decision_id = $this->getUser()->getAttribute('decision_id', null, 'sfGuardSecurityUser');
     if (!empty($decision_id)) {
         $this->decision = DecisionTable::getInstance()->getDecisionForUser($this->getUser()->getGuardUser(), $decision_id);
         $this->forward404Unless(is_object($this->decision));
     } else {
         $this->forward404();
     }
     $alternative = new Alternative();
     $alternative->setName($request->getParameter('name'));
     $alternative->setDecision($this->decision);
     $alternative->setCreatedBy(Alternative::generateUpdateAndCreatedBy($this->getUser()->getGuardUser()));
     $alternative->setUpdatedBy(Alternative::generateUpdateAndCreatedBy($this->getUser()->getGuardUser()));
     $alternative->save();
     $dashboard_role = $this->decision->getDashboardRole();
     if ($dashboard_role) {
         foreach ($this->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();
     }
     $additional_roles = Doctrine_Query::create()->from('Role r')->leftJoin('r.Decision d')->where('d.id = ?', $this->decision->getId())->andWhere('d.user_id = ?', $this->getUser()->getGuardUser()->id)->execute();
     $criterion_estimates = Doctrine_Query::create()->from('Criterion c')->leftJoin('c.Decision d')->where('d.id = ?', $this->decision->getId())->andWhere('d.user_id = ?', $this->getUser()->getGuardUser()->id)->andWhere('c.name = ?', 'Hour Estimate')->fetchOne();
     $criterion_value = Doctrine_Query::create()->from('Criterion c')->leftJoin('c.Decision d')->where('d.id = ?', $this->decision->getId())->andWhere('d.user_id = ?', $this->getUser()->getGuardUser()->id)->andWhere('c.name = ?', 'Value')->fetchOne();
     $criterion_usability = Doctrine_Query::create()->from('Criterion c')->leftJoin('c.Decision d')->where('d.id = ?', $this->decision->getId())->andWhere('d.user_id = ?', $this->getUser()->getGuardUser()->id)->andWhere('c.name = ?', 'Usability')->fetchOne();
     $criterion_feasibility = Doctrine_Query::create()->from('Criterion c')->leftJoin('c.Decision d')->where('d.id = ?', $this->decision->getId())->andWhere('d.user_id = ?', $this->getUser()->getGuardUser()->id)->andWhere('c.name = ?', 'Feasibility')->fetchOne();
     foreach ($additional_roles as $additional_role) {
         if ($additional_role->getName() == 'Collect Estimates' && $criterion_estimates) {
             $planned_alternative_measurement = new PlannedAlternativeMeasurement();
             $planned_alternative_measurement->setAlternative($alternative);
             $planned_alternative_measurement->setCriterion($criterion_estimates);
             $planned_alternative_measurement->setRole($additional_role);
             $planned_alternative_measurement->save();
         } elseif ($additional_role->getName() == 'Collect input on Value' && $criterion_value) {
             $planned_alternative_measurement = new PlannedAlternativeMeasurement();
             $planned_alternative_measurement->setAlternative($alternative);
             $planned_alternative_measurement->setCriterion($criterion_value);
             $planned_alternative_measurement->setRole($additional_role);
             $planned_alternative_measurement->save();
         } elseif ($additional_role->getName() == 'Collect input on Usability' && $criterion_usability) {
             $planned_alternative_measurement = new PlannedAlternativeMeasurement();
             $planned_alternative_measurement->setAlternative($alternative);
             $planned_alternative_measurement->setCriterion($criterion_usability);
             $planned_alternative_measurement->setRole($additional_role);
             $planned_alternative_measurement->save();
         } elseif ($additional_role->getName() == 'Collect input on Feasibility' && $criterion_feasibility) {
             $planned_alternative_measurement = new PlannedAlternativeMeasurement();
             $planned_alternative_measurement->setAlternative($alternative);
             $planned_alternative_measurement->setCriterion($criterion_feasibility);
             $planned_alternative_measurement->setRole($additional_role);
             $planned_alternative_measurement->save();
         }
     }
     // Create log
     $log = new Log();
     $log->injectDataAndPersist($alternative, $this->getUser()->getGuardUser(), array('action' => 'new'));
     return sfView::NONE;
 }
Ejemplo n.º 4
0
 /**
  * @param sfWebRequest $request
  * @return sfView
  */
 public function executeImportFromCustomFields(sfWebRequest $request)
 {
     $decision_id = $request->getParameter('decision_id', false);
     $decision = DecisionTable::getInstance()->getDecisionForUser($this->getUser()->getGuardUser(), $decision_id);
     $this->forward404Unless(is_object($decision));
     $header = $request->getParameter('header');
     $data = $request->getParameter('data');
     if (array_search('name', $header) === false) {
         return $this->renderText(json_encode(array('status' => 'error', 'text' => 'Please ensure that data field "Name" is mapped to a column in your SpreadSheet.')));
     }
     foreach ($data as $item) {
         $alternative = null;
         if (array_key_exists('id', $item) && !empty($item['id'])) {
             $alternative = AlternativeTable::getInstance()->createQuery('a')->leftJoin('a.Decision d')->leftJoin('d.User u')->leftJoin('u.TeamMember tm')->whereIn('d.user_id', sfGuardUserTable::getInstance()->getUsersInTeamIDs($this->getUser()->getGuardUser()))->andWhere('a.item_id = ?', $item['id'])->andWhere('d.id = ?', $decision->getId())->fetchOne();
         }
         if (!is_object($alternative)) {
             $alternative = new Alternative();
             $alternative->setDecision($decision);
             $alternative->setCreatedBy(Alternative::generateUpdateAndCreatedBy($this->getUser()->getGuardUser()));
             $alternative->setUpdatedBy(Alternative::generateUpdateAndCreatedBy($this->getUser()->getGuardUser()));
         }
         $custom_fields = array();
         foreach ($item as $prop => $value) {
             if (array_key_exists($prop, $header)) {
                 if ($header[$prop] == '_new') {
                     $custom_fields[$prop] = $value;
                 } elseif (!in_array($header[$prop], array('id')) && in_array($header[$prop], array('name', 'status', 'work progress', 'additional info', 'notes', 'due date', 'notify date', 'tags'))) {
                     if ($header[$prop] == 'tags') {
                         // Process tags
                         $tags_request = array_map('trim', explode(',', $value));
                         $tags = array();
                         foreach ($alternative->getTagAlternative() as $tag) {
                             $tags[] = $tag->Tag->name;
                         }
                         foreach (array_diff($tags_request, $tags) as $result) {
                             Tag::newTag($this->getUser()->getGuardUser(), $alternative->getId(), $result, 'alternative');
                         }
                         foreach (array_diff($tags, $tags_request) as $result) {
                             Tag::removeTag($this->getUser()->getGuardUser(), $alternative->getId(), $result, 'alternative');
                         }
                     } else {
                         $alternative->{str_replace(' ', '_', $header[$prop])} = $value;
                     }
                 }
             }
         }
         if ($custom_fields) {
             $alternative->setCustomFields(json_encode($custom_fields));
         }
         if (!$alternative->getName()) {
             $alternative->setName('New ' . InterfaceLabelTable::getInstance()->get($this->getUser()->getGuardUser(), InterfaceLabelTable::ITEM_TYPE));
         }
         $alternative->save();
     }
     return $this->renderText(json_encode(array('status' => 'success')));
 }
Ejemplo n.º 5
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())))));
 }