mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
MDL-38505 Permit lesson to import images in question text
This commit is contained in:
parent
d2aa53be1b
commit
efbe07b03c
@ -285,6 +285,7 @@ class qformat_default {
|
||||
var $displayerrors = true;
|
||||
var $category = null;
|
||||
var $questionids = array();
|
||||
protected $importcontext = null;
|
||||
var $qtypeconvert = array('numerical' => LESSON_PAGE_NUMERICAL,
|
||||
'multichoice' => LESSON_PAGE_MULTICHOICE,
|
||||
'truefalse' => LESSON_PAGE_TRUEFALSE,
|
||||
@ -297,6 +298,10 @@ class qformat_default {
|
||||
return false;
|
||||
}
|
||||
|
||||
function set_importcontext($context) {
|
||||
$this->importcontext = $context;
|
||||
}
|
||||
|
||||
function importpreprocess() {
|
||||
// Does any pre-processing that may be desired
|
||||
return true;
|
||||
@ -410,6 +415,15 @@ class qformat_default {
|
||||
|
||||
$this->questionids[] = $question->id;
|
||||
|
||||
// Import images in question text.
|
||||
if (isset($question->questiontextitemid)) {
|
||||
$questiontext = file_save_draft_area_files($question->questiontextitemid,
|
||||
$this->importcontext->id, 'mod_lesson', 'page_contents', $newpageid,
|
||||
null , $question->questiontext);
|
||||
// Update content with recoded urls.
|
||||
$DB->set_field("lesson_pages", "contents", $questiontext, array("id" => $newpageid));
|
||||
}
|
||||
|
||||
// Now to save all the answers and type-specific options
|
||||
|
||||
$question->lessonid = $lesson->id; // needed for foreign key
|
||||
@ -603,7 +617,12 @@ class qformat_default {
|
||||
protected function format_question_text($question) {
|
||||
$formatoptions = new stdClass();
|
||||
$formatoptions->noclean = true;
|
||||
return html_to_text(format_text($question->questiontext,
|
||||
// The html_to_text call strips out all URLs, but format_text complains
|
||||
// if it finds @@PLUGINFILE@@ tokens. So, we need to replace
|
||||
// @@PLUGINFILE@@ with a real URL, but it doesn't matter what.
|
||||
// We use http://example.com/.
|
||||
$text = str_replace('@@PLUGINFILE@@/', 'http://example.com/', $question->questiontext);
|
||||
return html_to_text(format_text($text,
|
||||
$question->questiontextformat, $formatoptions), 0, false);
|
||||
}
|
||||
|
||||
|
@ -82,6 +82,8 @@ if ($data = $mform->get_data()) {
|
||||
require_once($formatclassfile);
|
||||
$format = new $formatclass();
|
||||
|
||||
$format->set_importcontext($context);
|
||||
|
||||
// Do anything before that we need to
|
||||
if (! $format->importpreprocess()) {
|
||||
print_error('preprocesserror', 'lesson');
|
||||
|
Loading…
x
Reference in New Issue
Block a user