コード例 #1
0
 function validation($data)
 {
     $errors = parent::validation($data, null);
     $colcount = matrix_qtype::count_form_rows_or_cols($data, false);
     $rowcount = matrix_qtype::count_form_rows_or_cols($data);
     if ($rowcount == 0) {
         $errors['rowshort[0]'] = get_string('mustdefine1by1', 'qtype_matrix');
     }
     if ($colcount == 0) {
         $errors['colshort[0]'] = get_string('mustdefine1by1', 'qtype_matrix');
     }
     if (array_key_exists('grademethod', $data)) {
         $grademethod = $data['grademethod'];
     } else {
         $grademethod = matrix_qtype::single_default_grademethod();
     }
     if ($grademethod == QTYPE_MATRIX_GRADING_WEIGHTED && empty($data['multiple'])) {
         $errors['multiple'] = get_string('weightednomultiple', 'qtype_matrix');
     }
     $gradeclass = matrix_qtype::grade_class($grademethod, $data['multiple']);
     $matrixerrors = $gradeclass->validate_defining_form_matrix($data);
     $errors = array_merge($errors, $matrixerrors);
     return $errors ? $errors : true;
 }
コード例 #2
0
 function grade_responses(&$question, &$state, $cmoptions)
 {
     $gradeclass = matrix_qtype::grade_class($question->options->grademethod, $question->options->multiple);
     if ($gradeclass->is_manual_graded()) {
         $state->raw_grade = 0;
         $state->penalty = 0;
         return true;
     }
     $gradeclass->set_weights($question->options->weights);
     $subqs = $gradeclass->grade_matrix($state->responses);
     $state->raw_grade = $gradeclass->grade_question($subqs);
     //
     // Make sure we don't assign negative or too high marks.
     $state->raw_grade = min(max((double) $state->raw_grade, 0.0), 1.0) * $question->maxgrade;
     // Update the penalty.
     $state->penalty = $question->penalty * $question->maxgrade;
     // mark the state as graded
     $state->event = $state->event == QUESTION_EVENTCLOSE ? QUESTION_EVENTCLOSEANDGRADE : QUESTION_EVENTGRADE;
     return true;
 }
コード例 #3
0
 public function validate_defining_form_matrix($data)
 {
     // each row must have the positive weight value adding up to 100
     $matrix = matrix_qtype::formdata_to_matrix($data);
     $errors = array();
     foreach ($matrix as $row) {
         $positivevalue = 0;
         foreach ($row as $cell) {
             if ($cell < 0) {
                 continue;
             }
             $positivevalue += $cell;
         }
         if (ceil($positivevalue) != 1) {
             $errors['gradingmatrix'] = get_string('mustaddupto100', 'qtype_matrix');
         }
     }
     return $errors;
 }