mirror of
https://github.com/moodle/moodle.git
synced 2025-03-09 18:30:03 +01:00
Merge branch 'MDL-33424' of git://github.com/jmvedrine/moodle
This commit is contained in:
commit
e18c12c190
@ -1040,6 +1040,24 @@ class moodle1_question_bank_handler extends moodle1_xml_handler {
|
||||
/** @var array holds the instances of qtype specific conversion handlers */
|
||||
private $qtypehandlers = null;
|
||||
|
||||
/**
|
||||
* Return the file manager instance used.
|
||||
*
|
||||
* @return moodle1_file_manager
|
||||
*/
|
||||
public function get_file_manager() {
|
||||
return $this->fileman;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the information about the question category context being currently parsed
|
||||
*
|
||||
* @return array with keys contextid, contextlevel and contextinstanceid
|
||||
*/
|
||||
public function get_current_category_context() {
|
||||
return $this->currentcategory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers path that are not qtype-specific
|
||||
*/
|
||||
@ -1191,6 +1209,17 @@ class moodle1_question_bank_handler extends moodle1_xml_handler {
|
||||
$data['generalfeedbackformat'] = FORMAT_HTML;
|
||||
}
|
||||
|
||||
// Migrate files in questiontext.
|
||||
$this->fileman->contextid = $this->currentcategory['contextid'];
|
||||
$this->fileman->component = 'question';
|
||||
$this->fileman->filearea = 'questiontext';
|
||||
$this->fileman->itemid = $data['id'];
|
||||
$data['questiontext'] = moodle1_converter::migrate_referenced_files($data['questiontext'], $this->fileman);
|
||||
|
||||
// Migrate files in generalfeedback.
|
||||
$this->fileman->filearea = 'generalfeedback';
|
||||
$data['generalfeedback'] = moodle1_converter::migrate_referenced_files($data['generalfeedback'], $this->fileman);
|
||||
|
||||
// replay the upgrade step 2010080901 - updating question image
|
||||
if (!empty($data['image'])) {
|
||||
if (textlib::substr(textlib::strtolower($data['image']), 0, 7) == 'http://') {
|
||||
@ -1736,12 +1765,41 @@ abstract class moodle1_qtype_handler extends moodle1_plugin_handler {
|
||||
foreach ($answers as $elementname => $elements) {
|
||||
foreach ($elements as $element) {
|
||||
$answer = $this->convert_answer($element, $qtype);
|
||||
// Migrate images in answertext.
|
||||
if ($answer['answerformat'] == FORMAT_HTML) {
|
||||
$answer['answertext'] = $this->migrate_files($answer['answertext'], 'question', 'answer', $answer['id']);
|
||||
}
|
||||
// Migrate images in feedback.
|
||||
if ($answer['feedbackformat'] == FORMAT_HTML) {
|
||||
$answer['feedback'] = $this->migrate_files($answer['feedback'], 'question', 'answerfeedback', $answer['id']);
|
||||
}
|
||||
$this->write_xml('answer', $answer, array('/answer/id'));
|
||||
}
|
||||
}
|
||||
$this->xmlwriter->end_tag('answers');
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate files belonging to one qtype plugin text field.
|
||||
*
|
||||
* @param array $text the html fragment containing references to files
|
||||
* @param string $component the component for restored files
|
||||
* @param string $filearea the file area for restored files
|
||||
* @param int $itemid the itemid for restored files
|
||||
*
|
||||
* @return string the text for this field, after files references have been processed
|
||||
*/
|
||||
protected function migrate_files($text, $component, $filearea, $itemid) {
|
||||
$context = $this->qbankhandler->get_current_category_context();
|
||||
$fileman = $this->qbankhandler->get_file_manager();
|
||||
$fileman->contextid = $context['contextid'];
|
||||
$fileman->component = $component;
|
||||
$fileman->filearea = $filearea;
|
||||
$fileman->itemid = $itemid;
|
||||
$text = moodle1_converter::migrate_referenced_files($text, $fileman);
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the grouped numerical_units structure
|
||||
*
|
||||
@ -1900,7 +1958,8 @@ abstract class moodle1_qtype_handler extends moodle1_plugin_handler {
|
||||
if ($qtype !== 'multichoice') {
|
||||
$new['answerformat'] = FORMAT_PLAIN;
|
||||
} else {
|
||||
$new['answerformat'] = FORMAT_MOODLE;
|
||||
$new['answertext'] = text_to_html($new['answertext'], false, false, true);
|
||||
$new['answerformat'] = FORMAT_HTML;
|
||||
}
|
||||
|
||||
if ($CFG->texteditors !== 'textarea') {
|
||||
|
@ -76,6 +76,8 @@ class moodle1_qtype_match_handler extends moodle1_qtype_handler {
|
||||
$match['questiontextformat'] = $data['oldquestiontextformat'];
|
||||
}
|
||||
|
||||
$match['questiontext'] = $this->migrate_files(
|
||||
$match['questiontext'], 'qtype_match', 'subquestion', $match['id']);
|
||||
$this->write_xml('match', $match, array('/match/id'));
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ class moodle1_qtype_multichoice_handler extends moodle1_qtype_handler {
|
||||
'answernumbering' => 'abc',
|
||||
));
|
||||
}
|
||||
$this->write_multichoice($data['multichoice'], $data['oldquestiontextformat']);
|
||||
$this->write_multichoice($data['multichoice'], $data['oldquestiontextformat'], $data['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,8 +73,9 @@ class moodle1_qtype_multichoice_handler extends moodle1_qtype_handler {
|
||||
*
|
||||
* @param array $multichoices the grouped structure
|
||||
* @param int $oldquestiontextformat - {@see moodle1_question_bank_handler::process_question()}
|
||||
* @param int $questionid question id
|
||||
*/
|
||||
protected function write_multichoice(array $multichoices, $oldquestiontextformat) {
|
||||
protected function write_multichoice(array $multichoices, $oldquestiontextformat, $questionid) {
|
||||
global $CFG;
|
||||
|
||||
// the grouped array is supposed to have just one element - let us use foreach anyway
|
||||
@ -101,6 +102,13 @@ class moodle1_qtype_multichoice_handler extends moodle1_qtype_handler {
|
||||
$multichoice['incorrectfeedbackformat'] = $oldquestiontextformat;
|
||||
}
|
||||
|
||||
$multichoice['correctfeedback'] = $this->migrate_files(
|
||||
$multichoice['correctfeedback'], 'question', 'correctfeedback', $questionid);
|
||||
$multichoice['partiallycorrectfeedback'] = $this->migrate_files(
|
||||
$multichoice['partiallycorrectfeedback'], 'question', 'partiallycorrectfeedback', $questionid);
|
||||
$multichoice['incorrectfeedback'] = $this->migrate_files(
|
||||
$multichoice['incorrectfeedback'], 'question', 'incorrectfeedback', $questionid);
|
||||
|
||||
$this->write_xml('multichoice', $multichoice, array('/multichoice/id'));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user