diff --git a/mod/lesson/backup/moodle2/backup_lesson_stepslib.php b/mod/lesson/backup/moodle2/backup_lesson_stepslib.php
index 30367de03ae..2ff5ef6f5ce 100644
--- a/mod/lesson/backup/moodle2/backup_lesson_stepslib.php
+++ b/mod/lesson/backup/moodle2/backup_lesson_stepslib.php
@@ -190,6 +190,8 @@ class backup_lesson_activity_structure_step extends backup_activity_structure_st
// Annotate the file areas in user by the lesson module.
$lesson->annotate_files('mod_lesson', 'mediafile', null);
$page->annotate_files('mod_lesson', 'page_contents', 'id');
+ $answer->annotate_files('mod_lesson', 'page_answers', 'id');
+ $answer->annotate_files('mod_lesson', 'page_responses', 'id');
// Prepare and return the structure we have just created for the lesson module.
return $this->prepare_activity_structure($lesson);
diff --git a/mod/lesson/backup/moodle2/restore_lesson_activity_task.class.php b/mod/lesson/backup/moodle2/restore_lesson_activity_task.class.php
index 4b8351c8b0d..3dbbc902c74 100644
--- a/mod/lesson/backup/moodle2/restore_lesson_activity_task.class.php
+++ b/mod/lesson/backup/moodle2/restore_lesson_activity_task.class.php
@@ -55,6 +55,7 @@ class restore_lesson_activity_task extends restore_activity_task {
$contents = array();
$contents[] = new restore_decode_content('lesson_pages', array('contents'), 'lesson_page');
+ $contents[] = new restore_decode_content('lesson_answers', array('answer', 'response'), 'lesson_answer');
return $contents;
}
diff --git a/mod/lesson/backup/moodle2/restore_lesson_stepslib.php b/mod/lesson/backup/moodle2/restore_lesson_stepslib.php
index a06adb53a87..34e8371370c 100644
--- a/mod/lesson/backup/moodle2/restore_lesson_stepslib.php
+++ b/mod/lesson/backup/moodle2/restore_lesson_stepslib.php
@@ -105,7 +105,7 @@ class restore_lesson_activity_structure_step extends restore_activity_structure_
// Set a dummy mapping to get the old ID so that it can be used by get_old_parentid when
// processing attempts. It will be corrected in after_execute
- $this->set_mapping('lesson_answer', $data->id, 0);
+ $this->set_mapping('lesson_answer', $data->id, 0, true); // Has related fileareas.
// Answers need to be processed in order, so we store them in an
// instance variable and insert them in the after_execute stage
@@ -186,7 +186,7 @@ class restore_lesson_activity_structure_step extends restore_activity_structure_
ksort($this->answers);
foreach ($this->answers as $answer) {
$newitemid = $DB->insert_record('lesson_answers', $answer);
- $this->set_mapping('lesson_answer', $answer->id, $newitemid);
+ $this->set_mapping('lesson_answer', $answer->id, $newitemid, true);
// Update the lesson attempts to use the newly created answerid
$DB->set_field('lesson_attempts', 'answerid', $newitemid, array(
@@ -199,6 +199,8 @@ class restore_lesson_activity_structure_step extends restore_activity_structure_
$this->add_related_files('mod_lesson', 'mediafile', null);
// Add lesson page files, by lesson_page itemname
$this->add_related_files('mod_lesson', 'page_contents', 'lesson_page');
+ $this->add_related_files('mod_lesson', 'page_answers', 'lesson_answer');
+ $this->add_related_files('mod_lesson', 'page_responses', 'lesson_answer');
// Remap all the restored prevpageid and nextpageid now that we have all the pages and their mappings
$rs = $DB->get_recordset('lesson_pages', array('lessonid' => $this->task->get_activityid()),
diff --git a/mod/lesson/editpage.php b/mod/lesson/editpage.php
index e61107cd76d..786ab3315cb 100644
--- a/mod/lesson/editpage.php
+++ b/mod/lesson/editpage.php
@@ -85,6 +85,31 @@ if ($edit) {
$data->id = $cm->id;
$editoroptions['context'] = $context;
$data = file_prepare_standard_editor($data, 'contents', $editoroptions, $context, 'mod_lesson', 'page_contents', $editpage->id);
+
+ $answerscount = 0;
+ $answers = $editpage->get_answers();
+ foreach ($answers as $answer) {
+ $answereditor = 'answer_editor['.$answerscount.']';
+ if (is_array($data->$answereditor)) {
+ $answerdata = $data->$answereditor;
+ $answerdraftid = file_get_submitted_draft_itemid($answereditor);
+ $answertext = file_prepare_draft_area($answerdraftid, $PAGE->cm->context->id,
+ 'mod_lesson', 'page_answers', $answer->id, $editoroptions, $answerdata['text']);
+ $data->$answereditor = array('text' => $answertext, 'format' => $answerdata['format'], 'itemid' => $answerdraftid);
+ }
+
+ $responseeditor = 'response_editor['.$answerscount.']';
+ if (is_array($data->$responseeditor)) {
+ $responsedata = $data->$responseeditor;
+ $responsedraftid = file_get_submitted_draft_itemid($responseeditor);
+ $responsetext = file_prepare_draft_area($responsedraftid, $PAGE->cm->context->id,
+ 'mod_lesson', 'page_responses', $answer->id, $editoroptions, $responsedata['text']);
+ $data->$responseeditor = array('text' => $responsetext, 'format' => $responsedata['format'],
+ 'itemid' => $responsedraftid);
+ }
+ $answerscount++;
+ }
+
$mform->set_data($data);
$PAGE->navbar->add(get_string('edit'), new moodle_url('/mod/lesson/edit.php', array('id'=>$id)));
$PAGE->navbar->add(get_string('editingquestionpage', 'lesson', get_string($mform->qtypestring, 'lesson')));
diff --git a/mod/lesson/lang/en/lesson.php b/mod/lesson/lang/en/lesson.php
index 81fd75cf9da..594554f2492 100644
--- a/mod/lesson/lang/en/lesson.php
+++ b/mod/lesson/lang/en/lesson.php
@@ -336,7 +336,9 @@ $string['page'] = 'Page: {$a}';
$string['page-mod-lesson-x'] = 'Any lesson page';
$string['page-mod-lesson-view'] = 'View or preview lesson page';
$string['page-mod-lesson-edit'] = 'Edit lesson page';
+$string['pageanswers'] = 'Page answers';
$string['pagecontents'] = 'Page contents';
+$string['pageresponses'] = 'Page responses';
$string['pages'] = 'Pages';
$string['pagetitle'] = 'Page title';
$string['password'] = 'Password';
diff --git a/mod/lesson/lib.php b/mod/lesson/lib.php
index e21101de872..f83a6e50637 100644
--- a/mod/lesson/lib.php
+++ b/mod/lesson/lib.php
@@ -865,6 +865,13 @@ function lesson_pluginfile($course, $cm, $context, $filearea, $args, $forcedownl
}
$fullpath = "/$context->id/mod_lesson/$filearea/$pageid/".implode('/', $args);
+ } else if ($filearea === 'page_answers' || $filearea === 'page_responses') {
+ $itemid = (int)array_shift($args);
+ if (!$pageanswers = $DB->get_record('lesson_answers', array('id' => $itemid))) {
+ return false;
+ }
+ $fullpath = "/$context->id/mod_lesson/$filearea/$itemid/".implode('/', $args);
+
} else if ($filearea === 'mediafile') {
if (count($args) > 1) {
// Remove the itemid when it appears to be part of the arguments. If there is only one argument
@@ -897,6 +904,8 @@ function lesson_get_file_areas() {
$areas = array();
$areas['page_contents'] = get_string('pagecontents', 'mod_lesson');
$areas['mediafile'] = get_string('mediafile', 'mod_lesson');
+ $areas['page_answers'] = get_string('pageanswers', 'mod_lesson');
+ $areas['page_responses'] = get_string('pageresponses', 'mod_lesson');
return $areas;
}
diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php
index 9517df2402c..1d773957d2b 100644
--- a/mod/lesson/locallib.php
+++ b/mod/lesson/locallib.php
@@ -790,8 +790,19 @@ abstract class lesson_add_page_form_base extends moodleform {
if ($label === null) {
$label = get_string('answer', 'lesson');
}
- $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 ($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 {
+ $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));
+ }
+
if ($required) {
$this->_form->addRule('answer_editor['.$count.']', get_string('required'), 'required', null, 'client');
}
@@ -808,8 +819,12 @@ abstract class lesson_add_page_form_base extends moodleform {
if ($label === null) {
$label = get_string('response', 'lesson');
}
- $this->_form->addElement('editor', 'response_editor['.$count.']', $label, array('rows'=>'4', 'columns'=>'80'), array('noclean'=>true));
- $this->_form->setDefault('response_editor['.$count.']', array('text'=>'', 'format'=>FORMAT_MOODLE));
+ $this->_form->addElement('editor', 'response_editor['.$count.']', $label,
+ array('rows' => '4', 'columns' => '80'),
+ array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $this->_customdata['maxbytes']));
+ $this->_form->setType('response_editor['.$count.']', PARAM_RAW);
+ $this->_form->setDefault('response_editor['.$count.']', array('text' => '', 'format' => FORMAT_HTML));
+
if ($required) {
$this->_form->addRule('response_editor['.$count.']', get_string('required'), 'required', null, 'client');
}
@@ -1861,6 +1876,8 @@ abstract class lesson_page extends lesson_base {
$context = context_module::instance($cm->id);
$fs = get_file_storage();
$fs->delete_area_files($context->id, 'mod_lesson', 'page_contents', $this->properties->id);
+ $fs->delete_area_files($context->id, 'mod_lesson', 'page_answers', $this->properties->id);
+ $fs->delete_area_files($context->id, 'mod_lesson', 'page_responses', $this->properties->id);
// repair the hole in the linkage
if (!$this->properties->prevpageid && !$this->properties->nextpageid) {
@@ -1958,7 +1975,7 @@ abstract class lesson_page extends lesson_base {
* @return stdClass Returns the result of the attempt
*/
final public function record_attempt($context) {
- global $DB, $USER, $OUTPUT;
+ global $DB, $USER, $OUTPUT, $PAGE;
/**
* This should be overridden by each page type to actually check the response
@@ -2064,6 +2081,9 @@ abstract class lesson_page extends lesson_base {
$options->noclean = true;
$options->para = true;
$options->overflowdiv = true;
+ $result->response = file_rewrite_pluginfile_urls($result->response, 'pluginfile.php', $context->id,
+ 'mod_lesson', 'page_responses', $result->answerid);
+
$result->feedback = $OUTPUT->box(format_text($this->get_contents(), $this->properties->contentsformat, $options), 'generalbox boxaligncenter');
$result->feedback .= '
'.get_string("youranswer", "lesson").' : '.$result->studentanswer; // already in clean html
$result->feedback .= $OUTPUT->box($result->response, $class); // already conerted to HTML
@@ -2146,6 +2166,51 @@ abstract class lesson_page extends lesson_base {
return true;
}
+ /**
+ * save editor answers files and update answer record
+ *
+ * @param object $context
+ * @param int $maxbytes
+ * @param object $answer
+ * @param object $answereditor
+ * @param object $responseeditor
+ */
+ public function save_answers_files($context, $maxbytes, &$answer, $answereditor = '', $responseeditor = '') {
+ global $DB;
+ if (isset($answereditor['itemid'])) {
+ $answer->answer = file_save_draft_area_files($answereditor['itemid'],
+ $context->id, 'mod_lesson', 'page_answers', $answer->id,
+ array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $maxbytes),
+ $answer->answer, null);
+ $DB->set_field('lesson_answers', 'answer', $answer->answer, array('id' => $answer->id));
+ }
+ if (isset($responseeditor['itemid'])) {
+ $answer->response = file_save_draft_area_files($responseeditor['itemid'],
+ $context->id, 'mod_lesson', 'page_responses', $answer->id,
+ array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $maxbytes),
+ $answer->response, null);
+ $DB->set_field('lesson_answers', 'response', $answer->response, array('id' => $answer->id));
+ }
+ }
+
+ /**
+ * Rewrite urls in answer and response of a question answer
+ *
+ * @param object $answer
+ * @return object answer with rewritten urls
+ */
+ public static function rewrite_answers_urls($answer) {
+ global $PAGE;
+
+ $context = context_module::instance($PAGE->cm->id);
+ $answer->answer = file_rewrite_pluginfile_urls($answer->answer, 'pluginfile.php', $context->id,
+ 'mod_lesson', 'page_answers', $answer->id);
+ $answer->response = file_rewrite_pluginfile_urls($answer->response, 'pluginfile.php', $context->id,
+ 'mod_lesson', 'page_responses', $answer->id);
+
+ return $answer;
+ }
+
/**
* Updates a lesson page and its answers within the database
*
@@ -2201,6 +2266,10 @@ abstract class lesson_page extends lesson_base {
$DB->update_record("lesson_answers", $this->answers[$i]->properties());
}
+ // Save files in answers and responses.
+ $this->save_answers_files($context, $maxbytes, $this->answers[$i],
+ $properties->answer_editor[$i], $properties->response_editor[$i]);
+
} else if (isset($this->answers[$i]->id)) {
$DB->delete_records('lesson_answers', array('id'=>$this->answers[$i]->id));
unset($this->answers[$i]);
@@ -2260,13 +2329,16 @@ abstract class lesson_page extends lesson_base {
* @return array
*/
public function create_answers($properties) {
- global $DB;
+ global $DB, $PAGE;
// now add the answers
$newanswer = new stdClass;
$newanswer->lessonid = $this->lesson->id;
$newanswer->pageid = $this->properties->id;
$newanswer->timecreated = $this->properties->timecreated;
+ $cm = get_coursemodule_from_instance('lesson', $this->lesson->id, $this->lesson->course);
+ $context = context_module::instance($cm->id);
+
$answers = array();
for ($i = 0; $i < $this->lesson->maxanswers; $i++) {
@@ -2289,6 +2361,13 @@ abstract class lesson_page extends lesson_base {
$answer->score = $properties->score[$i];
}
$answer->id = $DB->insert_record("lesson_answers", $answer);
+ if (isset($properties->response_editor[$i])) {
+ $this->save_answers_files($context, $PAGE->course->maxbytes, $answer,
+ $properties->answer_editor[$i], $properties->response_editor[$i]);
+ } else {
+ $this->save_answers_files($context, $PAGE->course->maxbytes, $answer,
+ $properties->answer_editor[$i]);
+ }
$answers[$answer->id] = new lesson_page_answer($answer);
} else {
break;
diff --git a/mod/lesson/pagetypes/matching.php b/mod/lesson/pagetypes/matching.php
index ea0f0f44b4b..18971889109 100644
--- a/mod/lesson/pagetypes/matching.php
+++ b/mod/lesson/pagetypes/matching.php
@@ -96,13 +96,16 @@ class lesson_page_type_matching extends lesson_page {
}
public function create_answers($properties) {
- global $DB;
+ global $DB, $PAGE;
// now add the answers
$newanswer = new stdClass;
$newanswer->lessonid = $this->lesson->id;
$newanswer->pageid = $this->properties->id;
$newanswer->timecreated = $this->properties->timecreated;
+ $cm = get_coursemodule_from_instance('lesson', $this->lesson->id, $this->lesson->course);
+ $context = context_module::instance($cm->id);
+
$answers = array();
// need to add two to offset correct response and wrong response
@@ -127,6 +130,8 @@ class lesson_page_type_matching extends lesson_page {
if (isset($answer->answer) && $answer->answer != '') {
$answer->id = $DB->insert_record("lesson_answers", $answer);
+ $this->save_answers_files($context, $PAGE->course->maxbytes,
+ $answer, $properties->answer_editor[$i]);
$answers[$answer->id] = new lesson_page_answer($answer);
} else if ($i < 2) {
$answer->id = $DB->insert_record("lesson_answers", $answer);
@@ -159,6 +164,9 @@ class lesson_page_type_matching extends lesson_page {
$response = $data->response;
$getanswers = $this->get_answers();
+ foreach ($getanswers as $key => $answer) {
+ $getanswers[$key] = parent::rewrite_answers_urls($answer);
+ }
$correct = array_shift($getanswers);
$wrong = array_shift($getanswers);
@@ -333,6 +341,9 @@ class lesson_page_type_matching extends lesson_page {
} else {
$DB->update_record("lesson_answers", $this->answers[$i]->properties());
}
+ // Save files in answers and responses.
+ $this->save_answers_files($context, $maxbytes, $this->answers[$i],
+ $properties->answer_editor[$i], $properties->response_editor[$i]);
} else if ($i < 2) {
if (!isset($this->answers[$i]->id)) {
$this->answers[$i]->id = $DB->insert_record("lesson_answers", $this->answers[$i]);
@@ -340,6 +351,9 @@ class lesson_page_type_matching extends lesson_page {
$DB->update_record("lesson_answers", $this->answers[$i]->properties());
}
+ // Save files in answers and responses.
+ $this->save_answers_files( $context, $maxbytes, $this->answers[$i],
+ $properties->answer_editor[$i], $properties->response_editor[$i]);
} else if (isset($this->answers[$i]->id)) {
$DB->delete_records('lesson_answers', array('id'=>$this->answers[$i]->id));
unset($this->answers[$i]);
@@ -460,12 +474,21 @@ class lesson_add_page_form_matching extends lesson_add_page_form_base {
public function custom_definition() {
$this->_form->addElement('header', 'correctresponse', get_string('correctresponse', 'lesson'));
- $this->_form->addElement('editor', 'answer_editor[0]', get_string('correctresponse', 'lesson'), array('rows'=>'4', 'columns'=>'80'), array('noclean'=>true));
+ $this->_form->addElement('editor', 'answer_editor[0]', get_string('correctresponse', 'lesson'),
+ array('rows' => '4', 'columns' => '80'),
+ array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $this->_customdata['maxbytes']));
+ $this->_form->setType('answer_editor[0]', PARAM_RAW);
+ $this->_form->setDefault('answer_editor[0]', array('text' => '', 'format' => FORMAT_HTML));
$this->add_jumpto(0, get_string('correctanswerjump','lesson'), LESSON_NEXTPAGE);
$this->add_score(0, get_string("correctanswerscore", "lesson"), 1);
$this->_form->addElement('header', 'wrongresponse', get_string('wrongresponse', 'lesson'));
- $this->_form->addElement('editor', 'answer_editor[1]', get_string('wrongresponse', 'lesson'), array('rows'=>'4', 'columns'=>'80'), array('noclean'=>true));
+ $this->_form->addElement('editor', 'answer_editor[1]', get_string('wrongresponse', 'lesson'),
+ array('rows' => '4', 'columns' => '80'),
+ array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $this->_customdata['maxbytes']));
+ $this->_form->setType('answer_editor[1]', PARAM_RAW);
+ $this->_form->setDefault('answer_editor[1]', array('text' => '', 'format' => FORMAT_HTML));
+
$this->add_jumpto(1, get_string('wronganswerjump','lesson'), LESSON_THISPAGE);
$this->add_score(1, get_string("wronganswerscore", "lesson"), 0);
@@ -488,7 +511,7 @@ class lesson_add_page_form_matching extends lesson_add_page_form_base {
class lesson_display_answer_form_matching extends moodleform {
public function definition() {
- global $USER, $OUTPUT;
+ global $USER, $OUTPUT, $PAGE;
$mform = $this->_form;
$answers = $this->_customdata['answers'];
$useranswers = $this->_customdata['useranswers'];
@@ -529,6 +552,9 @@ class lesson_display_answer_form_matching extends moodleform {
// Temporary fixed until MDL-38885 gets integrated
$mform->setType('response', PARAM_TEXT);
}
+ $context = context_module::instance($PAGE->cm->id);
+ $answer->answer = file_rewrite_pluginfile_urls($answer->answer, 'pluginfile.php', $context->id,
+ 'mod_lesson', 'page_answers', $answer->id);
$mform->addElement('select', $responseid, format_text($answer->answer,$answer->answerformat,$options), $responseoptions, $disabled);
$mform->setType($responseid, PARAM_TEXT);
if ($hasattempt) {
diff --git a/mod/lesson/pagetypes/multichoice.php b/mod/lesson/pagetypes/multichoice.php
index 8d8409f8237..99cbe082f44 100644
--- a/mod/lesson/pagetypes/multichoice.php
+++ b/mod/lesson/pagetypes/multichoice.php
@@ -77,6 +77,8 @@ class lesson_page_type_multichoice extends lesson_page {
foreach ($answers as $key=>$answer) {
if ($answer->answer === '') {
unset($answers[$key]);
+ } else {
+ $answers[$key] = parent::rewrite_answers_urls($answer);
}
}
return $answers;
@@ -246,6 +248,7 @@ class lesson_page_type_multichoice extends lesson_page {
if (!$answer = $DB->get_record("lesson_answers", array("id" => $result->answerid))) {
print_error("Continue: answer record not found");
}
+ $answer = parent::rewrite_answers_urls($answer);
if ($this->lesson->jumpto_is_correct($this->properties->id, $answer->jumpto)) {
$result->correctanswer = true;
}
diff --git a/mod/lesson/pagetypes/truefalse.php b/mod/lesson/pagetypes/truefalse.php
index 7a8a0f4b507..d5584ee33a8 100644
--- a/mod/lesson/pagetypes/truefalse.php
+++ b/mod/lesson/pagetypes/truefalse.php
@@ -50,6 +50,9 @@ class lesson_page_type_truefalse extends lesson_page {
public function display($renderer, $attempt) {
global $USER, $CFG, $PAGE;
$answers = $this->get_answers();
+ foreach ($answers as $key => $answer) {
+ $answers[$key] = parent::rewrite_answers_urls($answer);
+ }
shuffle($answers);
$params = array('answers'=>$answers, 'lessonid'=>$this->lesson->id, 'contents'=>$this->get_contents(), 'attempt'=>$attempt);
@@ -81,6 +84,7 @@ class lesson_page_type_truefalse extends lesson_page {
}
$result->answerid = $data->answerid;
$answer = $DB->get_record("lesson_answers", array("id" => $result->answerid), '*', MUST_EXIST);
+ $answer = parent::rewrite_answers_urls($answer);
if ($this->lesson->jumpto_is_correct($this->properties->id, $answer->jumpto)) {
$result->correctanswer = true;
}
@@ -104,6 +108,7 @@ class lesson_page_type_truefalse extends lesson_page {
$options->para = false;
$i = 1;
foreach ($answers as $answer) {
+ $answer = parent::rewrite_answers_urls($answer);
$cells = array();
if ($this->lesson->custom && $answer->score > 0) {
// if the score is > 0, then it is correct
@@ -193,6 +198,9 @@ class lesson_page_type_truefalse extends lesson_page {
} else {
$DB->update_record("lesson_answers", $this->answers[$i]->properties());
}
+ // Save files in answers and responses.
+ $this->save_answers_files($context, $maxbytes, $this->answers[$i],
+ $properties->answer_editor[$i], $properties->response_editor[$i]);
} else if (isset($this->answers[$i]->id)) {
$DB->delete_records('lesson_answers', array('id'=>$this->answers[$i]->id));
unset($this->answers[$i]);
@@ -238,6 +246,7 @@ class lesson_page_type_truefalse extends lesson_page {
$formattextdefoptions->para = false;
$formattextdefoptions->noclean = true;
foreach ($answers as $answer) {
+ $answer = parent::rewrite_answers_urls($answer);
if ($this->properties->qoption) {
if ($useranswer == null) {
$userresponse = array();
@@ -385,6 +394,7 @@ class lesson_display_answer_form_truefalse extends moodleform {
$ansid = 'answer_id';
}
+ $answer = lesson_page::rewrite_answers_urls($answer);
$mform->addElement('radio', $ansid, null, format_text($answer->answer, $answer->answerformat, $options), $answer->id, $disabled);
$mform->setType($ansid, PARAM_INT);
if ($hasattempt && $answer->id == $USER->modattempts[$lessonid]->answerid) {
diff --git a/mod/lesson/tests/behat/questions_images.feature b/mod/lesson/tests/behat/questions_images.feature
new file mode 100644
index 00000000000..3433d451e41
--- /dev/null
+++ b/mod/lesson/tests/behat/questions_images.feature
@@ -0,0 +1,97 @@
+@mod @mod_lesson
+Feature: In a lesson activity, teacher can add embedded images in questions answers and responses
+ As a teacher
+ I need to add questions with images in answers and responses
+
+ @javascript @_file_upload
+ Scenario: questions with images in answers and responses
+ Given the following "users" exist:
+ | username | firstname | lastname | email |
+ | teacher1 | Teacher | 1 | teacher1@asd.com |
+ | student1 | Student | 1 | student1@asd.com |
+ And the following "courses" exist:
+ | fullname | shortname | category |
+ | Course 1 | C1 | 0 |
+ And the following "course enrolments" exist:
+ | user | course | role |
+ | teacher1 | C1 | editingteacher |
+ | student1 | C1 | student |
+ And I log in as "teacher1"
+ And I navigate to "My private files" node in "My profile"
+ And I upload "mod/lesson/tests/fixtures/moodle_logo.jpg" file to "Files" filemanager
+ And I click on "Save changes" "button"
+ When I am on homepage
+ And I follow "Course 1"
+ And I turn editing mode on
+ And I add a "Lesson" to section "1" and I fill the form with:
+ | Name | Test lesson name |
+ And I follow "Test lesson name"
+ And I follow "Add a question page"
+ And I set the field "Select a question type" to "Multichoice"
+ And I press "Add a question page"
+ And I set the following fields to these values:
+ | Page title | Multichoice question |
+ | Page contents | What animal is an amphibian? |
+ | id_answer_editor_0 | Frog |
+ | id_response_editor_0 | Correct answer |
+ | id_jumpto_0 | Next page |
+ | id_score_0 | 1 |
+ | id_answer_editor_1 | Cat |
+ | id_response_editor_1 | Incorrect answer |
+ | id_jumpto_1 | This page |
+ | id_score_1 | 0 |
+ | id_answer_editor_2 | Dog |
+ | id_response_editor_2 | Incorrect answer |
+ | id_jumpto_2 | This page |
+ | id_score_2 | 0 |
+ And I click on "Image" "button" in the "#fitem_id_answer_editor_2" "css_element"
+ And I click on "Browse repositories..." "button"
+ And I click on "Private files" "link"
+ And I click on "moodle_logo.jpg" "link"
+ And I click on "Select this file" "button"
+ And I set the field "Describe this image for someone who cannot see it" to "It's the logo"
+ And I click on "Save image" "button"
+ And I press "Save page"
+ And I set the field "qtype" to "Question"
+ And I set the field "Select a question type" to "True/false"
+ And I press "Add a question page"
+ And I set the following fields to these values:
+ | Page title | Next question |
+ | Page contents | Paper is made from trees. |
+ | id_answer_editor_0 | True |
+ | id_response_editor_0 | Correct |
+ | id_jumpto_0 | Next page |
+ | id_answer_editor_1 | False |
+ | id_response_editor_1 | Wrong |
+ | id_jumpto_1 | This page |
+ And I click on "Image" "button" in the "#fitem_id_response_editor_0" "css_element"
+ And I click on "Browse repositories..." "button"
+ And I click on "Private files" "link"
+ And I click on "moodle_logo.jpg" "link"
+ And I click on "Select this file" "button"
+ And I set the field "Describe this image for someone who cannot see it" to "It's the logo"
+ And I click on "Save image" "button"
+ And I press "Save page"
+ And I log out
+ And I log in as "student1"
+ And I follow "Course 1"
+ When I follow "Test lesson name"
+ Then I should see "What animal is an amphibian?"
+ And "//img[contains(@src, 'pluginfile.php')]" "xpath_element" should exist in the ".answeroption" "css_element"
+ And "//img[contains(@src, 'moodle_logo.jpg')]" "xpath_element" should exist in the ".answeroption" "css_element"
+ And I set the following fields to these values:
+ | Cat | 1 |
+ And I press "Submit"
+ And I should see "Incorrect answer"
+ And I press "Continue"
+ And I should see "Paper is made from trees."
+ And I set the following fields to these values:
+ | True | 1 |
+ And I press "Submit"
+ And I should see "Correct"
+ And I should not see "Wrong"
+ And "//img[contains(@src, 'pluginfile.php')]" "xpath_element" should exist in the ".correctanswer" "css_element"
+ And "//img[contains(@src, 'moodle_logo.jpg')]" "xpath_element" should exist in the ".correctanswer" "css_element"
+ And I press "Continue"
+ And I should see "Congratulations - end of lesson reached"
+ And I should see "Your score is 1 (out of 2)."
diff --git a/mod/lesson/tests/fixtures/moodle_logo.jpg b/mod/lesson/tests/fixtures/moodle_logo.jpg
new file mode 100644
index 00000000000..f2d536558a5
Binary files /dev/null and b/mod/lesson/tests/fixtures/moodle_logo.jpg differ