]> git.mjollnir.org Git - moodle.git/commitdiff
Survey backup included.
authorstronk7 <stronk7>
Sun, 11 May 2003 22:44:40 +0000 (22:44 +0000)
committerstronk7 <stronk7>
Sun, 11 May 2003 22:44:40 +0000 (22:44 +0000)
backup/STATUS.txt
backup/mod/survey/backuplib.php

index ccd310259391bf19c7bd40aa66c007c2457cb0e9..ce2207e876309b076531057c538c0fcc2f872470 100644 (file)
@@ -3,8 +3,8 @@ STATUS $Id$
 
 This documment shows the current status of the backup/restore option.
 
-Backup:  WORKING. COMPLETED but only assignments, resources and
-                  choices.
+Backup:  WORKING. COMPLETED but only assignments, resources,
+                  choices and surveys.
 
 Restore: NOT WORKING. No comments.
 
@@ -77,10 +77,10 @@ Backup Details:
                  + course data..................................DONE
                  + user data....................................DONE
                  + files..(ARE COURSE FILES !!!)................DONE
-              x surveys.........................................IN PROGRESS
-                 + course data..................................NO EXISTS
-                 + user data....................................NO EXISTS
-                 + files........................................NO EXISTS
+              x surveys.........................................DONE
+                 + course data..................................DONE
+                 + user data....................................DONE
+                 + files.....(NOT EXISTS).......................DONE
               x workshops.......................................NO EXISTS
                  + course data..................................NO EXISTS
                  + user data....................................NO EXISTS
index 9f39f3a6dab09f08a06f4c7377fa3391e7694021..416d9a57d9b45601dcc8b545ab3a5b88e3915d63 100644 (file)
     //
     //-----------------------------------------------------------
 
-    function survey_backup_mods() {
-        print "hola";
+    function survey_backup_mods($bf,$preferences) {
+
+        global $CFG;
+
+        $status = true;
+
+        //Iterate over survey table
+        $surveys = get_records ("survey","course",$preferences->backup_course,"id");
+        if ($surveys) {
+            foreach ($surveys as $survey) {
+                //Start mod
+                fwrite ($bf,start_tag("MOD",3,true));
+                //Print choice data
+                fwrite ($bf,full_tag("ID",4,false,$survey->id));
+                fwrite ($bf,full_tag("MODTYPE",4,false,"survey"));
+                fwrite ($bf,full_tag("TEMPLATE",4,false,$survey->template));
+                fwrite ($bf,full_tag("DAYS",4,false,$survey->days));
+                fwrite ($bf,full_tag("TIMECREATED",4,false,$survey->timecreated));
+                fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$survey->timemodified));
+                fwrite ($bf,full_tag("NAME",4,false,$survey->name));
+                fwrite ($bf,full_tag("INTRO",4,false,$survey->intro));
+                fwrite ($bf,full_tag("QUESTIONS",4,false,$survey->questions));
+
+                //if we've selected to backup users info, then execute backup_survey_answers and
+                //backup_survey_analysis
+                if ($preferences->mods["survey"]->userinfo) {
+                    $status = backup_survey_answers($bf,$preferences,$survey->id);
+                    $status = backup_survey_analysis($bf,$preferences,$survey->id);
+                }
+                //End mod
+                $status =fwrite ($bf,end_tag("MOD",3,true));
+            }
+        }
+        return $status;
+    }
+
+    //Backup survey_answers contents (executed from survey_backup_mods)
+    function backup_survey_answers ($bf,$preferences,$survey) {
+
+        global $CFG;
+
+        $status = true;
+
+        $survey_answers = get_records("survey_answers","survey",$survey,"id");
+        //If there is answers
+        if ($survey_answers) {
+            //Write start tag
+            $status =fwrite ($bf,start_tag("ANSWERS",4,true));
+            //Iterate over each answer
+            foreach ($survey_answers as $sur_ans) {
+                //Start answer
+                $status =fwrite ($bf,start_tag("ANSWER",5,true));
+                //Print survey_answers contents
+                fwrite ($bf,full_tag("ID",6,false,$sur_ans->id));
+                fwrite ($bf,full_tag("USERID",6,false,$sur_ans->userid));
+                fwrite ($bf,full_tag("QUESTION",6,false,$sur_ans->question));
+                fwrite ($bf,full_tag("TIME",6,false,$sur_ans->time));
+                fwrite ($bf,full_tag("ANSWER1",6,false,$sur_ans->answer1));
+                fwrite ($bf,full_tag("ANSWER2",6,false,$sur_ans->answer2));
+                //End answer
+                $status =fwrite ($bf,end_tag("ANSWER",5,true));
+            }
+            //Write end tag
+            $status =fwrite ($bf,end_tag("ANSWERS",4,true));
+        }
+        return $status;
     }
 
-   ////Return an array of info (name,value)
-   function NO_survey_check_backup_mods($course,$user_data=false,$backup_unique_code) {
-        //First the course data
-        $info[0][0] = get_string("modulenameplural","survey");
-        if ($ids = survey_ids ($course)) {
-            $info[0][1] = count($ids);
-        } else {
-            $info[0][1] = 0;
+    //Backup survey_analysis contents (executed from survey_backup_mods)
+    function backup_survey_analysis ($bf,$preferences,$survey) {
+
+        global $CFG;
+
+        $status = true;
+
+        $survey_analysis = get_records("survey_analysis","survey",$survey,"id");
+        //If there is analysis
+        if ($survey_analysis) {
+            //Write start tag
+            $status =fwrite ($bf,start_tag("ANALYSIS",4,true));
+            //Iterate over each analysis
+            foreach ($survey_analysis as $sur_ana) {
+                //Start answer
+                $status =fwrite ($bf,start_tag("ANALYS",5,true));
+                //Print survey_analysis contents
+                fwrite ($bf,full_tag("ID",6,false,$sur_ana->id));
+                fwrite ($bf,full_tag("USERID",6,false,$sur_ana->userid));
+                fwrite ($bf,full_tag("NOTES",6,false,$sur_ana->notes));
+                //End answer
+                $status =fwrite ($bf,end_tag("ANALYS",5,true));
+            }
+            //Write end tag
+            $status =fwrite ($bf,end_tag("ANALYSIS",4,true));
         }
+        return $status;
+    }
+
+    ////Return an array of info (name,value)
+   function survey_check_backup_mods($course,$user_data=false,$backup_unique_code) {
+       //First the course data
+       $info[0][0] = get_string("modulenameplural","survey");
+       if ($ids = survey_ids ($course)) {
+           $info[0][1] = count($ids);
+       } else {
+           $info[0][1] = 0;
+       }
 
         //Now, if requested, the user_data
         if ($user_data) {