Permalink
Browse files

backup now actually backs up. Includes all of our database changes

  • Loading branch information...
1 parent 9814a0e commit 493c24e5a8d0f135126b03e89d4036ec47ce232c michaelpenne committed Nov 1, 2004
Showing with 200 additions and 15 deletions.
  1. +200 −15 mod/lesson/backuplib.php
View
@@ -1,19 +1,22 @@
<?PHP //$Id$
+
//This php script contains all the stuff to backup/restore
//lesson mods
//This is the "graphical" structure of the lesson mod:
//
- // lesson ----------------------------|
- // (CL,pk->id) |
+ // lesson_default lesson ----------------------------|--------------------------|--------------------------|
+ // (UL, pk->id,fk->courseid) (CL,pk->id) | | |
+ // | | | |
+ // | lesson_grades lesson_high_scores lesson_timer
+ // | (UL, pk->id,fk->lessonid) (UL, pk->id,fk->lessonid) (UL, pk->id,fk->lessonid)
+ // |
+ // |
+ // lesson_pages---------------------------|
+ // (CL,pk->id,fk->lessonid) |
// | |
- // | lesson_grades
- // | (UL, pk->id,fk->lessonid)
- // lesson_pages
- // (CL,pk->id,fk->lessonid)
- // |
- // |
- // |
+ // | lesson_branch
+ // | (UL, pk->id,fk->pageid)
// lesson_answers
// (CL,pk->id,fk->pageid)
// |
@@ -48,26 +51,57 @@ function lesson_backup_mods($bf, $preferences) {
fwrite ($bf,full_tag("ID",4,false,$lesson->id));
fwrite ($bf,full_tag("MODTYPE",4,false,"lesson"));
fwrite ($bf,full_tag("NAME",4,false,$lesson->name));
+ fwrite ($bf,full_tag("PRACTICE",4,false,$lesson->practice));
+ fwrite ($bf,full_tag("MODATTEMPTS",4,false,$lesson->modattempts));
+ fwrite ($bf,full_tag("PASSWORD",4,false,$lesson->password));
+ fwrite ($bf,full_tag("USEPASSWORD",4,false,$lesson->usepassword));
fwrite ($bf,full_tag("GRADE",4,false,$lesson->grade));
+ fwrite ($bf,full_tag("CUSTOM",4,false,$lesson->custom));
+ fwrite ($bf,full_tag("ONGOING",4,false,$lesson->ongoing));
fwrite ($bf,full_tag("USEMAXGRADE",4,false,$lesson->usemaxgrade));
fwrite ($bf,full_tag("MAXANSWERS",4,false,$lesson->maxanswers));
fwrite ($bf,full_tag("MAXATTEMPTS",4,false,$lesson->maxattempts));
+ fwrite ($bf,full_tag("REVIEW",4,false,$lesson->review));
fwrite ($bf,full_tag("NEXTPAGEDEFAULT",4,false,$lesson->nextpagedefault));
fwrite ($bf,full_tag("MINQUESTIONS",4,false,$lesson->minquestions));
fwrite ($bf,full_tag("MAXPAGES",4,false,$lesson->maxpages));
+ fwrite ($bf,full_tag("TIMED",4,false,$lesson->timed));
+ fwrite ($bf,full_tag("MAXTIME",4,false,$lesson->maxtime));
fwrite ($bf,full_tag("RETAKE",4,false,$lesson->retake));
+ fwrite ($bf,full_tag("TREE",4,false,$lesson->tree));
+ fwrite ($bf,full_tag("SLIDESHOW",4,false,$lesson->slideshow));
+ fwrite ($bf,full_tag("WIDTH",4,false,$lesson->width));
+ fwrite ($bf,full_tag("HEIGHT",4,false,$lesson->height));
+ fwrite ($bf,full_tag("BGCOLOR",4,false,$lesson->bgcolor));
+ fwrite ($bf,full_tag("DISPLAYLEFT",4,false,$lesson->displayleft));
+ fwrite ($bf,full_tag("HIGHSCORES",4,false,$lesson->highscores));
+ fwrite ($bf,full_tag("MAXHIGHSCORES",4,false,$lesson->maxhighscores));
fwrite ($bf,full_tag("AVAILABLE",4,false,$lesson->available));
fwrite ($bf,full_tag("DEADLINE",4,false,$lesson->deadline));
fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$lesson->timemodified));
+
//Now we backup lesson pages
$status = backup_lesson_pages($bf,$preferences,$lesson->id);
- //if we've selected to backup users info, then backup grades
+ //if we've selected to backup users info, then backup grades, high scores, and timer info
if ($status) {
if ($preferences->mods["lesson"]->userinfo) {
- $status = backup_lesson_grades($bf, $preferences, $lesson->id);
+ if(!backup_lesson_grades($bf, $preferences, $lesson->id)) {
+ return false;
+ }
+ if (!backup_lesson_high_scores($bf, $preferences, $lesson->id)) {
+ return false;
+ }
+ if (!backup_lesson_timer($bf, $preferences, $lesson->id)) {
+ return false;
+ }
}
- //End mod
- $status =fwrite ($bf,end_tag("MOD",3,true));
+ // back up the default for the course. There might not be one, but if there
+ // is, there will only be one.
+ $status = backup_lesson_default($bf,$preferences);
+ //End mod
+ if ($status) {
+ $status =fwrite ($bf,end_tag("MOD",3,true));
+ }
}
}
}
@@ -93,12 +127,20 @@ function backup_lesson_pages ($bf, $preferences, $lessonid) {
fwrite ($bf,full_tag("PAGEID",6,false,$page->id)); // needed to fix (absolute) jumps
fwrite ($bf,full_tag("QTYPE",6,false,$page->qtype));
fwrite ($bf,full_tag("QOPTION",6,false,$page->qoption));
+ fwrite ($bf,full_tag("LAYOUT",6,false,$page->layout));
+ fwrite ($bf,full_tag("DISPLAY",6,false,$page->display));
fwrite ($bf,full_tag("TIMECREATED",6,false,$page->timecreated));
fwrite ($bf,full_tag("TIMEMODIFIED",6,false,$page->timemodified));
fwrite ($bf,full_tag("TITLE",6,false,$page->title));
fwrite ($bf,full_tag("CONTENTS",6,false,$page->contents));
//Now we backup lesson answers for this page
$status = backup_lesson_answers($bf, $preferences, $page->id);
+ // backup branch table info for branch tables.
+ if ($status && $preferences->mods["lesson"]->userinfo) {
+ if (!backup_lesson_branch($bf, $preferences, $page->id)) {
+ return false;
+ }
+ }
//End of page
$status =fwrite ($bf,end_tag("PAGE",5,true));
// move to the next (logical) page
@@ -137,12 +179,14 @@ function backup_lesson_answers($bf,$preferences,$pageno) {
//Start answer
$status =fwrite ($bf,start_tag("ANSWER",7,true));
//Print answer contents
+ fwrite ($bf,full_tag("ID",8,false,$answer->id));
fwrite ($bf,full_tag("JUMPTO",8,false,$answer->jumpto));
fwrite ($bf,full_tag("GRADE",8,false,$answer->grade));
+ fwrite ($bf,full_tag("SCORE",8,false,$answer->score));
fwrite ($bf,full_tag("FLAGS",8,false,$answer->flags));
fwrite ($bf,full_tag("TIMECREATED",8,false,$answer->timecreated));
fwrite ($bf,full_tag("TIMEMODIFIED",8,false,$answer->timemodified));
- fwrite ($bf,full_tag("ANSWERTEXT",8,false,$answer->answer));
+ fwrite ($bf,full_tag("ANSWERTEXT",8,false,$answer->answer)); // THIS MIGHT BE WRONG, IT IS ANSWER IN DB MARKN
fwrite ($bf,full_tag("RESPONSE",8,false,$answer->response));
//Now we backup any lesson attempts (if student data required)
if ($preferences->mods["lesson"]->userinfo) {
@@ -176,7 +220,8 @@ function backup_lesson_attempts ($bf,$preferences,$answerid) {
//Print attempt contents
fwrite ($bf,full_tag("USERID",6,false,$attempt->userid));
fwrite ($bf,full_tag("RETRY",6,false,$attempt->retry));
- fwrite ($bf,full_tag("CORRECT",6,false,$attempt->correct));
+ fwrite ($bf,full_tag("CORRECT",6,false,$attempt->correct));
+ fwrite ($bf,full_tag("USERANSWER",6,false,$attempt->useranswer));
fwrite ($bf,full_tag("TIMESEEN",6,false,$attempt->timeseen));
//End attempt
$status =fwrite ($bf,end_tag("ATTEMPT",5,true));
@@ -218,6 +263,146 @@ function backup_lesson_grades ($bf,$preferences,$lessonid) {
}
return $status;
}
+
+ //Backup lesson_branch contents (executed from backup_lesson_pages)
+ function backup_lesson_branch($bf,$preferences,$pageno) {
+
+ global $CFG;
+
+ $status = true;
+
+ // get the answers in a set order, the id order
+ $lesson_branch = get_records("lesson_branch", "pageid", $pageno, "id");
+
+ //If there is lesson_branch
+ if ($lesson_branch) {
+ //Write start tag
+ $status =fwrite ($bf,start_tag("BRANCHES",6,true));
+ //Iterate over each element
+ foreach ($lesson_branch as $branch) {
+ //Start branch
+ $status =fwrite ($bf,start_tag("BRANCH",7,true));
+ //Print answer contents
+ fwrite ($bf,full_tag("LESSONID",8,false,$branch->lessonid));
+ fwrite ($bf,full_tag("USERID",8,false,$branch->userid));
+ fwrite ($bf,full_tag("PAGEID",8,false,$branch->pageid));
+ fwrite ($bf,full_tag("RETRY",8,false,$branch->retry));
+ fwrite ($bf,full_tag("FLAG",8,false,$branch->flag));
+ fwrite ($bf,full_tag("TIMESEEN",8,false,$branch->timeseen));
+ // END BRANCH
+ $status =fwrite ($bf,end_tag("BRANCH",7,true));
+ }
+ //Write end tag
+ $status =fwrite ($bf,end_tag("BRANCHES",6,true));
+ }
+ return $status;
+ }
+
+ //Backup lesson_timer contents (executed from backup_lesson_mods)
+ function backup_lesson_timer ($bf,$preferences,$lessonid) {
+
+ global $CFG;
+
+ $status = true;
+
+ $times = get_records("lesson_timer", "lessonid", $lessonid);
+
+ //If there is times
+ if ($times) {
+ //Write start tag
+ $status =fwrite ($bf,start_tag("TIMES",8,true));
+ //Iterate over each time
+ foreach ($times as $time) {
+ //Start time
+ $status =fwrite ($bf,start_tag("TIME",9,true));
+ //Print time contents
+ fwrite ($bf,full_tag("LESSONID",10,false,$time->lessonid));
+ fwrite ($bf,full_tag("USERID",10,false,$time->userid));
+ fwrite ($bf,full_tag("STARTTIME",10,false,$time->starttime));
+ fwrite ($bf,full_tag("LESSONTIME",10,false,$time->lessontime));
+ //End comment
+ $status =fwrite ($bf,end_tag("TIME",9,true));
+ }
+ //Write end tag
+ $status =fwrite ($bf,end_tag("TIMES",8,true));
+ }
+ return $status;
+ }
+
+ // backup lesson_high_score contents (executed from backup_lesson_mods)
+ function backup_lesson_high_scores($bf, $preferences, $lessonid) {
+ global $CFG;
+
+ $status = true;
+
+ $highscores = get_records("lesson_high_scores", "lessonid", $lessonid);
+
+ //If there is highscores
+ if ($highscores) {
+ //Write start tag
+ $status =fwrite ($bf,start_tag("HIGHSCORES",8,true));
+ //Iterate over each highscore
+ foreach ($highscores as $highscore) {
+ //Start highscore
+ $status =fwrite ($bf,start_tag("HIGHSCORE",9,true));
+ //Print highscore contents
+ fwrite ($bf,full_tag("LESSONID",10,false,$highscore->lessonid));
+ fwrite ($bf,full_tag("USERID",10,false,$highscore->userid));
+ fwrite ($bf,full_tag("GRADEID",10,false,$highscore->gradeid));
+ fwrite ($bf,full_tag("NICKNAME",10,false,$highscore->nickname));
+ //End comment
+ $status =fwrite ($bf,end_tag("HIGHSCORE",9,true));
+ }
+ //Write end tag
+ $status =fwrite ($bf,end_tag("HIGHSCORES",8,true));
+ }
+ return $status;
+ }
+
+ // backup lesson_default contents (executed from backup_lesson_mods)
+ function backup_lesson_default ($bf,$preferences) {
+ global $CFG;
+
+ $status = true;
+
+ //only one default record per course
+ $default = get_record("lesson_default", "course", $preferences->backup_course);
+ if ($default) {
+ //Start mod
+ $status =fwrite ($bf,start_tag("DEFAULTS",3,true));
+ $status =fwrite ($bf,start_tag("DEFAULT",4,true));
+ //Print default data
+ fwrite ($bf,full_tag("PRACTICE",5,false,$default->practice));
+ fwrite ($bf,full_tag("MODATTEMPTS",5,false,$default->modattempts));
+ fwrite ($bf,full_tag("PASSWORD",5,false,$default->password));
+ fwrite ($bf,full_tag("USEPASSWORD",5,false,$default->usepassword));
+ fwrite ($bf,full_tag("GRADE",5,false,$default->grade));
+ fwrite ($bf,full_tag("CUSTOM",5,false,$default->custom));
+ fwrite ($bf,full_tag("ONGOING",5,false,$default->ongoing));
+ fwrite ($bf,full_tag("USEMAXGRADE",5,false,$default->usemaxgrade));
+ fwrite ($bf,full_tag("MAXANSWERS",5,false,$default->maxanswers));
+ fwrite ($bf,full_tag("MAXATTEMPTS",5,false,$default->maxattempts));
+ fwrite ($bf,full_tag("REVIEW",5,false,$default->review));
+ fwrite ($bf,full_tag("NEXTPAGEDEFAULT",5,false,$default->nextpagedefault));
+ fwrite ($bf,full_tag("MINQUESTIONS",5,false,$default->minquestions));
+ fwrite ($bf,full_tag("MAXPAGES",5,false,$default->maxpages));
+ fwrite ($bf,full_tag("TIMED",5,false,$default->timed));
+ fwrite ($bf,full_tag("MAXTIME",5,false,$default->maxtime));
+ fwrite ($bf,full_tag("RETAKE",5,false,$default->retake));
+ fwrite ($bf,full_tag("TREE",5,false,$default->tree));
+ fwrite ($bf,full_tag("SLIDESHOW",5,false,$default->slideshow));
+ fwrite ($bf,full_tag("WIDTH",5,false,$default->width));
+ fwrite ($bf,full_tag("HEIGHT",5,false,$default->height));
+ fwrite ($bf,full_tag("BGCOLOR",5,false,$default->bgcolor));
+ fwrite ($bf,full_tag("DISPLAYLEFT",5,false,$default->displayleft));
+ fwrite ($bf,full_tag("HIGHSCORES",5,false,$default->highscores));
+ fwrite ($bf,full_tag("MAXHIGHSCORES",5,false,$default->maxhighscores));
+ $status =fwrite ($bf,end_tag("DEFAULT",4,true));
+ $status =fwrite ($bf,end_tag("DEFAULTS",3,true));
+ }
+ return $status;
+ }
+
//Return an array of info (name,value)
function lesson_check_backup_mods($course,$user_data=false,$backup_unique_code) {
//First the course data

0 comments on commit 493c24e

Please sign in to comment.