Exemplo n.º 1
0
 /**
  * @param sfWebRequest $request
  * @return sfView
  */
 public function executeSave(sfWebRequest $request)
 {
     $this->forward404Unless($request->isXmlHttpRequest());
     $measurement = $request->getParameter('measurement');
     $decision_id = $request->getParameter('decision_id');
     $user = $this->getUser()->getGuardUser();
     $keys = array_keys($measurement);
     $alternative_id = array_shift($keys);
     $keys = array_keys($measurement[$alternative_id]);
     $criterion_id = array_shift($keys);
     $value = $measurement[$alternative_id][$criterion_id];
     $alternativeMeasurement = AlternativeMeasurementTable::getInstance()->getOneForDashboard($user, $decision_id, $alternative_id, $criterion_id);
     if (is_object($alternativeMeasurement)) {
         $alternativeMeasurement->score = $value;
         $alternativeMeasurement->save();
     } else {
         $response = ResponseTable::getInstance()->getOneForDashboard($user, $decision_id);
         if (is_object($response)) {
             $alternativeMeasurement = new AlternativeMeasurement();
             $alternativeMeasurement->score = $value;
             $alternativeMeasurement->alternative_head_id = $alternative_id;
             $alternativeMeasurement->criterion_id = $criterion_id;
             $alternativeMeasurement->Response = $response;
             $alternativeMeasurement->save();
         }
     }
     Doctrine_Query::create()->delete()->from('Graph')->where('decision_id = ?', $decision_id)->execute();
     $criteriaAnalyze = new CriteriaAnalyze();
     $criteriaAnalyze->setDecisionId($decision_id);
     $criteriaAnalyze->load();
     $stackedBarChart = new StackedBarChart();
     $stackedBarChart->setDecisionId($decision_id);
     $stackedBarChart->setCriteriaValues($criteriaAnalyze->getCriteriaValues());
     $stackedBarChart->load();
     $costAnalyze = new CostAnalyze();
     $costAnalyze->setDecisionId($decision_id);
     $costAnalyze->setSortedAlternativeIds($stackedBarChart->getSortedAlternativeIds());
     $costAnalyze->setCumulativeData($stackedBarChart->getCumulativeData());
     $costAnalyze->load();
     $cumulativeChart = new CumulativeGainChart();
     $cumulativeChart->setDecisionId($decision_id);
     $cumulativeChart->setSortedAlternativeIds($stackedBarChart->getSortedAlternativeIds());
     $cumulativeChart->setMeasurement($stackedBarChart->getCumulativeData());
     $cumulativeChart->setCostData($costAnalyze->getData());
     $cumulativeChart->setAlternativeNames($costAnalyze->getAlternativeNames());
     $cumulativeChart->setCriterionNames($costAnalyze->getCriteria());
     $cumulativeChart->load();
     $stacked_bar_chart[] = '"data":' . $stackedBarChart->getJsonData();
     $stacked_bar_chart[] = '"alternatives":' . $stackedBarChart->getAlternativesJson();
     $stacked_bar_chart[] = '"criteria":' . $stackedBarChart->getCriteriaJson();
     $cumulative_chart[] = '"costData":' . $cumulativeChart->getJsonCostData();
     $cumulative_chart[] = '"benefitData":' . $cumulativeChart->getJsonData();
     $cumulative_chart[] = '"criteria":' . json_encode($costAnalyze->getCriteria());
     $cumulative_chart[] = '"alternatives":' . $cumulativeChart->getAlternativesJson();
     $response = array();
     $response[] = '"cumulativeChart":{' . implode(',', $cumulative_chart) . '}';
     $response[] = '"stackedBarChart":{' . implode(',', $stacked_bar_chart) . '}';
     $this->getResponse()->setHttpHeader('Content-Type', 'application/json; charset=utf-8');
     return $this->renderText('{' . implode(',', $response) . '}');
 }
Exemplo n.º 2
0
 public function load(sfGuardUser $user, $decision_id)
 {
     $this->criteria = CriterionTable::getInstance()->getArrayForUser($user, $decision_id);
     $alternatives = AlternativeTable::getInstance()->getArrayForUser($user, $decision_id);
     $values = AlternativeMeasurementTable::getInstance()->getForDashboard($user, $decision_id);
     foreach ($alternatives as $alternative) {
         $this->body[$alternative['id']][0] = $alternative['name'];
         foreach ($this->criteria as $criterion) {
             $cell = new stdClass();
             $cell->measurement = str_replace(' ', '_', $criterion['measurement']);
             $cell->value = isset($values[$alternative['id']][$criterion['id']]) ? $values[$alternative['id']][$criterion['id']] : null;
             $this->body[$alternative['id']][$criterion['id']] = $cell;
         }
     }
 }
Exemplo n.º 3
0
 public function save()
 {
     foreach ($this->values as $criterion_id => $alternatives) {
         foreach ($alternatives as $alternative_id => $score) {
             if ($this->role->updateable) {
                 $alternativeMeasurement = AlternativeMeasurementTable::getInstance()->getOneForSave($this->response_id, $alternative_id, $criterion_id);
                 if (!$alternativeMeasurement) {
                     $alternativeMeasurement = new AlternativeMeasurement();
                 }
             } else {
                 $alternativeMeasurement = new AlternativeMeasurement();
             }
             $alternativeMeasurement->alternative_head_id = $alternative_id;
             $alternativeMeasurement->criterion_id = $criterion_id;
             $alternativeMeasurement->rating_method = 'five point scale';
             $alternativeMeasurement->response_id = $this->response_id;
             $alternativeMeasurement->score = $score;
             $alternativeMeasurement->save();
         }
     }
 }
 /**
  * Return the values from the database or empty array
  */
 public function getValues()
 {
     $return = array();
     if ($this->role and $this->role->Response->count() and $this->role->updateable and !$this->role->anonymous) {
         $context = sfContext::getInstance();
         $user = $context->getUser();
         // find response by user_id
         if ($user->isAuthenticated()) {
             $response = ResponseTable::getInstance()->findByRoleIdAndUserId($this->role->id, $user->getGuardUser()->id)->getFirst();
         } else {
             $email = $user->getAttribute('email_address', null, 'measurement/email/' . $this->role->id);
             $response = ResponseTable::getInstance()->findByRoleIdAndEmailAddress($this->role->id, $email)->getFirst();
         }
         if ($response instanceof Response) {
             $values = AlternativeMeasurementTable::getInstance()->findByResponseIdAndCriterionId($response->id, $this->criterion_id);
             /** @var CriterionPrioritization $object */
             foreach ($values as $object) {
                 $return[$object->alternative_head_id] = $object->score;
             }
         }
     }
     return $return;
 }