Automatically generated installer lang files
[moodle.git] / grade / export / ods / grade_export_ods.php
CommitLineData
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
18require_once($CFG->dirroot.'/grade/export/lib.php');
19
20class grade_export_ods extends grade_export {
ba74762b 21
5c75a0a3 22 public $plugin = 'ods';
caffc55a 23
c10ddfb3 24 /**
25 * To be implemented by child classes
26 */
caffc55a 27 function print_grades() {
ba74762b 28 global $CFG;
a2422359 29 require_once($CFG->dirroot.'/lib/odslib.class.php');
ba74762b 30
caffc55a 31 $export_tracking = $this->track_exports();
32
3674c398 33 $strgrades = get_string('grades');
ba74762b 34
8ebbb06a
SH
35 $shortname = format_string($this->course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $this->course->id)));
36
c10ddfb3 37 /// Calculate file name
8ebbb06a 38 $downloadfilename = clean_filename("$shortname $strgrades.ods");
c10ddfb3 39 /// Creating a workbook
40 $workbook = new MoodleODSWorkbook("-");
41 /// Sending HTTP headers
42 $workbook->send($downloadfilename);
43 /// Adding the worksheet
a530b69d 44 $myxls = $workbook->add_worksheet($strgrades);
ba74762b 45
c10ddfb3 46 /// Print names of all the fields
47 $myxls->write_string(0,0,get_string("firstname"));
48 $myxls->write_string(0,1,get_string("lastname"));
49 $myxls->write_string(0,2,get_string("idnumber"));
50 $myxls->write_string(0,3,get_string("institution"));
51 $myxls->write_string(0,4,get_string("department"));
52 $myxls->write_string(0,5,get_string("email"));
53 $pos=6;
caffc55a 54 foreach ($this->columns as $grade_item) {
55 $myxls->write_string(0, $pos++, $this->format_column_name($grade_item));
ba74762b 56
57 /// add a column_feedback column
caffc55a 58 if ($this->export_feedback) {
59 $myxls->write_string(0, $pos++, $this->format_column_name($grade_item, true));
a216f661 60 }
c10ddfb3 61 }
ba74762b 62
c10ddfb3 63 /// Print all the lines of data.
64 $i = 0;
eb859919 65 $geub = new grade_export_update_buffer();
caffc55a 66 $gui = new graded_users_iterator($this->course, $this->columns, $this->groupid);
78ab98bc 67 $gui->require_active_enrolment($this->onlyactive);
caffc55a 68 $gui->init();
69 while ($userdata = $gui->next_user()) {
70 $i++;
71 $user = $userdata->user;
72
73 $myxls->write_string($i,0,$user->firstname);
74 $myxls->write_string($i,1,$user->lastname);
75 $myxls->write_string($i,2,$user->idnumber);
76 $myxls->write_string($i,3,$user->institution);
77 $myxls->write_string($i,4,$user->department);
78 $myxls->write_string($i,5,$user->email);
79 $j=6;
80 foreach ($userdata->grades as $itemid => $grade) {
eb859919 81 if ($export_tracking) {
82 $status = $geub->track($grade);
83 }
84
caffc55a 85 $gradestr = $this->format_grade($grade);
86 if (is_numeric($gradestr)) {
87 $myxls->write_number($i,$j++,$gradestr);
88 }
89 else {
90 $myxls->write_string($i,$j++,$gradestr);
c10ddfb3 91 }
ba74762b 92
caffc55a 93 // writing feedback if requested
94 if ($this->export_feedback) {
95 $myxls->write_string($i, $j++, $this->format_feedback($userdata->feedbacks[$itemid]));
c10ddfb3 96 }
c10ddfb3 97 }
98 }
caffc55a 99 $gui->close();
eb859919 100 $geub->close();
c10ddfb3 101
102 /// Close the workbook
103 $workbook->close();
ba74762b 104
c10ddfb3 105 exit;
106 }
107}
108
6c3ef410 109