]> git.mjollnir.org Git - moodle.git/commitdiff
more fixes for gradebook backup/restore
authortoyomoyo <toyomoyo>
Wed, 30 May 2007 08:45:13 +0000 (08:45 +0000)
committertoyomoyo <toyomoyo>
Wed, 30 May 2007 08:45:13 +0000 (08:45 +0000)
backup/backuplib.php
backup/restorelib.php

index 44c58af5488fd205c59e69f42127c297baed9f1f..4d7c5489ed16717be5a8103260b67aa15eb2c094 100644 (file)
             fwrite ($bf,start_tag("GRADE_ITEMS",3,true)); 
             //Iterate for each item
             foreach ($grade_items as $grade_item) {
+
+                // do not restore if this grade_item is a mod, and 
+                if ($grade_item->itemtype == 'mod') {
+
+                    // get module information
+                    $mod = get_record('course_modules', 'id', $grade_item->iteminstance);
+                    $modt = get_record('modules', 'id', $mod->module);
+
+                    // if no user data selected, we skip this grade_item
+                    if (!backup_userdata_selected($preferences,$modt->name,$mod->id)) {
+                        continue;
+                    }
+                }
+
                 //Begin grade_item
                 fwrite ($bf,start_tag("GRADE_ITEM",4,true)); 
                 //Output individual fields     
index dfdb4a7986c6f1aae54c178b80ce21fa6a88aafb..082702469ef3ad652a24e56077077a9e1e70a73c 100644 (file)
                             if ($dbrec->itemtype == 'mod') {
                                 
                                 // get the old mod
-                                $mod = get_record('course_module', 'id', $iteminstance);
-                                $modt = get_record('modules', 'id', $mod->module);                              
-                                
+                                $mod = get_record('course_modules', 'id', $iteminstance);
+                                $modt = get_record('modules', 'id', $mod->module);
+
                                 if (!restore_userdata_selected($restore, $modt->name, $mod->id)) {
                                     // module instance not selected when restored using granular
                                     // skip this item
                                     $counteritems++;
                                     continue;
                                 }
-                                                              
+
                                 // iteminstance should point to new mod
                                 $dbrec->iteminstance = backup_getid($restore->backup_unique_code,'course_modules', $iteminstance);
 
                             $dbrec->plusfactor = backup_todb($info['GRADE_ITEM']['#']['PLUSFACTOR']['0']['#']);
                             $dbrec->hidden = backup_todb($info['GRADE_ITEM']['#']['HIDDEN']['0']['#']);                                                                      
                             
-                            /// if thesse 5 all match then we know this item is already in db                                                  
-                           
+                            /// if thesse 5 all match then we know this item is already in db
+
                             /*
-                            $itemex = get_record_sql('SELECT id,id FROM grade_items 
-                                                      WHERE courseid = '.$dbrec->courseid.' 
-                                                      AND itemtype = '.$dbrec->itemtype.' 
+                            $itemex = get_record_sql('SELECT id,id FROM grade_items
+                                                      WHERE courseid = '.$dbrec->courseid.'
+                                                      AND itemtype = '.$dbrec->itemtype.'
                                                       AND itemmodule = '.$dbrec->itemmodule.'
                                                       AND iteminstance = '.$dbrec->iteminstance.'
                                                       AND itemnumber = '.$dbrec->itemnumber);
                             
                             if ($lastitem = get_record_sql("SELECT sortorder, id FROM {$CFG->prefix}grade_items
                                                         WHERE courseid = $restore->course_id
-                                                        ORDER BY sortorder DESC ", true)) { 
+                                                        ORDER BY sortorder DESC ", true)) {
 
                                 // we just need the first one
                                 $dbrec->sortorder = $lastitem->sortorder + 1;
                             } else {
-                                // this is the first grade_item  
+                                // this is the first grade_item
                                 $dbrec->sortorder = 0;
                             }
 
-                            $itemid = insert_record('grade_items',$dbrec);                            
+                            $itemid = insert_record('grade_items',$dbrec);
                             
                             /// now, restore grade_calculations, grade_raw, grade_final, grade_text, and grade_history
                             if (!empty($info['GRADE_ITEM']['#']['GRADE_GRADES_RAW']['0']['#']) && ($raws = $info['GRADE_ITEM']['#']['GRADE_GRADES_RAW']['0']['#']['GRADE_RAW'])) {
                                 //Iterate over items
                                 for($i = 0; $i < sizeof($raws); $i++) {
                                     $ite_info = $raws[$i];
-                                    //traverse_xmlize($ite_info);                                                                 //Debug
+                                    //traverse_xmlize($ite_info);
+//Debug
                                     //print_object ($GLOBALS['traverse_array']);                                                  //Debug
                                     //$GLOBALS['traverse_array']="";                                                              //Debug
                                     //Now build the GRADE_ITEM record structure
                                 //Iterate over items
                                 for($i = 0; $i < sizeof($calcs); $i++) {
                                     $ite_info = $calcs[$i];
-                                    //traverse_xmlize($ite_info);                                                                 //Debug
-                                    //print_object ($GLOBALS['traverse_array']);                                                  //Debug
+                                    //traverse_xmlize($ite_info);
+//Debug
+                                    //print_object ($GLOBALS['traverse_array']);
+//Debug
                                     //$GLOBALS['traverse_array']="";                                                              //Debug
                                     $calc->itemid       = $itemid;