Skip to content

Commit

Permalink
Fix is_complete_response and styling
Browse files Browse the repository at this point in the history
  • Loading branch information
AnupamaSarjoshi committed Sep 22, 2023
1 parent c0e2033 commit d708d6f
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 36 deletions.
5 changes: 2 additions & 3 deletions edit_oumatrix_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ private function data_preprocessing_rows($question) {
$question->feedback[] = $feedback[$key];
$key++;
}
$question->feedback = $feedback;
return $question;
}

Expand Down Expand Up @@ -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++) {
Expand All @@ -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);
Expand Down
86 changes: 58 additions & 28 deletions question.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)) {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
6 changes: 2 additions & 4 deletions questiontype.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -337,7 +335,7 @@ protected function initialise_question_rows(question_definition $question, $ques
}
$newrow->correctanswers = $correctAnswers;
}
$question->rows[] = $newrow;
$question->rows[$index] = $newrow;
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -141,6 +148,10 @@ public function get_matrix(question_attempt $qa, question_display_options $optio
// Creating table rows for the row questions.
$table .= "<tr> ";

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";
Expand Down
2 changes: 1 addition & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit d708d6f

Please sign in to comment.