/** * 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 = CriterionPrioritizationTable::getInstance()->findByResponseId($response->id); /** @var CriterionPrioritization $object */ foreach ($values as $object) { $return[$object->criterion_head_id] = $object->score; } } } return $return; }
public function prepareData() { $percent_sum = 0; $objects = CriterionPrioritizationTable::getInstance()->createQuery('cp')->select('cp.rating_method')->distinct()->leftJoin('cp.Response r')->where('r.decision_id = ?', $this->decision_id)->fetchArray(); foreach ($objects as $object) { if ($object['rating_method'] == 'pairwise comparison') { $analyzeMethod = new PairwiseComparisonCriteriaAnalyze(); } else { $analyzeMethod = new BasicCriteriaAnalyze(); $analyzeMethod->setRatingMethod($object['rating_method']); } $analyzeMethod->setDecisionId($this->decision_id); $analyzeMethod->load(); if ($analyzeMethod->hasData()) { $percent_sum += $analyzeMethod->prepareData(); $this->collection = $analyzeMethod->getCollection(); } } if (count($objects)) { $percent_sum /= count($objects); } $has_data = false; if ($percent_sum) { $has_data = true; // Corrects round $delta = 100 - $percent_sum > 0 ? 0.1 : -0.1; $steps = round(abs(100 - $percent_sum) * 10); for ($i = 0; $i < $steps; $i++) { $this->collection[$i]['value'] += $delta; } } return $has_data; }