2 ///////////////////////////////////////////////////////////////////////////
4 // NOTICE OF COPYRIGHT //
6 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
7 // http://moodle.com //
9 // Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
11 // This program is free software; you can redistribute it and/or modify //
12 // it under the terms of the GNU General Public License as published by //
13 // the Free Software Foundation; either version 2 of the License, or //
14 // (at your option) any later version. //
16 // This program is distributed in the hope that it will be useful, //
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
19 // GNU General Public License for more details: //
21 // http://www.gnu.org/copyleft/gpl.html //
23 ///////////////////////////////////////////////////////////////////////////
25 require_once($CFG->dirroot
.'/grade/export/lib.php');
27 class grade_export_txt
extends grade_export
{
31 var $separator; // default separator
33 function grade_export_txt($course, $groupid=0, $itemlist='', $export_feedback=false, $updatedgradesonly = false, $displaytype = GRADE_DISPLAY_TYPE_REAL
, $decimalpoints = 2, $separator='comma') {
34 $this->grade_export($course, $groupid, $itemlist, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints);
35 $this->separator
= $separator;
38 function process_form($formdata) {
39 parent
::process_form($formdata);
40 if (isset($formdata->separator
)) {
41 $this->separator
= $formdata->separator
;
45 function get_export_params() {
46 $params = parent
::get_export_params();
47 $params['separator'] = $this->separator
;
51 function print_grades() {
54 $export_tracking = $this->track_exports();
56 $strgrades = get_string('grades');
58 switch ($this->separator
) {
67 /// Print header to force download
68 @header
('Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0');
69 @header
('Expires: '. gmdate('D, d M Y H:i:s', 0) .' GMT');
70 @header
('Pragma: no-cache');
71 header("Content-Type: application/download\n");
72 $downloadfilename = clean_filename("{$this->course->shortname} $strgrades");
73 header("Content-Disposition: attachment; filename=\"$downloadfilename.txt\"");
75 /// Print names of all the fields
76 echo get_string("firstname").$separator.
77 get_string("lastname").$separator.
78 get_string("idnumber").$separator.
79 get_string("institution").$separator.
80 get_string("department").$separator.
83 foreach ($this->columns
as $grade_item) {
84 echo $separator.$this->format_column_name($grade_item);
86 /// add a feedback column
87 if ($this->export_feedback
) {
88 echo $separator.$this->format_column_name($grade_item, true);
93 /// Print all the lines of data.
94 $geub = new grade_export_update_buffer();
95 $gui = new graded_users_iterator($this->course
, $this->columns
, $this->groupid
);
97 while ($userdata = $gui->next_user()) {
99 $user = $userdata->user
;
101 echo $user->firstname
.$separator.$user->lastname
.$separator.$user->idnumber
.$separator.$user->institution
.$separator.$user->department
.$separator.$user->email
;
103 foreach ($userdata->grades
as $itemid => $grade) {
104 if ($export_tracking) {
105 $status = $geub->track($grade);
108 echo $separator.$this->format_grade($grade);
110 if ($this->export_feedback
) {
111 echo $separator.$this->format_feedback($userdata->feedbacks
[$itemid]);