$status = true;
- // get all the grade_items
- // might need to do it using sortorder
- if ($grade_items = get_records('grade_items', 'courseid', $preferences->backup_course)) {
+ // get all the grade_items, ordered by sort order since upon restoring, it is not always
+ // possible to use the same sort order. We could at least preserve the sortorder by restoring
+ // grade_items in the original sortorder
+ if ($grade_items = get_records_sql("SELECT * FROM {$CFG->prefix}grade_items
+ WHERE courseid = $preferences->backup_course
+ ORDER BY sortorder ASC")) {
//Begin grade_items tag
fwrite ($bf,start_tag("GRADE_ITEMS",3,true));
foreach ($histories as $history) {
fwrite ($bf,start_tag("GRADE_HISTORY",6,true));
fwrite ($bf,full_tag("ID",7,false,$history->id));
- fwrite ($bf,full_tag("USERID",7,false,$hisotry->userid));
- fwrite ($bf,full_tag("OLDGRADE",7,false,$hisotry->oldgrade));
+ fwrite ($bf,full_tag("USERID",7,false,$history->userid));
+ fwrite ($bf,full_tag("OLDGRADE",7,false,$history->oldgrade));
fwrite ($bf,full_tag("NEWGRADE",7,false,$history->newgrade));
fwrite ($bf,full_tag("NOTE",7,false,$history->note));
- fwrite ($bf,full_tag("HOWMODIFIED",7,false,$hisotry->howmodified));
- fwrite ($bf,full_tag("USERMODIFIED",7,false,$hisotry->usermodified));
+ fwrite ($bf,full_tag("HOWMODIFIED",7,false,$history->howmodified));
+ fwrite ($bf,full_tag("USERMODIFIED",7,false,$history->usermodified));
fwrite ($bf,end_tag("GRADE_HISTORY",6,true));
}
- $stauts = fwrite ($bf,end_tag("GRADE_GRADES_HISOTRY",5,true));
+ $stauts = fwrite ($bf,end_tag("GRADE_GRADES_HISTORY",5,true));
}
return $status;
}
echo '<li>'.get_string('gradeitems','grades').'</li>';
}
$counter = 0;
- $countercat = 0;
- while ($countercat < $itemscount) {
+ $counteritems = 0;
+ while ($counteritems < $itemscount) {
+
//Fetch recordset_size records in each iteration
$recs = get_records_select("backup_ids","table_name = 'grade_items' AND backup_code = '$restore->backup_unique_code'",
"old_id",
"old_id, old_id",
- $countercat,
+ $counteritems,
$recordset_size);
if ($recs) {
foreach ($recs as $rec) {
$dbrec->courseid = $restore->course_id;
- if ($info['GRADE_ITEM']['#']['CATEGORYID']['0']['#']) {
+ if (!empty($info['GRADE_ITEM']['#']['CATEGORYID']['0']['#'])) {
$dbrec->categoryid = backup_getid($restore->backup_unique_code,'grade_categories',backup_todb($info['GRADE_ITEM']['#']['CATEGORYID']['0']['#']));
}
*/
// always insert, since modules restored to existing courses are always inserted
- $itemid = insert_record('grade_items',$dbrec);
+
+ // get the current sortorder, add 1 to it and use that
+
+ if ($lastitem = get_record_sql("SELECT sortorder, id FROM {$CFG->prefix}grade_items
+ WHERE courseid = $restore->course_id
+ ORDER BY sortorder DESC ", true)) {
+
+ // we just need the first one
+ $dbrec->sortorder = $lastitem->sortorder + 1;
+ } else {
+ // this is the first grade_item
+ $dbrec->sortorder = 0;
+ }
+
+ $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
$text->informationformat = backup_todb($ite_info['#']['INFORMATIONFORMAT']['0']['#']);
$text->feedback = backup_todb($ite_info['#']['FEEDBACK']['0']['#']);
$text->feedbackformat = backup_todb($ite_info['#']['FEEDBACKFORMAT']['0']['#']);
-
+
insert_record('grade_grades_text', $text);
-
+
$counter++;
if ($counter % 20 == 0) {
if (!defined('RESTORE_SILENTLY')) {
$history->howmodified = backup_todb($ite_info['#']['HOWMODIFIED']['0']['#']);
$modifier = backup_getid($restore->backup_unique_code,"user", backup_todb($ite_info['#']['USERMODIFIED']['0']['#']));
$history->usermodified = $modifier->new_id;
- insert_record('grade_history', $text);
+ insert_record('grade_history', $history);
$counter++;
if ($counter % 20 == 0) {
}
}
}
+ $counteritems++; // increment item count
}
}
- $countercat++;
+
}
}