Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed Feb 21, 2024
1 parent e3cf0b3 commit 4b82336
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
10 changes: 6 additions & 4 deletions question.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ abstract class qtype_oumatrix_base extends question_graded_automatically {
/** @var column[] The columns (answers) object, indexed by number. */
public $columns;

/** @var row[] The rows (subquestions) object. */
/** @var row[] The rows (subquestions) object, indexed by number. */
public $rows;

/** @var int The number of columns. */
Expand Down Expand Up @@ -190,7 +190,7 @@ public function has_specific_feedback(): bool {
* @param int $rowid
* @return row|null
*/
protected function get_row_by_id(int $rowid): ?qtype_oumatrix\row {
protected function get_row_by_id(int $rowid): ?row {
foreach ($this->rows as $row) {
if ($row->id == $rowid) {
return $row;
Expand Down Expand Up @@ -314,17 +314,19 @@ public function classify_response(array $response): array {
}

public function prepare_simulated_post_data($simulatedresponse): array {
// Expected structure of $simulatedresponse is Row name => Col name.
// Each row must be present, in order.
$postdata = [];
$subquestions = array_keys($simulatedresponse);
$answers = array_values($simulatedresponse);

foreach ($this->roworder as $key => $rowid) {
foreach ($this->roworder as $key => $rownumber) {
$row = $this->rows[$rowid];
if ($row->name !== $subquestions[$key]) {
continue;
}
if ($key === ($row->number - 1) && $row->name === $subquestions[$key]) {
foreach ($this->columns as $colid => $column) {
foreach ($this->columns as $column) {
if ($column->name !== $answers[$key]) {
continue;
}
Expand Down
36 changes: 18 additions & 18 deletions tests/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,20 +481,20 @@ public function make_oumatrix_question_animals_single(): qtype_oumatrix_single {
$question->shownumcorrect = 1;

$question->columns = [
11 => new column($question->id, 1, 'Insects', 11),
12 => new column($question->id, 2, 'Fish', 12),
13 => new column($question->id, 3, 'Birds', 13),
14 => new column($question->id, 4, 'Mammals', 14),
1 => new column($question->id, 1, 'Insects', 11),
2 => new column($question->id, 2, 'Fish', 12),
3 => new column($question->id, 3, 'Birds', 13),
4 => new column($question->id, 4, 'Mammals', 14),
];

$question->rows = [
11 => new row(11, $question->id, 1, 'Bee', [1 => '1'],
1 => new row(11, $question->id, 1, 'Bee', [1 => '1'],
'Flies and Bees are insects.', FORMAT_HTML),
12 => new row(12, $question->id, 2, 'Salmon', [2 => '1'],
2 => new row(12, $question->id, 2, 'Salmon', [2 => '1'],
'Cod, Salmon and Trout are fish.', FORMAT_HTML),
13 => new row(13, $question->id, 3, 'Seagull', [3 => '1'],
3 => new row(13, $question->id, 3, 'Seagull', [3 => '1'],
'Gulls and Owls are birds.', FORMAT_HTML),
14 => new row(14, $question->id, 4, 'Dog', [4 => '1'],
4 => new row(14, $question->id, 4, 'Dog', [4 => '1'],
'Cows, Dogs and Horses are mammals.', FORMAT_HTML),
];

Expand Down Expand Up @@ -538,21 +538,21 @@ public function make_oumatrix_question_food_multiple(): qtype_oumatrix_multiple
$question->shownumcorrect = 1;

$question->columns = [
21 => new column($question->id, 1, 'Chicken breast', 21),
22 => new column($question->id, 2, 'Carrot', 22),
23 => new column($question->id, 3, 'Salmon fillet', 23),
24 => new column($question->id, 4, 'Asparagus', 24),
25 => new column($question->id, 5, 'Olive oil', 25),
26 => new column($question->id, 6, 'Steak', 26),
27 => new column($question->id, 7, 'Potato', 27),
1 => new column($question->id, 1, 'Chicken breast', 21),
2 => new column($question->id, 2, 'Carrot', 22),
3 => new column($question->id, 3, 'Salmon fillet', 23),
4 => new column($question->id, 4, 'Asparagus', 24),
5 => new column($question->id, 5, 'Olive oil', 25),
6 => new column($question->id, 6, 'Steak', 26),
7 => new column($question->id, 7, 'Potato', 27),
];

$question->rows = [
21 => new row(21, $question->id, 1, 'Proteins', [1 => '1', 3 => '1', 6 => '1'],
1 => new row(21, $question->id, 1, 'Proteins', [1 => '1', 3 => '1', 6 => '1'],
'Chicken, fish and red meat containing proteins.', FORMAT_HTML),
22 => new row(22, $question->id, 2, 'Vegetables', [2 => '1', 4 => '1', 7 => '1'],
2 => new row(22, $question->id, 2, 'Vegetables', [2 => '1', 4 => '1', 7 => '1'],
'Carrot, Asparagus, Potato are vegetables.', FORMAT_HTML),
23 => new row(23, $question->id, 3, 'Fats', [5 => '1'],
3 => new row(23, $question->id, 3, 'Fats', [5 => '1'],
'Olive oil contains fat.', FORMAT_HTML),
];

Expand Down

0 comments on commit 4b82336

Please sign in to comment.