Skip to content

Commit

Permalink
MDL-35851 lesson: Handle importing questions into an empty lesson.
Browse files Browse the repository at this point in the history
Also - make sure the page we are updating belongs to the lesson.
  • Loading branch information
Damyon Wiese committed Jul 18, 2013
1 parent 9f837ac commit 20ea7f2
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions mod/lesson/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ function importprocess($filename, $lesson, $pageid) {
$addquestionontop = true;
$updatelessonpage = $DB->get_record('lesson_pages', array('lessonid' => $lesson->id, 'prevpageid' => 0));
} else {
$updatelessonpage = $DB->get_record('lesson_pages', array('id' => $pageid));
$updatelessonpage = $DB->get_record('lesson_pages', array('lessonid' => $lesson->id, 'id' => $pageid));
}

$unsupportedquestions = 0;
Expand Down Expand Up @@ -432,11 +432,13 @@ function importprocess($filename, $lesson, $pageid) {
break;
}
}
// update the prev links
if ($addquestionontop) {
$DB->set_field("lesson_pages", "prevpageid", $pageid, array("id" => $updatelessonpage->id));
} else {
$DB->set_field("lesson_pages", "prevpageid", $pageid, array("id" => $updatelessonpage->nextpageid));
// Update the prev links if there were existing pages.
if (!empty($updatelessonpage)) {
if ($addquestionontop) {
$DB->set_field("lesson_pages", "prevpageid", $pageid, array("id" => $updatelessonpage->id));
} else {
$DB->set_field("lesson_pages", "prevpageid", $pageid, array("id" => $updatelessonpage->nextpageid));
}
}
if ($unsupportedquestions) {
echo $OUTPUT->notification(get_string('unknownqtypesnotimported', 'lesson', $unsupportedquestions));
Expand Down

0 comments on commit 20ea7f2

Please sign in to comment.