/**
  * Grade a specific row
  * 
  * @param qtype_matrix_question     $question
  * @param object                    $row
  * @param array                     $answers
  * @return float 
  */
 public function grade_row($question, $row, $answers)
 {
     $is_row_correct = true;
     foreach ($question->cols as $col) {
         $is_correct = $question->is_correct($row, $col);
         $is_answered = $question->is_answered($answers, $row, $col);
         if ($is_answered != $is_correct) {
             $is_row_correct = false;
             break;
         }
     }
     return $is_row_correct ? 1 : 0;
 }
 /**
  * Grade a specific row
  * 
  * @param qtype_matrix_question     $question
  * @param object                    $row
  * @param array                     $answers
  * @return float 
  */
 public function grade_row($question, $row, $answers)
 {
     $row_score = 0;
     $row_malus = 0;
     foreach ($question->cols as $col) {
         $is_correct = $question->is_correct($row, $col);
         $is_answered = $question->is_answered($answers, $row, $col);
         if ($is_answered) {
             $weight = $question->weight($row, $col);
             $row_score += $weight > 0 ? $weight : 0;
             $row_malus += $weight < 0 ? abs($weight) : 0;
         }
     }
     $row_malus = min(1, $row_malus);
     return $row_score - $row_score * $row_malus;
 }
 /**
  *
  * @param qtype_matrix_question $question
  * @return array 
  */
 protected static function make_answer_multiple_incorrect($question)
 {
     $result = array();
     foreach ($question->rows as $row) {
         $key = $question->key($row, $col = 2);
         $result[$key] = 'on';
         $key = $question->key($row, $col = 3);
         $result[$key] = 'on';
     }
     return $result;
 }