Permalink
Browse files

MDL-27819 Backup - fixed extra answers/jump data.

	- fixed unset causing missing property
	- fixed answers empty notice, allowed for page with no answers.
  • Loading branch information...
1 parent 5c5f711 commit 914bfea2457cce5bd243f975bbcda8dc95221e95 @nebgor nebgor committed with stronk7 Jun 16, 2011
Showing with 19 additions and 14 deletions.
  1. +19 −14 mod/lesson/backup/moodle1/lib.php
@@ -209,6 +209,8 @@ public function on_lesson_page_end() {
$this->prevpageid = $pg1->id;
array_shift($this->pages); //throw written n-1th page
}
+ $this->answers = array(); //clear answers for the page ending. do not unset, object property will be missing.
+ $this->page = null;
}
public function on_lesson_pages_end() {
@@ -225,8 +227,7 @@ public function on_lesson_pages_end() {
//reset
unset($this->pages);
$this->prevpageid = 0;
- unset($this->answers);
- unset($this->page);
+
}
/**
@@ -272,22 +273,26 @@ protected function write_single_page_xml($page, $prevpageid=0, $nextpageid=0) {
$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';
+
+ $numanswers = count($answers);
+ if ($numanswers) { //if there are any answers (possible there are none!)
+ if ($numanswers > 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 ($answers as $data) {
+ $this->write_xml('answer', $data, array('/answer/id'));
+ }
}
- foreach ($answers as $data) {
- $this->write_xml('answer', $data, array('/answer/id'));
- }
$this->xmlwriter->end_tag('answers');
// answers is now closed for current page. Ending the page.

0 comments on commit 914bfea

Please sign in to comment.