]> git.mjollnir.org Git - moodle.git/commitdiff
Backupo / Restore for labels (untested as yet)
authormoodler <moodler>
Sun, 14 Sep 2003 15:20:43 +0000 (15:20 +0000)
committermoodler <moodler>
Sun, 14 Sep 2003 15:20:43 +0000 (15:20 +0000)
mod/label/backuplib.php [new file with mode: 0644]
mod/label/restorelib.php [new file with mode: 0644]

diff --git a/mod/label/backuplib.php b/mod/label/backuplib.php
new file mode 100644 (file)
index 0000000..0224de4
--- /dev/null
@@ -0,0 +1,37 @@
+<?PHP //$Id$
+    //This php script contains all the stuff to backup/restore
+    //label mods
+
+    //This function executes all the backup procedure about this mod
+    function label_backup_mods($bf,$preferences) {
+        global $CFG;
+
+        $status = true; 
+
+        ////Iterate over label table
+        if ($labels = get_records ("label","course", $preferences->backup_course,"id")) {
+            foreach ($labels as $label) {
+                //Start mod
+                fwrite ($bf,start_tag("MOD",3,true));
+                //Print assignment data
+                fwrite ($bf,full_tag("ID",4,false,$label->id));
+                fwrite ($bf,full_tag("MODTYPE",4,false,"label"));
+                fwrite ($bf,full_tag("NAME",4,false,$label->name));
+                fwrite ($bf,full_tag("CONTENT",4,false,$label->content));
+                fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$label->timemodified));
+                //End mod
+                $status = fwrite ($bf,end_tag("MOD",3,true));
+            }
+        }
+        return $status;
+    }
+   
+    ////Return an array of info (name,value)
+    function label_check_backup_mods($course,$user_data=false,$backup_unique_code) {
+         //First the course data
+         $info[0][0] = get_string("modulenameplural","label");
+         $info[0][1] = count_records("label", "course", "$course");
+         return $info;
+    } 
+
+?>
diff --git a/mod/label/restorelib.php b/mod/label/restorelib.php
new file mode 100644 (file)
index 0000000..f96d9d1
--- /dev/null
@@ -0,0 +1,54 @@
+<?PHP //$Id$
+    //This php script contains all the stuff to backup/restore
+    //label mods
+
+    //This function executes all the restore procedure about this mod
+    function label_restore_mods($mod,$restore) {
+
+        global $CFG;
+
+        $status = true;
+
+        //Get record from backup_ids
+        $data = backup_getid($restore->backup_unique_code,$mod->modtype,$mod->id);
+
+        if ($data) {
+            //Now get completed xmlized object
+            $info = $data->info;
+            //traverse_xmlize($info);                                                                     //Debug
+            //print_object ($GLOBALS['traverse_array']);                                                  //Debug
+            //$GLOBALS['traverse_array']="";                                                              //Debug
+          
+            //Now, build the RESOURCE record structure
+            $label->course = $restore->course_id;
+            $label->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
+            $label->content = backup_todb($info['MOD']['#']['CONTENT']['0']['#']);
+            $label->timemodified = $info['MOD']['#']['TIMEMODIFIED']['0']['#'];
+            //The structure is equal to the db, so insert the label
+            $newid = insert_record ("label",$label);
+
+            //Do some output     
+            echo "<ul><li>".get_string("modulename","label")." \"".$label->name."\"<br>";
+            backup_flush(300);
+
+            if ($newid) {
+                //We have the newid, update backup_ids
+                backup_putid($restore->backup_unique_code,$mod->modtype,
+                             $mod->id, $newid);
+   
+            } else {
+                $status = false;
+            }
+
+            //Finalize ul        
+            echo "</ul>";
+
+        } else {
+            $status = false;
+        }
+
+        return $status;
+    }
+   
+?>