MDL-48963 Lesson: File support to true/false answers

This commit is contained in:
Stephen Bourget 2015-02-01 09:32:52 -05:00
parent 4c27f52d91
commit a1556aaf86
5 changed files with 16 additions and 10 deletions

View File

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

View File

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

View File

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

View File

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

View File

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