[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 3 // This file is part of Moodle - http://moodle.org/ 4 // 5 // Moodle is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // Moodle is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 17 18 require_once($CFG->dirroot.'/grade/export/lib.php'); 19 require_once($CFG->libdir.'/filelib.php'); 20 21 class grade_export_xml extends grade_export { 22 23 public $plugin = 'xml'; 24 public $updatedgradesonly = false; // default to export ALL grades 25 26 /** 27 * To be implemented by child classes 28 * @param boolean $feedback 29 * @param boolean $publish Whether to output directly, or send as a file 30 * @return string 31 */ 32 public function print_grades($feedback = false) { 33 global $CFG; 34 require_once($CFG->libdir.'/filelib.php'); 35 36 $export_tracking = $this->track_exports(); 37 38 $strgrades = get_string('grades'); 39 40 /// Calculate file name 41 $shortname = format_string($this->course->shortname, true, array('context' => context_course::instance($this->course->id))); 42 $downloadfilename = clean_filename("$shortname $strgrades.xml"); 43 44 make_temp_directory('gradeexport'); 45 $tempfilename = $CFG->tempdir .'/gradeexport/'. md5(sesskey().microtime().$downloadfilename); 46 if (!$handle = fopen($tempfilename, 'w+b')) { 47 print_error('cannotcreatetempdir'); 48 } 49 50 /// time stamp to ensure uniqueness of batch export 51 fwrite($handle, '<results batch="xml_export_'.time().'">'."\n"); 52 53 $export_buffer = array(); 54 55 $geub = new grade_export_update_buffer(); 56 $gui = new graded_users_iterator($this->course, $this->columns, $this->groupid); 57 $gui->require_active_enrolment($this->onlyactive); 58 $gui->init(); 59 while ($userdata = $gui->next_user()) { 60 $user = $userdata->user; 61 62 if (empty($user->idnumber)) { 63 //id number must exist otherwise we cant match up students when importing 64 continue; 65 } 66 67 // studentgrades[] index should match with corresponding $index 68 foreach ($userdata->grades as $itemid => $grade) { 69 $grade_item = $this->grade_items[$itemid]; 70 $grade->grade_item =& $grade_item; 71 $gradestr = $this->format_grade($grade, $this->displaytype); // no formating for now 72 73 // MDL-11669, skip exported grades or bad grades (if setting says so) 74 if ($export_tracking) { 75 $status = $geub->track($grade); 76 if ($this->updatedgradesonly && ($status == 'nochange' || $status == 'unknown')) { 77 continue; 78 } 79 } 80 81 fwrite($handle, "\t<result>\n"); 82 83 if ($export_tracking) { 84 fwrite($handle, "\t\t<state>$status</state>\n"); 85 } 86 87 // only need id number 88 fwrite($handle, "\t\t<assignment>{$grade_item->idnumber}</assignment>\n"); 89 // this column should be customizable to use either student id, idnumber, uesrname or email. 90 fwrite($handle, "\t\t<student>{$user->idnumber}</student>\n"); 91 fwrite($handle, "\t\t<score>$gradestr</score>\n"); 92 if ($this->export_feedback) { 93 $feedbackstr = $this->format_feedback($userdata->feedbacks[$itemid]); 94 fwrite($handle, "\t\t<feedback>$feedbackstr</feedback>\n"); 95 } 96 fwrite($handle, "\t</result>\n"); 97 } 98 } 99 fwrite($handle, "</results>"); 100 fclose($handle); 101 $gui->close(); 102 $geub->close(); 103 104 if (defined('BEHAT_SITE_RUNNING')) { 105 // If behat is running, we cannot test the output if we force a file download. 106 include($tempfilename); 107 } else { 108 @header("Content-type: text/xml; charset=UTF-8"); 109 send_temp_file($tempfilename, $downloadfilename, false); 110 } 111 } 112 } 113 114
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |