]> git.mjollnir.org Git - moodle.git/commitdiff
Now glossary_ratings are in backup/restore too. !!
authorstronk7 <stronk7>
Sat, 22 Nov 2003 20:02:34 +0000 (20:02 +0000)
committerstronk7 <stronk7>
Sat, 22 Nov 2003 20:02:34 +0000 (20:02 +0000)
Solved one errors with glossary_alias.
Updated "graphical structure" of the module.

mod/glossary/backuplib.php
mod/glossary/restorelib.php

index 1285f9b3e8ae22903b46ebbbe0e0eacd7d9d78bf..8aec04564721cc07fa20a2ad263ce5bba4d80be9 100644 (file)
@@ -4,18 +4,19 @@
 
     //This is the "graphical" structure of the glossary mod:
     //
-    //                     glossary ---------------------- glossary_categories
-    //                    (CL,pk->id)                  (CL,pk->id,fk->glossaryid)
-    //                        |                                       |
-    //                        |                                       |
-    //                        |                                       |
-    //                  glossary_entries -------------- glossary_entries_categories
-    //         (UL,pk->id, fk->glossaryid, files)      (UL, pk->categoryid,entryid]
-    //                        |             \                          
-    //                        |              \                         
-    //                        |               \                        
-    //                  glossary_comments      --------- glossary_alias 
-    //              (UL,pk->id, fk->entryid)            (UL, pk->id, pk->entryid)
+    //                     glossary ----------------------------------------- glossary_categories
+    //                    (CL,pk->id)                                     (CL,pk->id,fk->glossaryid)
+    //                        |                                                       |
+    //                        |                                                       |
+    //                        |                                                       |
+    //                  glossary_entries --------------------------------glossary_entries_categories
+    //         (UL,pk->id, fk->glossaryid, files)         |               (UL, pk->categoryid,entryid)
+    //                        |                           |             
+    //                        |                           |--------------------glossary_ratings 
+    //                        |                           |               (UL, pk->id, pk->entryid)
+    //                  glossary_comments                 |
+    //              (UL,pk->id, fk->entryid)              |---------------------glossary_alias
+    //                                                                     (UL, pk->id, pk->entryid)
     //
     //
     // Meaning: pk->primary key field of the table
 
                     if ( $userinfo ) {
                         $status = backup_glossary_comments ($bf,$preferences,$glo_ent->id);
+                        $status = backup_glossary_ratings ($bf,$preferences,$glo_ent->id);
                     }
 
                     $status =fwrite ($bf,end_tag("ENTRY",5,true));
         }
         return $status;
     }
+
+   //Backup glossary_ratings contents (executed from backup_glossary_entries)
+    function backup_glossary_ratings ($bf,$preferences,$entryid) {
+
+        global $CFG;
+
+        $status = true;
+
+        $ratings = get_records("glossary_ratings","entryid",$entryid);
+        if ($ratings) {
+            $status =fwrite ($bf,start_tag("RATINGS",6,true));
+            foreach ($ratings as $rating) {
+                $status =fwrite ($bf,start_tag("RATING",7,true));
+
+                fwrite ($bf,full_tag("ID",8,false,$rating->id));
+                fwrite ($bf,full_tag("USERID",8,false,$rating->userid));
+                fwrite ($bf,full_tag("TIME",8,false,$rating->time));
+                fwrite ($bf,full_tag("RATING",8,false,$rating->rating));
+
+                $status =fwrite ($bf,end_tag("RATING",7,true));
+            }
+            $status =fwrite ($bf,end_tag("RATINGS",6,true));
+        }
+        return $status;
+    }
    
     //Backup glossary_alias contents (executed from backup_glossary_entries)
     function backup_glossary_aliases ($bf,$preferences,$entryid) {
             foreach ($aliases as $alias) {
                 $status =fwrite ($bf,start_tag("ALIAS",7,true));
 
-                fwrite ($bf,full_tag("NAME",8,false,$comment->id));
+                fwrite ($bf,full_tag("ALIAS_TEXT",8,false,$alias->alias));
 
                 $status =fwrite ($bf,end_tag("ALIAS",7,true));        
             }
index 09260270bb4c1c7cf926cdf4aab126e700ac1a5d..cff7b76fc39c1fec706ef08c53ea0fb14ef7097d 100644 (file)
@@ -4,18 +4,19 @@
 
     //This is the "graphical" structure of the glossary mod:
     //
-    //                     glossary ---------------------- glossary_categories
-    //                    (CL,pk->id)                  (CL,pk->id,fk->glossaryid)
-    //                        |                                       |
-    //                        |                                       |
-    //                        |                                       |
-    //                  glossary_entries -------------- glossary_entries_categories
-    //         (UL,pk->id, fk->glossaryid, files)      (UL, [pk->categoryid,entryid]
-    //                        |               \
-    //                        |                \
-    //                        |                 \
-    //                  glossary_comments        ------ glossary_alias
-    //              (UL,pk->id, fk->entryid)            (UL, pk->id, pk->entryid)
+    //                     glossary ----------------------------------------- glossary_categories
+    //                    (CL,pk->id)                                     (CL,pk->id,fk->glossaryid)
+    //                        |                                                       |
+    //                        |                                                       |
+    //                        |                                                       |
+    //                  glossary_entries --------------------------------glossary_entries_categories
+    //         (UL,pk->id, fk->glossaryid, files)         |               (UL, pk->categoryid,entryid)
+    //                        |                           |
+    //                        |                           |--------------------glossary_ratings
+    //                        |                           |               (UL, pk->id, pk->entryid)
+    //                  glossary_comments                 |
+    //              (UL,pk->id, fk->entryid)              |---------------------glossary_alias
+    //                                                                     (UL, pk->id, pk->entryid)
     //
     //
     // Meaning: pk->primary key field of the table
                     $status = glossary_alias_restore_mods($oldid,$newid,$ent_info,$restore);
                     //Now restore glossary_comments
                     $status = glossary_comments_restore_mods($oldid,$newid,$ent_info,$restore);
+                    //Now restore glossary_ratings
+                    $status = glossary_ratings_restore_mods($oldid,$newid,$ent_info,$restore);
                     //Now copy moddata associated files if needed
                     if ($entry->attachment) {
                         $status = glossary_restore_files ($old_glossary_id, $new_glossary_id,
         return $status;
     }
 
+    //This function restores the glossary_ratings
+    function glossary_ratings_restore_mods($old_entry_id,$new_entry_id,$info,$restore) {
+
+        global $CFG;
+
+        $status = true;
+
+        //Get the ratings array
+        $ratings = $info['#']['RATINGS']['0']['#']['RATING'];
+
+        //Iterate over ratings
+        for($i = 0; $i < sizeof($ratings); $i++) {
+            $rat_info = $ratings[$i];
+            //traverse_xmlize($rat_info);                                                                 //Debug
+            //print_object ($GLOBALS['traverse_array']);                                                  //Debug
+            //$GLOBALS['traverse_array']="";                                                              //Debug
+
+            //Now, build the GLOSSARY_RATINGS record structure
+            $rating->entryid = $new_entry_id;
+            $rating->userid = backup_todb($rat_info['#']['USERID']['0']['#']);
+            $rating->time = backup_todb($rat_info['#']['TIME']['0']['#']);
+            $rating->rating = backup_todb($rat_info['#']['RATING']['0']['#']);
+
+            //We have to recode the userid field
+            $user = backup_getid($restore->backup_unique_code,"user",$rating->userid);
+            if ($user) {
+                $rating->userid = $user->new_id;
+            }
+
+            //The structure is equal to the db, so insert the glossary_ratings
+            $newid = insert_record ("glossary_ratings",$rating);
+
+            //Do some output
+            if (($i+1) % 50 == 0) {
+                echo ".";
+                if (($i+1) % 1000 == 0) {
+                    echo "<br>";
+                }
+                backup_flush(300);
+            }
+
+            if (!$newid) {
+                $status = false;
+            }
+        }
+
+        return $status;
+    }
+
     //This function restores the glossary_alias table
     function glossary_alias_restore_mods($old_entry_id,$new_entry_id,$info,$restore) {
 
 
             //Now, build the GLOSSARY_ALIAS record structure
             $alias->entryid = $new_entry_id;
-            $alias->name = backup_todb($alias_info['#']['NAME']['0']['#']);
+            $alias->alias = backup_todb($alias_info['#']['ALIAS_TEXT']['0']['#']);
 
             //The structure is equal to the db, so insert the glossary_comments
             $newid = insert_record ("glossary_alias",$alias);