From a1556aaf86edad78a36876927223121489b44e80 Mon Sep 17 00:00:00 2001 From: Stephen Bourget Date: Sun, 1 Feb 2015 09:32:52 -0500 Subject: [PATCH] MDL-48963 Lesson: File support to true/false answers --- mod/lesson/locallib.php | 15 +++++++++------ mod/lesson/pagetypes/matching.php | 2 +- mod/lesson/pagetypes/multichoice.php | 2 +- mod/lesson/pagetypes/truefalse.php | 4 ++-- mod/lesson/upgrade.txt | 3 +++ 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index 1a3ba153b84..db9fd909ba3 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -58,6 +58,8 @@ define("LESSON_UNDEFINED", -99); /** LESSON_MAX_EVENT_LENGTH = 432000 ; 5 days maximum */ define("LESSON_MAX_EVENT_LENGTH", "432000"); +/** Answer format is HTML */ +define("LESSON_ANSWER_HTML", "HTML"); ////////////////////////////////////////////////////////////////////////////////////// /// Any other lesson functions go here. Each of them must have a name that @@ -785,23 +787,24 @@ abstract class lesson_add_page_form_base extends moodleform { * @param int $count The count of the element to add * @param string $label, null means default * @param bool $required + * @param string $format * @return void */ - protected final function add_answer($count, $label = null, $required = false) { + protected final function add_answer($count, $label = null, $required = false, $format= '') { if ($label === null) { $label = get_string('answer', 'lesson'); } - if ($this->qtype != 'multichoice' && $this->qtype != 'matching') { - $this->_form->addElement('editor', 'answer_editor['.$count.']', $label, - array('rows' => '4', 'columns' => '80'), array('noclean' => true)); - $this->_form->setDefault('answer_editor['.$count.']', array('text' => '', 'format' => FORMAT_MOODLE)); - } else { + if ($format == LESSON_ANSWER_HTML) { $this->_form->addElement('editor', 'answer_editor['.$count.']', $label, array('rows' => '4', 'columns' => '80'), array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $this->_customdata['maxbytes'])); $this->_form->setType('answer_editor['.$count.']', PARAM_RAW); $this->_form->setDefault('answer_editor['.$count.']', array('text' => '', 'format' => FORMAT_HTML)); + } else { + $this->_form->addElement('editor', 'answer_editor['.$count.']', $label, + array('rows' => '4', 'columns' => '80'), array('noclean' => true)); + $this->_form->setDefault('answer_editor['.$count.']', array('text' => '', 'format' => FORMAT_MOODLE)); } if ($required) { diff --git a/mod/lesson/pagetypes/matching.php b/mod/lesson/pagetypes/matching.php index 7c28403be3f..c6b1230bb55 100644 --- a/mod/lesson/pagetypes/matching.php +++ b/mod/lesson/pagetypes/matching.php @@ -495,7 +495,7 @@ class lesson_add_page_form_matching extends lesson_add_page_form_base { for ($i = 2; $i < $this->_customdata['lesson']->maxanswers+2; $i++) { $this->_form->addElement('header', 'matchingpair'.($i-1), get_string('matchingpair', 'lesson', $i-1)); - $this->add_answer($i, null, ($i < 4)); + $this->add_answer($i, null, ($i < 4), LESSON_ANSWER_HTML); $required = ($i < 4); $label = get_string('matchesanswer','lesson'); $count = $i; diff --git a/mod/lesson/pagetypes/multichoice.php b/mod/lesson/pagetypes/multichoice.php index c22a6ea0bb4..5dc763af77a 100644 --- a/mod/lesson/pagetypes/multichoice.php +++ b/mod/lesson/pagetypes/multichoice.php @@ -453,7 +453,7 @@ class lesson_add_page_form_multichoice extends lesson_add_page_form_base { for ($i = 0; $i < $this->_customdata['lesson']->maxanswers; $i++) { $this->_form->addElement('header', 'answertitle'.$i, get_string('answer').' '.($i+1)); - $this->add_answer($i, null, ($i<2)); + $this->add_answer($i, null, ($i<2), LESSON_ANSWER_HTML); $this->add_response($i); $this->add_jumpto($i, null, ($i == 0 ? LESSON_NEXTPAGE : LESSON_THISPAGE)); $this->add_score($i, null, ($i===0)?1:0); diff --git a/mod/lesson/pagetypes/truefalse.php b/mod/lesson/pagetypes/truefalse.php index c0376c6bb27..d9896801983 100644 --- a/mod/lesson/pagetypes/truefalse.php +++ b/mod/lesson/pagetypes/truefalse.php @@ -339,13 +339,13 @@ class lesson_add_page_form_truefalse extends lesson_add_page_form_base { public function custom_definition() { $this->_form->addElement('header', 'answertitle0', get_string('correctresponse', 'lesson')); - $this->add_answer(0, null, true); + $this->add_answer(0, null, true, LESSON_ANSWER_HTML); $this->add_response(0); $this->add_jumpto(0, get_string('correctanswerjump', 'lesson'), LESSON_NEXTPAGE); $this->add_score(0, get_string('correctanswerscore', 'lesson'), 1); $this->_form->addElement('header', 'answertitle1', get_string('wrongresponse', 'lesson')); - $this->add_answer(1, null, true); + $this->add_answer(1, null, true, LESSON_ANSWER_HTML); $this->add_response(1); $this->add_jumpto(1, get_string('wronganswerjump', 'lesson'), LESSON_THISPAGE); $this->add_score(1, get_string('wronganswerscore', 'lesson'), 0); diff --git a/mod/lesson/upgrade.txt b/mod/lesson/upgrade.txt index 2e5abe80126..819059eaf9f 100644 --- a/mod/lesson/upgrade.txt +++ b/mod/lesson/upgrade.txt @@ -8,6 +8,9 @@ This files describes API changes in the lesson code. have been removed, this is now handled by the base class: lesson_page::update in locallib.php and the exact same code is executed (it is also executed by the lesson_page_type_cluster class that previously had no update function). +* A fourth parameter (format) has been added to the add_answer() function + located as part of the lesson_add_page_form_base class. If specified with a value of 'LESSON_ANSWER_HTML' + then a rich html editor is generated. Otherwise an editor is created with Moodle Auto Format === Earlier changes ===