|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00018 require_once($CFG->dirroot.'/grade/export/lib.php'); 00019 require_once($CFG->libdir.'/filelib.php'); 00020 00021 class grade_export_xml extends grade_export { 00022 00023 public $plugin = 'xml'; 00024 public $updatedgradesonly = false; // default to export ALL grades 00025 00032 public function print_grades($feedback = false) { 00033 global $CFG; 00034 require_once($CFG->libdir.'/filelib.php'); 00035 00036 $export_tracking = $this->track_exports(); 00037 00038 $strgrades = get_string('grades'); 00039 00041 $shortname = format_string($this->course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $this->course->id))); 00042 $downloadfilename = clean_filename("$shortname $strgrades.xml"); 00043 00044 make_temp_directory('gradeexport'); 00045 $tempfilename = $CFG->tempdir .'/gradeexport/'. md5(sesskey().microtime().$downloadfilename); 00046 if (!$handle = fopen($tempfilename, 'w+b')) { 00047 print_error('cannotcreatetempdir'); 00048 } 00049 00051 fwrite($handle, '<results batch="xml_export_'.time().'">'."\n"); 00052 00053 $export_buffer = array(); 00054 00055 $geub = new grade_export_update_buffer(); 00056 $gui = new graded_users_iterator($this->course, $this->columns, $this->groupid); 00057 $gui->init(); 00058 while ($userdata = $gui->next_user()) { 00059 $user = $userdata->user; 00060 00061 if (empty($user->idnumber)) { 00062 //id number must exist otherwise we cant match up students when importing 00063 continue; 00064 } 00065 00066 // studentgrades[] index should match with corresponding $index 00067 foreach ($userdata->grades as $itemid => $grade) { 00068 $grade_item = $this->grade_items[$itemid]; 00069 $grade->grade_item =& $grade_item; 00070 $gradestr = $this->format_grade($grade); // no formating for now 00071 00072 // MDL-11669, skip exported grades or bad grades (if setting says so) 00073 if ($export_tracking) { 00074 $status = $geub->track($grade); 00075 if ($this->updatedgradesonly && ($status == 'nochange' || $status == 'unknown')) { 00076 continue; 00077 } 00078 } 00079 00080 fwrite($handle, "\t<result>\n"); 00081 00082 if ($export_tracking) { 00083 fwrite($handle, "\t\t<state>$status</state>\n"); 00084 } 00085 00086 // only need id number 00087 fwrite($handle, "\t\t<assignment>{$grade_item->idnumber}</assignment>\n"); 00088 // this column should be customizable to use either student id, idnumber, uesrname or email. 00089 fwrite($handle, "\t\t<student>{$user->idnumber}</student>\n"); 00090 fwrite($handle, "\t\t<score>$gradestr</score>\n"); 00091 if ($this->export_feedback) { 00092 $feedbackstr = $this->format_feedback($userdata->feedbacks[$itemid]); 00093 fwrite($handle, "\t\t<feedback>$feedbackstr</feedback>\n"); 00094 } 00095 fwrite($handle, "\t</result>\n"); 00096 } 00097 } 00098 fwrite($handle, "</results>"); 00099 fclose($handle); 00100 $gui->close(); 00101 $geub->close(); 00102 00103 @header("Content-type: text/xml; charset=UTF-8"); 00104 send_temp_file($tempfilename, $downloadfilename, false); 00105 } 00106 } 00107 00108