Permalink
Browse files

MDL-27446 Backup - added answers 'jumpto' conversion to moodle1 conve…

…rter for

lesson
  • Loading branch information...
1 parent b7119f4 commit 486e889262680d42de1c0b7e83afad950456a4d4 @nebgor nebgor committed with mudrd8mz Jun 9, 2011
Showing with 30 additions and 4 deletions.
  1. +30 −4 mod/lesson/backup/moodle1/lib.php
@@ -30,6 +30,8 @@
* Lesson conversion handler
*/
class moodle1_mod_lesson_handler extends moodle1_mod_handler {
+ // @var array of answers, when there are more that 4 answers, we need to fix <jumpto>.
+ protected $answers;
/** @var moodle1_file_manager */
protected $fileman = null;
@@ -68,6 +70,9 @@ public function get_paths() {
),
)
),
+ new convert_path(
+ 'lesson_answers', '/MOODLE_BACKUP/COURSE/MODULES/MOD/LESSON/PAGES/PAGE/ANSWERS'
+ ),
new convert_path(
'lesson_answer', '/MOODLE_BACKUP/COURSE/MODULES/MOD/LESSON/PAGES/PAGE/ANSWERS/ANSWER',
array(
@@ -146,8 +151,6 @@ public function process_lesson_page($data) {
$this->xmlwriter->full_tag($field, $value);
}
}
-
- $this->xmlwriter->begin_tag('answers');
}
/**
@@ -167,14 +170,37 @@ public function process_lesson_answer($data) {
$data['responseformat'] = FORMAT_HTML;
}
- $this->write_xml('answer', $data, array('/answer/id'));
+ // buffer for conversion of <jumpto> in line with
+ // upgrade step 2010121400 from mod/lesson/db/upgrade.php
+ $this->answers[] = $data;
+ }
+
+ public function on_lesson_answers_end() {
+ $this->xmlwriter->begin_tag('answers');
+ if (count($this->answers) > 3) {
+ if ($this->answers[0]['jumpto'] !== '0' || $this->answers[1]['jumpto'] !== '0') {
+ if ($this->answers[2]['jumpto'] !== '0') {
+ $this->answers[0]['jumpto'] = $this->answers[2]['jumpto'];
+ $this->answers[2]['jumpto'] = '0';
+ }
+ if ($this->answers[3]['jumpto'] !== '0') {
+ $this->answers[1]['jumpto'] = $this->answers[3]['jumpto'];
+ $this->answers[3]['jumpto'] = '0';
+ }
+ }
+ }
+
+ foreach ($this->answers as $data) {
+ $this->write_xml('answer', $data, array('/answer/id'));
+ }
+ unset($this->answers);
+ $this->xmlwriter->end_tag('answers');
}
/**
* This is executed when we reach the closing </pages>tag of our 'page' path
*/
public function on_lesson_page_end(){
- $this->xmlwriter->end_tag('answers');
$this->xmlwriter->end_tag('page');
}

0 comments on commit 486e889

Please sign in to comment.