}
$status = backup_gradebook_item_info($bf,$preferences, $backupall);
+ $status = backup_gradebook_grade_letters_info($bf,$preferences);
$status = backup_gradebook_outcomes_info($bf, $preferences);
$status = backup_gradebook_outcomes_courses_info($bf, $preferences);
}
//Backup gradebook_item (called from backup_gradebook_info
+ function backup_gradebook_grade_letters_info($bf, $preferences) {
+ global $CFG;
+ $status = true;
+
+ // 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
+ $context = get_context_instance(CONTEXT_COURSE, $preferences->backup_course);
+ $grade_letters = get_records_sql("SELECT *
+ FROM {$CFG->prefix}grade_letters
+ WHERE contextid = $context->id");
+ if ($grade_letters) {
+ //Begin grade_categories tag
+ fwrite ($bf,start_tag("GRADE_LETTERS",3,true));
+ //Iterate for each category
+ foreach ($grade_letters as $grade_letter) {
+ //Begin grade_category
+ fwrite ($bf,start_tag("GRADE_LETTER",4,true));
+ //Output individual fields
+ fwrite ($bf,full_tag("ID",5,false,$grade_letter->id));
+
+ // not keeping path and depth because they can be derived
+ fwrite ($bf,full_tag("LOWERBOUNDARY",5,false,$grade_letter->lowerboundary));
+ fwrite ($bf,full_tag("LETTER",5,false,$grade_letter->letter));
+
+ //End grade_category
+ fwrite ($bf,end_tag("GRADE_LETTER",4,true));
+ }
+ //End grade_categories tag
+ $status = fwrite ($bf,end_tag("GRADE_LETTERS",3,true));
+ }
+
+ return $status;
+ }
+
function backup_gradebook_outcomes_info($bf,$preferences) {
global $CFG;
// Count how many we have
$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');
+ $letterscount = count_records ('backup_ids', 'backup_code', $restore->backup_unique_code, 'table_name', 'grade_letters');
$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');
$gchcount = count_records ('backup_ids', 'backup_code', $restore->backup_unique_code, 'table_name', 'grade_categories_history');
}
}
+ // Process letters
+
+ $context = get_context_instance(CONTEXT_COURSE, $restore->course_id);
+ // respect current grade letters if defined
+ if ($letterscount && $continue && !record_exists('grade_letters', 'contextid', $context->id)) {
+ if (!defined('RESTORE_SILENTLY')) {
+ echo '<li>'.get_string('gradeletters','grades').'</li>';
+ }
+ $counter = 0;
+ while ($counter < $letterscount) {
+ // Fetch recordset_size records in each iteration
+ $recs = get_records_select("backup_ids","table_name = 'grade_letters' AND backup_code = '$restore->backup_unique_code'",
+ "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_letters',$rec->old_id);
+ if ($data) {
+ // Now get completed xmlized object
+ $info = $data->info;
+ $dbrec->contextid = $context->id;
+ $dbrec->lowerboundary = backup_todb($info['GRADE_LETTER']['#']['LOWERBOUNDARY']['0']['#']);
+ $dbrec->letter = backup_todb($info['GRADE_LETTER']['#']['LETTER']['0']['#']);
+ // course might already have grade letters defined, if so, skip
+ insert_record('grade_letters', $dbrec);
+
+ }
+ $counter++;
+ }
+ }
+ }
+ }
+
// process outcomes
if ($outcomecount && $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[5] == "GRADE_OUTCOMES_COURSE" || $this->tree[5] == "GRADE_CATEGORIES_HISTORY" || $this->tree[5] == "GRADE_GRADES_HISTORY" || $this->tree[5] == "GRADE_TEXT_HISTORY" || $this->tree[5] == "GRADE_ITEM_HISTORY" || $this->tree[5] == "GRADE_OUTCOME_HISTORY") && ($this->tree[3] == "GRADEBOOK")) {
+ if (($this->tree[5] == "GRADE_ITEM" || $this->tree[5] == "GRADE_CATEGORY" || $this->tree[5] == "GRADE_LETTER" || $this->tree[5] == "GRADE_OUTCOME" || $this->tree[5] == "GRADE_OUTCOMES_COURSE" || $this->tree[5] == "GRADE_CATEGORIES_HISTORY" || $this->tree[5] == "GRADE_GRADES_HISTORY" || $this->tree[5] == "GRADE_TEXT_HISTORY" || $this->tree[5] == "GRADE_ITEM_HISTORY" || $this->tree[5] == "GRADE_OUTCOME_HISTORY") && ($this->tree[3] == "GRADEBOOK")) {
if (!isset($this->temp)) {
$this->temp = "";
//Call to xmlize for this portion of xml data (one PREFERENCE)
//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
$item_id = $data["GRADE_ITEM"]["#"]["ID"]["0"]["#"];
$this->counter++;
//Save to db
//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
$category_id = $data["GRADE_CATEGORY"]["#"]["ID"]["0"]["#"];
$this->counter++;
//Save to db
//Reset temp
unset($this->temp);
}
+
+ if (($this->level == 5) and ($tagName == "GRADE_LETTER")) {
+ //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);
+ $letter_id = $data["GRADE_LETTER"]["#"]["ID"]["0"]["#"];
+ $this->counter++;
+ //Save to db
+ $status = backup_putid($this->preferences->backup_unique_code, 'grade_letters' ,$letter_id,
+ null,$data);
+ //Create returning info
+ $this->info = $this->counter;
+ //Reset temp
+ unset($this->temp);
+ }
//If we've finished a grade_outcome, xmlize it an save to db
if (($this->level == 5) and ($tagName == "GRADE_OUTCOME")) {
//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
$outcome_id = $data["GRADE_OUTCOME"]["#"]["ID"]["0"]["#"];
$this->counter++;
//Save to db
//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
//Call to xmlize for this portion of xml data (one PREFERENCE)
//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
$id = $data["GRADE_CATEGORIES_HISTORY"]["#"]["ID"]["0"]["#"];
$this->counter++;
//Save to db
//Call to xmlize for this portion of xml data (one PREFERENCE)
//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
$id = $data["GRADE_GRADES_HISTORY"]["#"]["ID"]["0"]["#"];
$this->counter++;
//Save to db
//Call to xmlize for this portion of xml data (one PREFERENCE)
//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
$id = $data["GRADE_ITEM_HISTORY"]["#"]["ID"]["0"]["#"];
$this->counter++;
//Save to db
//Call to xmlize for this portion of xml data (one PREFERENCE)
//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
$id = $data["GRADE_OUTCOME_HISTORY"]["#"]["ID"]["0"]["#"];
$this->counter++;
//Save to db