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
}
$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
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
}
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
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));
}
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) {
$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
}
}
+ // process outcomescourses
+ if ($outcomescoursescount && $continue) {
+ if (!defined('RESTORE_SILENTLY')) {
+ echo '<li>'.get_string('gradeoutcomescourses','grades').'</li>';
+ }
+ $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 "<br />";
+ }
+ }
+ backup_flush(300);
+ }
+ }
+ }
+ }
+ }
+
// Process grade items (grade_raw, grade_final, and grade_text)
if ($itemscount && $continue) {
if (!defined('RESTORE_SILENTLY')) {
//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 = "";
}
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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".$this->temp;
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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".$this->temp;
//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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\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())."<p>"; //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)