From 568ef8bb052c09be19dae62ea08b7180f6027e17 Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Mon, 3 Dec 2018 15:48:10 +0100 Subject: [PATCH] MDL-59081 mod_lesson: Add other answer options to questions This adds another form field that will catch all other answers made by the student. Current question types updated are numerical and shortanswer. --- mod/lesson/editpage.php | 2 ++ mod/lesson/lang/en/lesson.php | 5 ++++- mod/lesson/locallib.php | 20 ++++++++++++++++---- mod/lesson/upgrade.txt | 5 +++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/mod/lesson/editpage.php b/mod/lesson/editpage.php index e0b4bd3983a..7f7bef8103a 100644 --- a/mod/lesson/editpage.php +++ b/mod/lesson/editpage.php @@ -137,6 +137,8 @@ if ($edit) { } $answerscount++; } + // Let the lesson pages make updates if required. + $data = $editpage->update_form_data($data); $mform->set_data($data); $PAGE->navbar->add(get_string('edit'), new moodle_url('/mod/lesson/edit.php', array('id'=>$id))); diff --git a/mod/lesson/lang/en/lesson.php b/mod/lesson/lang/en/lesson.php index b8b16abd3dd..7fa90a08bc6 100644 --- a/mod/lesson/lang/en/lesson.php +++ b/mod/lesson/lang/en/lesson.php @@ -59,6 +59,9 @@ $string['additionalattemptsremaining'] = 'Completed, You can re-attempt this les $string['addpage'] = 'Add a page'; $string['addshortanswer'] = 'Create a Short answer question page'; $string['addtruefalse'] = 'Create a True/false question page'; +$string['allotheranswers'] = 'All other answers'; +$string['allotheranswersjump'] = 'All other answers jump'; +$string['allotheranswersscore'] = 'All other answers score'; $string['allowofflineattempts'] = 'Allow lesson to be attempted offline using the mobile app'; $string['allowofflineattempts_help'] = 'If enabled, a mobile app user can download the lesson and attempt it offline. All the possible answers and correct responses will be downloaded as well. @@ -162,7 +165,7 @@ $string['displayleftmenu'] = 'Display menu'; $string['displayleftmenu_help'] = 'If enabled, a menu allowing users to navigate through the list of pages is displayed.'; $string['displayofgrade'] = 'Display of grade (for students only)'; $string['displayreview'] = 'Provide option to try a question again'; -$string['displayreview_help'] = 'If enabled, when a question is answered incorrectly, the student is given the option to try it again for no point credit, or continue with the lesson.'; +$string['displayreview_help'] = 'If enabled, when a question is answered incorrectly, the student is given the option to try it again for no point credit, or continue with the lesson. If the student clicks to move on to another question then the selected (wrong) answer will be followed. By default wrong answer jumps are set to "this page" and have a score of 0, so it is recommended that you set the wrong answer jump to a different page to avoid confusion with your students.'; $string['displayscorewithessays'] = '

You earned {$a->score} out of {$a->tempmaxgrade} for the automatically graded questions.

Your {$a->essayquestions} essay question(s) will be graded and added into your final score at a later date.

Your current grade without the essay question(s) is {$a->score} out of {$a->grade}.

'; diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index 95850ccaa83..b0b564f625e 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -61,6 +61,9 @@ define("LESSON_MAX_EVENT_LENGTH", "432000"); /** Answer format is HTML */ define("LESSON_ANSWER_HTML", "HTML"); +/** Placeholder answer for all other answers. */ +define("LESSON_OTHER_ANSWERS", "@#wronganswer#@"); + ////////////////////////////////////////////////////////////////////////////////////// /// Any other lesson functions go here. Each of them must have a name that /// starts with lesson_ @@ -4456,7 +4459,7 @@ abstract class lesson_page extends lesson_base { $DB->insert_record("lesson_answers", $answer); } } else { - for ($i = 0; $i < $this->lesson->maxanswers; $i++) { + for ($i = 0; $i < count($properties->answer_editor); $i++) { if (!array_key_exists($i, $this->answers)) { $this->answers[$i] = new stdClass; $this->answers[$i]->lessonid = $this->lesson->id; @@ -4575,7 +4578,7 @@ abstract class lesson_page extends lesson_base { $answers = array(); - for ($i = 0; $i < $this->lesson->maxanswers; $i++) { + for ($i = 0; $i < ($this->lesson->maxanswers + 1); $i++) { $answer = clone($newanswer); if (isset($properties->answer_editor[$i])) { @@ -4610,8 +4613,6 @@ abstract class lesson_page extends lesson_base { $properties->answer_editor[$i]); } $answers[$answer->id] = new lesson_page_answer($answer); - } else { - break; } } @@ -4901,6 +4902,17 @@ abstract class lesson_page extends lesson_base { return $fs->get_area_files($this->lesson->context->id, 'mod_lesson', 'page_contents', $this->properties->id, 'itemid, filepath, filename', $includedirs, $updatedsince); } + + /** + * Make updates to the form data if required. + * + * @since Moodle 3.7 + * @param stdClass $data The form data to update. + * @return stdClass The updated fom data. + */ + public function update_form_data(stdClass $data) : stdClass { + return $data; + } } diff --git a/mod/lesson/upgrade.txt b/mod/lesson/upgrade.txt index 5ba485e23c6..7f0e0c2fbf0 100644 --- a/mod/lesson/upgrade.txt +++ b/mod/lesson/upgrade.txt @@ -1,5 +1,10 @@ This files describes API changes in the lesson code. +=== 3.6.1 === + +* A new function update_form_data() has been added to lesson_page class. This can be overridden by the individual page types + to alter the form data before being sent to the mform. + === 3.4 === * External function mod_lesson_external::get_user_attempt() now returns the full page object inside each answerpages.