From ea2280282e0f123d6acdab1be0561ed9d8a075df Mon Sep 17 00:00:00 2001 From: stronk7 Date: Sun, 1 Jun 2003 19:38:14 +0000 Subject: [PATCH] Restore surveys COMPLETED. --- backup/mod/survey/restorelib.php | 175 +++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 backup/mod/survey/restorelib.php diff --git a/backup/mod/survey/restorelib.php b/backup/mod/survey/restorelib.php new file mode 100644 index 0000000000..7f429c6801 --- /dev/null +++ b/backup/mod/survey/restorelib.php @@ -0,0 +1,175 @@ +id) |(CL,pk->id,?????) | + // | -------------------- + // | + // ----------------------------------- + // | | + // survey_analysis survey_answers + // (UL,pk->id, fk->survey) (UL,pk->id, fk->survey) + // + // Meaning: pk->primary key field of the table + // fk->foreign key to link with parent + // nt->nested field (recursive data) + // CL->course level info + // UL->user level info + // files->table may have files) + // + //----------------------------------------------------------- + + + function survey_restore_mods($mod,$restore) { + + global $CFG,$db; + + $status = true; + + //Get record from backup_ids + $data = backup_getid($restore->backup_unique_code,$mod->modtype,$mod->id); + + if ($data) { + //We have info, get and unserialize info + //First strip slashes + $temp = stripslashes($data->info); + //Now get completed xmlized object + $info = unserialize($temp); + //traverse_xmlize($info); //Debug + //print_object ($GLOBALS['traverse_array']); //Debug + //$GLOBALS['traverse_array']=""; //Debug + + //Now, build the SURVEY record structure + $survey->course = $restore->course_id; + $survey->template = backup_todb($info['MOD']['#']['TEMPLATE']['0']['#']); + $survey->days = backup_todb($info['MOD']['#']['DAYS']['0']['#']); + $survey->timecreated = backup_todb($info['MOD']['#']['TIMECREATED']['0']['#']); + $survey->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']); + $survey->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); + $survey->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']); + $survey->questions = backup_todb($info['MOD']['#']['QUESTIONS']['0']['#']); + + //The structure is equal to the db, so insert the survey + $newid = insert_record ("survey",$survey); + if ($newid) { + //We have the newid, update backup_ids + backup_putid($restore->backup_unique_code,$mod->modtype, + $mod->id, $newid); + //Now check if want to restore user data and do it. + if ($restore->mods[survey]->userinfo) { + //Restore survey_answers + $status = survey_answers_restore_mods ($newid,$info,$restore); + //Restore survey_analysis + if ($status) { + $status = survey_analysis_restore_mods ($newid,$info,$restore); + } + } + } else { + $status = false; + } + + } else { + $status = false; + } + + return $status; + } + + //This function restores the survey_answers + function survey_answers_restore_mods($survey_id,$info,$restore) { + + global $CFG; + + $status = true; + + //Get the answers array + $answers = $info['MOD']['#']['ANSWERS']['0']['#']['ANSWER']; + + //Iterate over answers + for($i = 0; $i < sizeof($answers); $i++) { + $sub_info = $answers[$i]; + //traverse_xmlize($sub_info); //Debug + //print_object ($GLOBALS['traverse_array']); //Debug + //$GLOBALS['traverse_array']=""; //Debug + + //We'll need this later!! + $oldid = backup_todb($sub_info['#']['ID']['0']['#']); + $olduserid = backup_todb($sub_info['#']['USERID']['0']['#']); + + //Now, build the SURVEY_ANSWERS record structure + $answer->survey = $survey_id; + $answer->userid = backup_todb($sub_info['#']['USERID']['0']['#']); + $answer->question = backup_todb($sub_info['#']['QUESTION']['0']['#']); + $answer->time = backup_todb($sub_info['#']['TIME']['0']['#']); + $answer->answer1 = backup_todb($sub_info['#']['ANSWER1']['0']['#']); + $answer->answer2 = backup_todb($sub_info['#']['ANSWER2']['0']['#']); + + //We have to recode the userid field + $user = backup_getid($restore->backup_unique_code,"user",$answer->userid); + if ($user) { + $answer->userid = $user->new_id; + } + + //The structure is equal to the db, so insert the survey_answers + $newid = insert_record ("survey_answers",$answer); + if ($newid) { + //We have the newid, update backup_ids + backup_putid($restore->backup_unique_code,"survey_answers",$oldid, + $newid); + } else { + $status = false; + } + } + + return $status; + } + + //This function restores the survey_analysis + function survey_analysis_restore_mods($survey_id,$info,$restore) { + + global $CFG; + + $status = true; + + //Get the analysis array + $analysis = $info['MOD']['#']['ANALYSIS']['0']['#']['ANALYS']; + + //Iterate over analysis + for($i = 0; $i < sizeof($analysis); $i++) { + $sub_info = $analysis[$i]; + traverse_xmlize($sub_info); //Debug + print_object ($GLOBALS['traverse_array']); //Debug + $GLOBALS['traverse_array']=""; //Debug + + //We'll need this later!! + $oldid = backup_todb($sub_info['#']['ID']['0']['#']); + $olduserid = backup_todb($sub_info['#']['USERID']['0']['#']); + + //Now, build the SURVEY_ANALYSIS record structure + $analys->survey = $survey_id; + $analys->userid = backup_todb($sub_info['#']['USERID']['0']['#']); + $analys->notes = backup_todb($sub_info['#']['NOTES']['0']['#']); + + //We have to recode the userid field + $user = backup_getid($restore->backup_unique_code,"user",$analys->userid); + if ($user) { + $analys->userid = $user->new_id; + } + + //The structure is equal to the db, so insert the survey_analysis + $newid = insert_record ("survey_analysis",$analys); + if ($newid) { + //We have the newid, update backup_ids + backup_putid($restore->backup_unique_code,"survey_analysis",$oldid, + $newid); + } else { + $status = false; + } + } + + return $status; + } +?> -- 2.39.5