diff --git a/edit_oumatrix_form.php b/edit_oumatrix_form.php index 2bd0365..f1d795a 100644 --- a/edit_oumatrix_form.php +++ b/edit_oumatrix_form.php @@ -233,7 +233,6 @@ private function data_preprocessing_rows($question) { $question->feedback[] = $feedback[$key]; $key++; } - $question->feedback = $feedback; return $question; } @@ -353,7 +352,8 @@ protected function get_per_row_fields(MoodleQuickForm $mform, string $label, arr $rowanswerlistlabel = ($this->inputtype === 'single') ? get_string('correctanswer', 'qtype_oumatrix') : get_string('correctanswers', 'qtype_oumatrix'); - // TODO: To find a better way tio display $rowanswerlistlabel string after the rowname. + $rowoptions[] = $mform->createElement('html', + html_writer::tag('div', $rowanswerlistlabel, ['class' => 'rowanswerlistlabel'])); // Get the list answer input type (radio buttons or checkboxes). for ($i = 0; $i < $this->numcolumns; $i++) { @@ -365,7 +365,6 @@ protected function get_per_row_fields(MoodleQuickForm $mform, string $label, arr $rowoptions[] = $mform->createElement('checkbox', "rowanswers$columnvalue", '', $anslabel); } } - //$rowoptions[] = $mform->createElement('group', 'rowanswerlist', $rowanswerlistlabel, $rowanswerlist, null, false); $repeated[] = $mform->createElement('group', 'rowoptions', $label, $rowoptions, null, false); $repeated[] = $mform->createElement('editor', 'feedback', get_string('feedback', 'question'), ['rows' => 2], $this->editoroptions); diff --git a/question.php b/question.php index 6746781..9996316 100644 --- a/question.php +++ b/question.php @@ -86,7 +86,37 @@ protected function init_roworder(question_attempt $qa) { public abstract function is_choice_selected($response, $rowkey, $colkey); public function check_file_access($qa, $options, $component, $filearea, $args, $forcedownload) { - return parent::check_file_access($qa, $options, $component, $filearea, $args, $forcedownload); + //return parent::check_file_access($qa, $options, $component, $filearea, $args, $forcedownload); + if ($component == 'question' && in_array($filearea, + array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback'))) { + return $this->check_combined_feedback_file_access($qa, $options, $filearea, $args); + } else if ($component == 'qtype_oumatrix' && $filearea == 'feedback') { + $responseid = reset($args); // Itemid is answer id. + $response = $qa->get_last_qt_data(); + $isselected = false; + foreach ($this->roworder as $value => $rowid) { + + if ($this->inputtype == 'single' && $rowid == $responseid) { + $isselected = true; + break; + } + } + // Param $options->suppresschoicefeedback is a hack specific to the + // oumultiresponse question type. It would be good to refactor to + // avoid refering to it here. + return $options->feedback && empty($options->suppresschoicefeedback) && + $isselected; + //return $options->feedback; + + } 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 is_same_response(array $prevresponse, array $newresponse): bool { @@ -277,8 +307,18 @@ public function check_file_access($qa, $options, $component, $filearea, $args, $ return parent::check_file_access($qa, $options, $component, $filearea, $args, $forcedownload); } + public function prepare_simulated_post_data($simulatedresponse) { + return $simulatedresponse; + } + public function is_same_response(array $prevresponse, array $newresponse): bool { - return parent::is_same_response($prevresponse, $newresponse); + foreach ($this->roworder as $key => $notused) { + $fieldname = $this->field($key); + if (!question_utils::arrays_same_at_key_missing_is_blank($prevresponse, $newresponse, $fieldname)) { + return false; + } + } + return true; } /** @@ -492,33 +532,21 @@ protected function field(int $rowkey, int $columnkey): string { public function prepare_simulated_post_data($simulatedresponse) { return $simulatedresponse; } - - public function check_file_access($qa, $options, $component, $filearea, $args, $forcedownload) { - return parent::check_file_access($qa, $options, $component, $filearea, $args, $forcedownload); - } + // + //public function check_file_access($qa, $options, $component, $filearea, $args, $forcedownload) { + // return parent::check_file_access($qa, $options, $component, $filearea, $args, $forcedownload); + //} public function is_same_response(array $prevresponse, array $newresponse): bool { - return parent::is_same_response($prevresponse, $newresponse); - /*if (!$this->is_complete_response($prevresponse)) { - $prevresponse = []; - } - if (!$this->is_complete_response($newresponse)) { - $newresponse = []; - } - foreach ($this->rows as $k => $row) { - print_object('$row -------------'); - print_object($row); - // TODO: - foreach ($row->correctanswers as $key =>$value) { - $fieldname = $this->field($key); - if (!question_utils::arrays_same_at_key( - $prevresponse, $newresponse, $fieldname)) { + foreach ($this->roworder as $key => $notused) { + foreach ($this->columns as $column) { + $fieldname = $this->field($key, $column->number); + if (!question_utils::arrays_same_at_key_integer($prevresponse, $newresponse, $fieldname)) { return false; } - return question_utils::arrays_same_at_key($prevresponse, $newresponse, 'answer'); } } - return true;*/ + return true; } public function get_correct_response(): ?array { @@ -549,15 +577,17 @@ public function summarise_response(array $response): ?string { $answers[] = $column->name; } } - $rowresponse = $rowresponse . implode(', ', $answers); - $responsewords[] = $rowresponse; + if (count($answers) > 0) { + $rowresponse = $rowresponse . implode(', ', $answers); + $responsewords[] = $rowresponse; + } } return implode('; ', $responsewords); } public function is_complete_response(array $response): bool { - $inputresponse = false; foreach ($this->rows as $row) { + $inputresponse = false; foreach ($this->columns as $col) { $fieldname = $this->field($row->number, $col->number); if (array_key_exists($fieldname, $response)) { @@ -568,7 +598,7 @@ public function is_complete_response(array $response): bool { return $inputresponse; } } - return $inputresponse; + return true; } public function is_gradable_response(array $response): bool { @@ -579,7 +609,7 @@ public function get_validation_error(array $response): string { if ($this->is_complete_response($response)) { return ''; } - return get_string('pleaseananswerallrows', 'qtype_oumatrix'); + return get_string('pleaseananswerallparts', 'qtype_oumatrix'); } public function grade_response(array $response): array { diff --git a/questiontype.php b/questiontype.php index a2bb7dd..625f9fe 100644 --- a/questiontype.php +++ b/questiontype.php @@ -316,10 +316,8 @@ public function get_possible_responses($questiondata) { * @param object $questiondata the question data loaded from the database. */ protected function initialise_question_rows(question_definition $question, $questiondata) { - print_object($questiondata); - print_object('-------------------------- $questiondata'); if (!empty($questiondata->rows)) { - foreach ($questiondata->rows as $row) { + foreach ($questiondata->rows as $index => $row) { $newrow = $this->make_row($row); if ($newrow->correctanswers != '') { $correctAnswers = []; @@ -337,7 +335,7 @@ protected function initialise_question_rows(question_definition $question, $ques } $newrow->correctanswers = $correctAnswers; } - $question->rows[] = $newrow; + $question->rows[$index] = $newrow; } } } diff --git a/renderer.php b/renderer.php index 63efe34..a164a73 100644 --- a/renderer.php +++ b/renderer.php @@ -113,6 +113,13 @@ public function formulation_and_controls(question_attempt $qa, $result .= html_writer::end_tag('div'); // Answer. $result .= html_writer::end_tag('fieldset'); // Ablock. + + if ($qa->get_state() == question_state::$invalid) { + $result .= html_writer::nonempty_tag('div', + $question->get_validation_error($qa->get_last_qt_data()), + array('class' => 'validationerror')); + } + return $result; } @@ -141,6 +148,10 @@ public function get_matrix(question_attempt $qa, question_display_options $optio // Creating table rows for the row questions. $table .= " "; + if ($options->readonly) { + $inputattributes['disabled'] = 'disabled'; + } + // Set the input attribute based on the single or multiple answer mode. if ( $this->get_input_type() == "single") { $inputattributes['type'] = "radio"; diff --git a/styles.css b/styles.css index bceb975..1069c66 100644 --- a/styles.css +++ b/styles.css @@ -19,7 +19,7 @@ margin-bottom: 0.5m; } -.que.oumatrix .mform .form-inline .form-group [data-groupname^=rowanswerlist] { +body#page-question-type-oumatrix .rowanswerlistlabel { padding: 0 0.5rem 0 1.0rem; }