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.
This commit is contained in:
Adrian Greeve 2018-12-03 15:48:10 +01:00
parent 0920f35ed9
commit 568ef8bb05
4 changed files with 27 additions and 5 deletions

View File

@ -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)));

View File

@ -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'] = '<p>You earned {$a->score} out of {$a->tempmaxgrade} for the automatically graded questions.</p>
<p>Your {$a->essayquestions} essay question(s) will be graded and added into your final score at a later date.</p>
<p>Your current grade without the essay question(s) is {$a->score} out of {$a->grade}.</p>';

View File

@ -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;
}
}

View File

@ -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.