|
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 00020 class grade_export_txt extends grade_export { 00021 00022 public $plugin = 'txt'; 00023 00024 public $separator; // default separator 00025 00026 public function grade_export_txt($course, $groupid=0, $itemlist='', $export_feedback=false, $updatedgradesonly = false, $displaytype = GRADE_DISPLAY_TYPE_REAL, $decimalpoints = 2, $separator='comma') { 00027 $this->grade_export($course, $groupid, $itemlist, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints); 00028 $this->separator = $separator; 00029 } 00030 00031 public function __construct($course, $groupid=0, $itemlist='', $export_feedback=false, $updatedgradesonly = false, $displaytype = GRADE_DISPLAY_TYPE_REAL, $decimalpoints = 2, $separator='comma') { 00032 parent::__construct($course, $groupid, $itemlist, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints); 00033 $this->separator = $separator; 00034 } 00035 00036 public function get_export_params() { 00037 $params = parent::get_export_params(); 00038 $params['separator'] = $this->separator; 00039 return $params; 00040 } 00041 00042 public function print_grades() { 00043 global $CFG; 00044 00045 $export_tracking = $this->track_exports(); 00046 00047 $strgrades = get_string('grades'); 00048 00049 switch ($this->separator) { 00050 case 'comma': 00051 $separator = ","; 00052 break; 00053 case 'tab': 00054 default: 00055 $separator = "\t"; 00056 } 00057 00059 if (strpos($CFG->wwwroot, 'https://') === 0) { //https sites - watch out for IE! KB812935 and KB316431 00060 @header('Cache-Control: max-age=10'); 00061 @header('Expires: '. gmdate('D, d M Y H:i:s', 0) .' GMT'); 00062 @header('Pragma: '); 00063 } else { //normal http - prevent caching at all cost 00064 @header('Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0'); 00065 @header('Expires: '. gmdate('D, d M Y H:i:s', 0) .' GMT'); 00066 @header('Pragma: no-cache'); 00067 } 00068 header("Content-Type: application/download\n"); 00069 $shortname = format_string($this->course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $this->course->id))); 00070 $downloadfilename = clean_filename("$shortname $strgrades"); 00071 header("Content-Disposition: attachment; filename=\"$downloadfilename.txt\""); 00072 00074 echo get_string("firstname").$separator. 00075 get_string("lastname").$separator. 00076 get_string("idnumber").$separator. 00077 get_string("institution").$separator. 00078 get_string("department").$separator. 00079 get_string("email"); 00080 00081 foreach ($this->columns as $grade_item) { 00082 echo $separator.$this->format_column_name($grade_item); 00083 00085 if ($this->export_feedback) { 00086 echo $separator.$this->format_column_name($grade_item, true); 00087 } 00088 } 00089 echo "\n"; 00090 00092 $geub = new grade_export_update_buffer(); 00093 $gui = new graded_users_iterator($this->course, $this->columns, $this->groupid); 00094 $gui->init(); 00095 while ($userdata = $gui->next_user()) { 00096 00097 $user = $userdata->user; 00098 00099 echo $user->firstname.$separator.$user->lastname.$separator.$user->idnumber.$separator.$user->institution.$separator.$user->department.$separator.$user->email; 00100 00101 foreach ($userdata->grades as $itemid => $grade) { 00102 if ($export_tracking) { 00103 $status = $geub->track($grade); 00104 } 00105 00106 echo $separator.$this->format_grade($grade); 00107 00108 if ($this->export_feedback) { 00109 echo $separator.$this->format_feedback($userdata->feedbacks[$itemid]); 00110 } 00111 } 00112 echo "\n"; 00113 } 00114 $gui->close(); 00115 $geub->close(); 00116 00117 exit; 00118 } 00119 } 00120 00121