Commit | Line | Data |
---|---|---|
c10ddfb3 | 1 | <?php |
e060e33d | 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/>. | |
c10ddfb3 | 17 | |
18 | require_once($CFG->dirroot.'/grade/export/lib.php'); | |
19 | ||
20 | class grade_export_txt extends grade_export { | |
ba74762b | 21 | |
5c75a0a3 | 22 | public $plugin = 'txt'; |
ba74762b | 23 | |
5c75a0a3 | 24 | public $separator; // default separator |
caffc55a | 25 | |
78ab98bc AD |
26 | public function __construct($course, $groupid=0, $itemlist='', $export_feedback=false, $updatedgradesonly = false, $displaytype = GRADE_DISPLAY_TYPE_REAL, $decimalpoints = 2, $separator = 'comma', $onlyactive = false) { |
27 | parent::__construct($course, $groupid, $itemlist, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints, $onlyactive); | |
112fdf47 | 28 | $this->separator = $separator; |
d9617050 | 29 | } |
ba74762b | 30 | |
5c75a0a3 | 31 | public function get_export_params() { |
caffc55a | 32 | $params = parent::get_export_params(); |
33 | $params['separator'] = $this->separator; | |
34 | return $params; | |
35 | } | |
36 | ||
5c75a0a3 | 37 | public function print_grades() { |
1b074625 | 38 | global $CFG; |
a2422359 | 39 | |
caffc55a | 40 | $export_tracking = $this->track_exports(); |
11745964 | 41 | |
3674c398 | 42 | $strgrades = get_string('grades'); |
97599c0a | 43 | |
caffc55a | 44 | switch ($this->separator) { |
45 | case 'comma': | |
46 | $separator = ","; | |
47 | break; | |
eb859919 | 48 | case 'tab': |
caffc55a | 49 | default: |
50 | $separator = "\t"; | |
a2422359 | 51 | } |
ba74762b | 52 | |
53 | /// Print header to force download | |
1aee8c7e | 54 | if (strpos($CFG->wwwroot, 'https://') === 0) { //https sites - watch out for IE! KB812935 and KB316431 |
55 | @header('Cache-Control: max-age=10'); | |
56 | @header('Expires: '. gmdate('D, d M Y H:i:s', 0) .' GMT'); | |
57 | @header('Pragma: '); | |
58 | } else { //normal http - prevent caching at all cost | |
59 | @header('Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0'); | |
60 | @header('Expires: '. gmdate('D, d M Y H:i:s', 0) .' GMT'); | |
61 | @header('Pragma: no-cache'); | |
62 | } | |
ba74762b | 63 | header("Content-Type: application/download\n"); |
8ebbb06a SH |
64 | $shortname = format_string($this->course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $this->course->id))); |
65 | $downloadfilename = clean_filename("$shortname $strgrades"); | |
c10ddfb3 | 66 | header("Content-Disposition: attachment; filename=\"$downloadfilename.txt\""); |
67 | ||
68 | /// Print names of all the fields | |
caffc55a | 69 | echo get_string("firstname").$separator. |
70 | get_string("lastname").$separator. | |
71 | get_string("idnumber").$separator. | |
72 | get_string("institution").$separator. | |
73 | get_string("department").$separator. | |
c10ddfb3 | 74 | get_string("email"); |
ba74762b | 75 | |
caffc55a | 76 | foreach ($this->columns as $grade_item) { |
77 | echo $separator.$this->format_column_name($grade_item); | |
78 | ||
79 | /// add a feedback column | |
80 | if ($this->export_feedback) { | |
81 | echo $separator.$this->format_column_name($grade_item, true); | |
ba74762b | 82 | } |
c10ddfb3 | 83 | } |
caffc55a | 84 | echo "\n"; |
ba74762b | 85 | |
c10ddfb3 | 86 | /// Print all the lines of data. |
eb859919 | 87 | $geub = new grade_export_update_buffer(); |
caffc55a | 88 | $gui = new graded_users_iterator($this->course, $this->columns, $this->groupid); |
78ab98bc | 89 | $gui->require_active_enrolment($this->onlyactive); |
caffc55a | 90 | $gui->init(); |
91 | while ($userdata = $gui->next_user()) { | |
ba74762b | 92 | |
caffc55a | 93 | $user = $userdata->user; |
11745964 | 94 | |
caffc55a | 95 | echo $user->firstname.$separator.$user->lastname.$separator.$user->idnumber.$separator.$user->institution.$separator.$user->department.$separator.$user->email; |
a2422359 | 96 | |
caffc55a | 97 | foreach ($userdata->grades as $itemid => $grade) { |
eb859919 | 98 | if ($export_tracking) { |
99 | $status = $geub->track($grade); | |
100 | } | |
101 | ||
caffc55a | 102 | echo $separator.$this->format_grade($grade); |
ba74762b | 103 | |
caffc55a | 104 | if ($this->export_feedback) { |
105 | echo $separator.$this->format_feedback($userdata->feedbacks[$itemid]); | |
ba74762b | 106 | } |
c10ddfb3 | 107 | } |
caffc55a | 108 | echo "\n"; |
c10ddfb3 | 109 | } |
caffc55a | 110 | $gui->close(); |
eb859919 | 111 | $geub->close(); |
97599c0a | 112 | |
c10ddfb3 | 113 | exit; |
114 | } | |
115 | } | |
116 | ||
6c3ef410 | 117 |