Permalink
Browse files

MDL-27819 backup - added nextpageid and prevpageid elements to lesson…

… moodle1 backup conversion to 2.x
  • Loading branch information...
1 parent 84a5f2d commit 496a576aa9c84efcda2d38dc0f93b9bfc5d0ae91 @nebgor nebgor committed with stronk7 Jun 13, 2011
Showing with 77 additions and 36 deletions.
  1. +77 −36 mod/lesson/backup/moodle1/lib.php
@@ -33,6 +33,11 @@ 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 stdClass a page object of the current page
+ protected $page;
+ // @var array of page objects to store entire pages, to help generate nextpageid and prevpageid in data
+ protected $pages;
+
/** @var moodle1_file_manager */
protected $fileman = null;
@@ -67,11 +72,13 @@ public function get_paths() {
array(
'newfields' => array(
'contentsformat' => FORMAT_MOODLE,
+ 'nextpageid' => 0, //set to default to the next sequencial page in process_lesson_page()
+ 'prevpageid' => 0
),
)
),
new convert_path(
- 'lesson_answers', '/MOODLE_BACKUP/COURSE/MODULES/MOD/LESSON/PAGES/PAGE/ANSWERS'
+ 'lesson_pages', '/MOODLE_BACKUP/COURSE/MODULES/MOD/LESSON/PAGES'
),
new convert_path(
'lesson_answer', '/MOODLE_BACKUP/COURSE/MODULES/MOD/LESSON/PAGES/PAGE/ANSWERS/ANSWER',
@@ -121,17 +128,18 @@ public function process_lesson($data) {
'modulename' => 'lesson', 'contextid' => $contextid));
$this->xmlwriter->begin_tag('lesson', array('id' => $instanceid));
+ unset($data['id']);
foreach ($data as $field => $value) {
- if ($field <> 'id') {
- $this->xmlwriter->full_tag($field, $value);
- }
+ $this->xmlwriter->full_tag($field, $value);
}
- $this->xmlwriter->begin_tag('pages');
-
return $data;
}
+ public function on_lesson_pages_start() {
+ $this->xmlwriter->begin_tag('pages');
+ }
+
/**
* This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/LESSON/PAGES/PAGE
* data available
@@ -145,12 +153,11 @@ public function process_lesson_page($data) {
$data['contentsformat'] = FORMAT_HTML;
}
- $this->xmlwriter->begin_tag('page', array('id' => $data['pageid']));
- foreach ($data as $field => $value) {
- if ($field <> 'id') {
- $this->xmlwriter->full_tag($field, $value);
- }
- }
+ // store page in pages
+ $this->page = new stdClass();
+ $this->page->id = $data['pageid'];
+ unset($data['pageid']);
+ $this->page->data = $data;
}
/**
@@ -175,41 +182,75 @@ public function process_lesson_answer($data) {
$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';
+ public function on_lesson_page_end() {
+ $this->page->answers = $this->answers;
+ unset($this->answers);
+ $this->pages[] = $this->page;
+ unset($this->page);
+ }
+
+ public function on_lesson_pages_end() {
+ $prevpageid = 0;
+
+ foreach ($this->pages as $page) {
+ $curpageid = $page->id;
+ // if there are more pages, set nextpageid
+ if (isset($this->pages[1])) {
+ $nextpage = $this->pages[1];
+ $nextpageid = $nextpage->id;
+ } else {
+ //theres only one page left
+ $nextpageid = 0;
+ }
+ //mince nextpageid and prevpageid
+ $page->data['nextpageid'] = $nextpageid;
+ $page->data['prevpageid'] = $prevpageid;
+
+ array_shift($this->pages);
+
+ // write out each page data
+ $this->xmlwriter->begin_tag('page', array('id' => $page->id));
+
+ foreach ($page->data as $field => $value) {
+ $this->xmlwriter->full_tag($field, $value);
+ }
+
+ //effectively on_lesson_answers_end(), where we write out answers for current page.
+ $answers = $page->answers;
+
+ $this->xmlwriter->begin_tag('answers');
+ if (count($answers) > 3) {
+ if ($answers[0]['jumpto'] !== '0' || $answers[1]['jumpto'] !== '0') {
+ if ($answers[2]['jumpto'] !== '0') {
+ $answers[0]['jumpto'] = $answers[2]['jumpto'];
+ $answers[2]['jumpto'] = '0';
+ }
+ if ($answers[3]['jumpto'] !== '0') {
+ $answers[1]['jumpto'] = $answers[3]['jumpto'];
+ $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');
- }
+ foreach ($answers as $data) {
+ $this->write_xml('answer', $data, array('/answer/id'));
+ }
+ $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('page');
+ // answers is now closed for current page. Ending the page.
+ $this->xmlwriter->end_tag('page');
+
+ // set prevpageid
+ $prevpageid = $curpageid;
+ }
+ $this->xmlwriter->end_tag('pages');
}
/**
* This is executed when we reach the closing </MOD> tag of our 'lesson' path
*/
public function on_lesson_end() {
// finish writing lesson.xml
- $this->xmlwriter->end_tag('pages');
$this->xmlwriter->end_tag('lesson');
$this->xmlwriter->end_tag('activity');
$this->close_xml_writer();

0 comments on commit 496a576

Please sign in to comment.