コード例 #1
0
ファイル: question.php プロジェクト: JP-Git/moodle
    public function classify_response(array $response) {
        if (empty($response['answer'])) {
            return array($this->id => question_classified_response::no_response());
        }

        if ($this->has_separate_unit_field()) {
            $selectedunit = $response['unit'];
        } else {
            $selectedunit = null;
        }
        list($value, $unit, $multiplier) = $this->ap->apply_units($response['answer'], $selectedunit);
        $ans = $this->get_matching_answer($value, $multiplier);

        $resp = $response['answer'];
        if ($this->has_separate_unit_field()) {
            $resp = $this->ap->add_unit($resp, $unit);
        }

        if (!$ans) {
            return array($this->id => new question_classified_response(0, $resp, 0));
        }

        return array($this->id => new question_classified_response($ans->id,
                $resp,
                $this->apply_unit_penalty($ans->fraction, $ans->unitisright)));
    }
コード例 #2
0
ファイル: question.php プロジェクト: nottmoo/moodle
    public function classify_response(array $response) {
        if (empty($response['answer'])) {
            return array($this->id => question_classified_response::no_response());
        }

        if ($this->unitdisplay == qtype_numerical::UNITSELECT) {
            $selectedunit = $response['unit'];
        } else {
            $selectedunit = null;
        }
        list($value, $unit) = $this->ap->apply_units($response['answer'], $selectedunit);
        $ans = $this->get_matching_answer($value);
        if (!$ans) {
            return array($this->id => question_classified_response::no_response());
        }

        $resp = $response['answer'];
        if ($this->unitdisplay == qtype_numerical::UNITSELECT) {
            $resp = $this->ap->add_unit($resp, $unit);
        }

        return array($this->id => new question_classified_response($ans->id,
                $resp,
                $this->apply_unit_penalty($ans->fraction, $unit)));
    }
コード例 #3
0
 public function check_file_access($qa, $options, $component, $filearea, $args, $forcedownload)
 {
     if ($component == 'question' && $filearea == 'answerfeedback') {
         $currentanswer = $qa->get_last_qt_var('answer');
         if ($this->has_separate_unit_field()) {
             $selectedunit = $qa->get_last_qt_var('unit');
         } else {
             $selectedunit = null;
         }
         list($value, $unit, $multiplier) = $this->ap->apply_units($currentanswer, $selectedunit);
         $answer = $this->get_matching_answer($value, $multiplier);
         $answerid = reset($args);
         // Itemid is answer id.
         return $options->feedback && $answer && $answerid == $answer->id;
     } else {
         if ($component == 'question' && $filearea == 'hint') {
             return $this->check_hint_file_access($qa, $options, $args);
         } else {
             return parent::check_file_access($qa, $options, $component, $filearea, $args, $forcedownload);
         }
     }
 }
 public function test_currency()
 {
     $ap = new qtype_numerical_answer_processor(array('$' => 1, '£' => 1), true, '.', ',');
     $this->assertEqual(array('1234.56', '£', 1), $ap->apply_units('£1,234.56'));
     $this->assertEqual(array('100', '$', 1), $ap->apply_units('$100'));
     $this->assertEqual(array('100', '$', 1), $ap->apply_units('$100.'));
     $this->assertEqual(array('100.00', '$', 1), $ap->apply_units('$100.00'));
     $this->assertEqual(array('100', '', null), $ap->apply_units('100'));
     $this->assertEqual(array('100', 'frog', null), $ap->apply_units('frog 100'));
 }