From: toyomoyo Date: Wed, 1 Aug 2007 05:55:36 +0000 (+0000) Subject: adding grade_outcomes_courses into backup and restore X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=6cdaa1f43b379548c9194866b805590cef9a42fd;p=moodle.git adding grade_outcomes_courses into backup and restore --- diff --git a/backup/backuplib.php b/backup/backuplib.php index de4d39a003..e464bb7de3 100644 --- a/backup/backuplib.php +++ b/backup/backuplib.php @@ -1366,7 +1366,6 @@ function backup_gradebook_info($bf,$preferences) { global $CFG; - $status = true; // see if ALL grade items of type mod of this course are being backed up @@ -1401,6 +1400,7 @@ } $status = backup_gradebook_item_info($bf,$preferences, $backupall); $status = backup_gradebook_outcomes_info($bf, $preferences); + $status = backup_gradebook_outcomes_courses_info($bf, $preferences); // back up grade outcomes //Gradebook footer @@ -1408,14 +1408,10 @@ return $status; } - function backup_gradebook_category_info($bf,$preferences) { global $CFG; - $status = true; - //Output grade_category - // getting grade categories, but make sure parents come before children // because when we do restore, we need to recover the parents first // we do this by getting the lowest depth first @@ -1448,18 +1444,14 @@ } return $status; - } - //Backup gradebook_item (called from backup_gradebook_info function backup_gradebook_item_info($bf,$preferences, $backupall) { global $CFG; require_once($CFG->libdir . '/gradelib.php'); - $status = true; - // 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 @@ -1533,24 +1525,14 @@ function backup_gradebook_outcomes_info($bf,$preferences) { global $CFG; - $status = true; - - // get all global outcomes (used in this course) - // and course specific outcomes - // we don't need to backup all the outcomes in this case + // only back up courses already in the grade_outcomes_courses table $grade_outcomes = get_records_sql('SELECT go.* FROM '.$CFG->prefix.'grade_outcomes_courses goc, '.$CFG->prefix.'grade_outcomes go WHERE goc.courseid = '.$preferences->backup_course.' AND goc.outcomeid = go.id'); - if (empty($grade_outcomes)) { - $grade_outcomes = get_records('grade_outcomes', 'courseid', $preferences->backup_course); - } elseif ($mcourseoutcomes = get_records('grade_outcomes', 'courseid', $preferences->backup_course)) { - $grade_outcomes += $mcourseoutcomes; - } - if (!empty($grade_outcomes)) { //Begin grade_outcomes tag fwrite ($bf,start_tag("GRADE_OUTCOMES",3,true)); @@ -1575,6 +1557,35 @@ } return $status; } + + // outcomes assigned to this course + function backup_gradebook_outcomes_courses_info($bf,$preferences) { + + global $CFG; + + $status = true; + // get all global outcomes (used in this course) + // and course specific outcomes + // we don't need to backup all the outcomes in this case + if ($outcomes_courses = get_records('grade_outcomes_courses', 'courseid', $preferences->backup_course)) { + //Begin grade_outcomes tag + fwrite ($bf,start_tag("GRADE_OUTCOMES_COURSES",3,true)); + //Iterate for each outcome + foreach ($outcomes_courses as $outcomes_course) { + //Begin grade_outcome + fwrite ($bf,start_tag("GRADE_OUTCOMES_COURSE",4,true)); + //Output individual fields + fwrite ($bf,full_tag("ID",5,false,$outcomes_course->id)); + fwrite ($bf,full_tag("OUTCOMEID",5,false,$outcomes_course->outcomeid)); + + //End grade_outcome + fwrite ($bf,end_tag("GRADE_OUTCOMES_COURSE",4,true)); + } + //End grade_outcomes tag + $status = fwrite ($bf,end_tag("GRADE_OUTCOMES_COURSES",3,true)); + } + return $status; + } function backup_gradebook_grades_info($bf,$preferences, $itemid) { diff --git a/backup/restorelib.php b/backup/restorelib.php index 5f441f92ed..38b28c6711 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -1197,6 +1197,7 @@ $categoriescount = count_records ('backup_ids', 'backup_code', $restore->backup_unique_code, 'table_name', 'grade_categories'); $itemscount = count_records ('backup_ids', 'backup_code', $restore->backup_unique_code, 'table_name', 'grade_items'); $outcomecount = count_records ('backup_ids', 'backup_code', $restore->backup_unique_code, 'table_name', 'grade_outcomes'); + $outcomescoursescount = count_records ('backup_ids', 'backup_code', $restore->backup_unique_code, 'table_name', 'grade_outcomes_courses'); // we need to know if all grade items that were backed up are being restored // if that is not the case, we do not restore grade categories nor gradeitems of category type or course type @@ -1401,6 +1402,54 @@ } } + // process outcomescourses + if ($outcomescoursescount && $continue) { + if (!defined('RESTORE_SILENTLY')) { + echo '
  • '.get_string('gradeoutcomescourses','grades').'
  • '; + } + $counter = 0; + while ($counter < $outcomescoursescount) { + //Fetch recordset_size records in each iteration + $recs = get_records_select("backup_ids","table_name = 'grade_outcomes_courses' AND backup_code = '$restore->backup_unique_code'", + "old_id", + "old_id, old_id", + $counter, + $recordset_size); + if ($recs) { + foreach ($recs as $rec) { + //Get the full record from backup_ids + $data = backup_getid($restore->backup_unique_code,'grade_outcomes_courses',$rec->old_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 + + $oldoutcomesid = backup_todb($info['GRADE_OUTCOMES_COURSE']['#']['OUTCOMEID']['0']['#']); + $newoutcome = backup_getid($restore->backup_unique_code,"grade_outcomes",$oldoutcomesid); + unset($dbrec); + $dbrec->courseid = $restore->course_id; + $dbrec->outcomeid = $newoutcome->new_id; + insert_record('grade_outcomes_courses', $dbrec); + } + //Increment counters + $counter++; + //Do some output + if ($counter % 1 == 0) { + if (!defined('RESTORE_SILENTLY')) { + echo "."; + if ($counter % 20 == 0) { + echo "
    "; + } + } + backup_flush(300); + } + } + } + } + } + // Process grade items (grade_raw, grade_final, and grade_text) if ($itemscount && $continue) { if (!defined('RESTORE_SILENTLY')) { @@ -3543,7 +3592,7 @@ //If we are under a GRADE_PREFERENCE, GRADE_LETTER or GRADE_CATEGORY tag under a GRADEBOOK zone, accumule it if (isset($this->tree[5]) and isset($this->tree[3])) { - if (($this->tree[5] == "GRADE_ITEM" || $this->tree[5] == "GRADE_CATEGORY" || $this->tree[5] == "GRADE_OUTCOME") && ($this->tree[3] == "GRADEBOOK")) { + if (($this->tree[5] == "GRADE_ITEM" || $this->tree[5] == "GRADE_CATEGORY" || $this->tree[5] == "GRADE_OUTCOME" || $this->tree[5] == "GRADE_OUTCOMES_COURSE") && ($this->tree[3] == "GRADEBOOK")) { if (!isset($this->temp)) { $this->temp = ""; } @@ -4638,7 +4687,7 @@ if ($this->level == 4) { $this->temp = ""; } - //If we've finished a message, xmlize it an save to db + //If we've finished a grade item, xmlize it an save to db if (($this->level == 5) and ($tagName == "GRADE_ITEM")) { //Prepend XML standard header to info gathered $xml_data = "\n".$this->temp; @@ -4688,7 +4737,7 @@ unset($this->temp); } - //If we've finished a grade_category, xmlize it an save to db + //If we've finished a grade_outcome, xmlize it an save to db if (($this->level == 5) and ($tagName == "GRADE_OUTCOME")) { //Prepend XML standard header to info gathered $xml_data = "\n".$this->temp; @@ -4711,6 +4760,30 @@ //Reset temp unset($this->temp); } + + //If we've finished a grade_outcomes_course, xmlize it an save to db + if (($this->level == 5) and ($tagName == "GRADE_OUTCOMES_COURSE")) { + //Prepend XML standard header to info gathered + $xml_data = "\n".$this->temp; + //Call to xmlize for this portion of xml data (one CATECORY) + //echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug + $data = xmlize($xml_data,0); + //echo strftime ("%X",time())."

    "; //Debug + //traverse_xmlize($data); //Debug + //print_object ($GLOBALS['traverse_array']); //Debug + //$GLOBALS['traverse_array']=""; //Debug + //Now, save data to db. We'll use it later + //Get id and status from data + $outcomes_course_id = $data["GRADE_OUTCOMES_COURSE"]["#"]["ID"]["0"]["#"]; + $this->counter++; + //Save to db + $status = backup_putid($this->preferences->backup_unique_code, 'grade_outcomes_courses' ,$outcomes_course_id, + null,$data); + //Create returning info + $this->info = $this->counter; + //Reset temp + unset($this->temp); + } } //Stop parsing if todo = GRADEBOOK and tagName = GRADEBOOK (en of the tag, of course)