Automatically generated installer lang files
[moodle.git] / grade / export / ods / grade_export_ods.php
1 <?php
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/>.
18 require_once($CFG->dirroot.'/grade/export/lib.php');
20 class grade_export_ods extends grade_export {
22     public $plugin = 'ods';
24     /**
25      * To be implemented by child classes
26      */
27     function print_grades() {
28         global $CFG;
29         require_once($CFG->dirroot.'/lib/odslib.class.php');
31         $export_tracking = $this->track_exports();
33         $strgrades = get_string('grades');
35         $shortname = format_string($this->course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $this->course->id)));
37     /// Calculate file name
38         $downloadfilename = clean_filename("$shortname $strgrades.ods");
39     /// Creating a workbook
40         $workbook = new MoodleODSWorkbook("-");
41     /// Sending HTTP headers
42         $workbook->send($downloadfilename);
43     /// Adding the worksheet
44         $myxls = $workbook->add_worksheet($strgrades);
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;
54         foreach ($this->columns as $grade_item) {
55             $myxls->write_string(0, $pos++, $this->format_column_name($grade_item));
57             /// add a column_feedback column
58             if ($this->export_feedback) {
59                 $myxls->write_string(0, $pos++, $this->format_column_name($grade_item, true));
60             }
61         }
63     /// Print all the lines of data.
64         $i = 0;
65         $geub = new grade_export_update_buffer();
66         $gui = new graded_users_iterator($this->course, $this->columns, $this->groupid);
67         $gui->require_active_enrolment($this->onlyactive);
68         $gui->init();
69         while ($userdata = $gui->next_user()) {
70             $i++;
71             $user = $userdata->user;
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) {
81                 if ($export_tracking) {
82                     $status = $geub->track($grade);
83                 }
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);
91                 }
93                 // writing feedback if requested
94                 if ($this->export_feedback) {
95                     $myxls->write_string($i, $j++, $this->format_feedback($userdata->feedbacks[$itemid]));
96                 }
97             }
98         }
99         $gui->close();
100         $geub->close();
102     /// Close the workbook
103         $workbook->close();
105         exit;
106     }