From 1a27182bc6fb27e2d7b9e90310c8817c352c7d0d Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Wed, 24 Oct 2007 07:41:45 +0000 Subject: [PATCH] MDL-11513, adding support for grade_letters --- backup/backuplib.php | 36 +++++++++++++++ backup/restorelib.php | 104 ++++++++++++++++++++++-------------------- 2 files changed, 91 insertions(+), 49 deletions(-) diff --git a/backup/backuplib.php b/backup/backuplib.php index b80908f13e..988fb8d14b 100644 --- a/backup/backuplib.php +++ b/backup/backuplib.php @@ -1405,6 +1405,7 @@ } $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); @@ -1547,6 +1548,41 @@ } //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; diff --git a/backup/restorelib.php b/backup/restorelib.php index abe69fdae5..45d0f70106 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -1194,6 +1194,7 @@ // 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'); @@ -1347,6 +1348,42 @@ } } + // 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 '
  • '.get_string('gradeletters','grades').'
  • '; + } + $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')) { @@ -4048,7 +4085,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[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 = ""; @@ -5205,12 +5242,6 @@ //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())."

    "; //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 @@ -5231,12 +5262,6 @@ //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 $category_id = $data["GRADE_CATEGORY"]["#"]["ID"]["0"]["#"]; $this->counter++; //Save to db @@ -5247,6 +5272,23 @@ //Reset temp unset($this->temp); } + + if (($this->level == 5) and ($tagName == "GRADE_LETTER")) { + //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); + $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")) { @@ -5255,12 +5297,6 @@ //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 $outcome_id = $data["GRADE_OUTCOME"]["#"]["ID"]["0"]["#"]; $this->counter++; //Save to db @@ -5279,12 +5315,6 @@ //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 @@ -5302,12 +5332,6 @@ //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())."

    "; //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 @@ -5327,12 +5351,6 @@ //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())."

    "; //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 @@ -5352,12 +5370,6 @@ //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())."

    "; //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 @@ -5377,12 +5389,6 @@ //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())."

    "; //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 -- 2.39.5