mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 17:06:53 +02:00
MDL-58668 mod_lesson: Fix how multi answers are processed
The module was choosing as incorrect the first possible incorrect answer instead the first student incorrect answer. In the patch I also refactored the foreach loop to avoid code duplication.
This commit is contained in:
parent
6d14355ce8
commit
d5eefdb6a0
1 changed files with 35 additions and 57 deletions
|
@ -178,71 +178,49 @@ class lesson_page_type_multichoice extends lesson_page {
|
||||||
}
|
}
|
||||||
$correctpageid = null;
|
$correctpageid = null;
|
||||||
$wrongpageid = null;
|
$wrongpageid = null;
|
||||||
// this is for custom scores. If score on answer is positive, it is correct
|
|
||||||
if ($this->lesson->custom) {
|
// Iterate over all the possible answers.
|
||||||
$ncorrect = 0;
|
|
||||||
$nhits = 0;
|
|
||||||
foreach ($answers as $answer) {
|
foreach ($answers as $answer) {
|
||||||
if ($answer->score > 0) {
|
if ($this->lesson->custom) {
|
||||||
|
$iscorrectanswer = $answer->score > 0;
|
||||||
|
} else {
|
||||||
|
$iscorrectanswer = $this->lesson->jumpto_is_correct($this->properties->id, $answer->jumpto);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Iterate over all the student answers to check if he selected the current possible answer.
|
||||||
|
foreach ($studentanswers as $answerid) {
|
||||||
|
if ($answerid == $answer->id) {
|
||||||
|
if ($iscorrectanswer) {
|
||||||
|
$nhits++;
|
||||||
|
} else {
|
||||||
|
// Always jump to the page related to the student's first wrong answer.
|
||||||
|
if (!isset($wrongpageid)) {
|
||||||
|
// Leave in its "raw" state - will be converted into a proper page id later.
|
||||||
|
$wrongpageid = $answer->jumpto;
|
||||||
|
}
|
||||||
|
// Save the answer id for scoring.
|
||||||
|
if ($wronganswerid == 0) {
|
||||||
|
$wronganswerid = $answer->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($iscorrectanswer) {
|
||||||
$ncorrect++;
|
$ncorrect++;
|
||||||
|
|
||||||
foreach ($studentanswers as $answerid) {
|
// Save the first jumpto page id, may be needed!
|
||||||
if ($answerid == $answer->id) {
|
|
||||||
$nhits++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// save the first jumpto page id, may be needed!...
|
|
||||||
if (!isset($correctpageid)) {
|
if (!isset($correctpageid)) {
|
||||||
// leave in its "raw" state - will converted into a proper page id later
|
// Leave in its "raw" state - will be converted into a proper page id later.
|
||||||
$correctpageid = $answer->jumpto;
|
$correctpageid = $answer->jumpto;
|
||||||
}
|
}
|
||||||
// save the answer id for scoring
|
// Save the answer id for scoring.
|
||||||
if ($correctanswerid == 0) {
|
if ($correctanswerid == 0) {
|
||||||
$correctanswerid = $answer->id;
|
$correctanswerid = $answer->id;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// save the first jumpto page id, may be needed!...
|
|
||||||
if (!isset($wrongpageid)) {
|
|
||||||
// leave in its "raw" state - will converted into a proper page id later
|
|
||||||
$wrongpageid = $answer->jumpto;
|
|
||||||
}
|
|
||||||
// save the answer id for scoring
|
|
||||||
if ($wronganswerid == 0) {
|
|
||||||
$wronganswerid = $answer->id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
foreach ($answers as $answer) {
|
|
||||||
if ($this->lesson->jumpto_is_correct($this->properties->id, $answer->jumpto)) {
|
|
||||||
$ncorrect++;
|
|
||||||
foreach ($studentanswers as $answerid) {
|
|
||||||
if ($answerid == $answer->id) {
|
|
||||||
$nhits++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// save the first jumpto page id, may be needed!...
|
|
||||||
if (!isset($correctpageid)) {
|
|
||||||
// leave in its "raw" state - will converted into a proper page id later
|
|
||||||
$correctpageid = $answer->jumpto;
|
|
||||||
}
|
|
||||||
// save the answer id for scoring
|
|
||||||
if ($correctanswerid == 0) {
|
|
||||||
$correctanswerid = $answer->id;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// save the first jumpto page id, may be needed!...
|
|
||||||
if (!isset($wrongpageid)) {
|
|
||||||
// leave in its "raw" state - will converted into a proper page id later
|
|
||||||
$wrongpageid = $answer->jumpto;
|
|
||||||
}
|
|
||||||
// save the answer id for scoring
|
|
||||||
if ($wronganswerid == 0) {
|
|
||||||
$wronganswerid = $answer->id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((count($studentanswers) == $ncorrect) and ($nhits == $ncorrect)) {
|
if ((count($studentanswers) == $ncorrect) and ($nhits == $ncorrect)) {
|
||||||
$result->correctanswer = true;
|
$result->correctanswer = true;
|
||||||
$result->response = implode('<br />', $responses);
|
$result->response = implode('<br />', $responses);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue