MDL-11515:
[moodle-linuxchix.git] / grade / export / ods / grade_export_ods.php
blob5f254a719ed365e4f66eef70419096272edfb87b
1 <?php
2 ///////////////////////////////////////////////////////////////////////////
3 // //
4 // NOTICE OF COPYRIGHT //
5 // //
6 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
7 // http://moodle.com //
8 // //
9 // Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
10 // //
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. //
15 // //
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: //
20 // //
21 // http://www.gnu.org/copyleft/gpl.html //
22 // //
23 ///////////////////////////////////////////////////////////////////////////
25 require_once($CFG->dirroot.'/grade/export/lib.php');
27 class grade_export_ods extends grade_export {
29 var $plugin = 'ods';
31 /**
32 * To be implemented by child classes
34 function print_grades() {
35 global $CFG;
36 require_once($CFG->dirroot.'/lib/odslib.class.php');
38 $export_tracking = $this->track_exports();
40 $strgrades = get_string('grades', 'grade');
42 /// Calculate file name
43 $downloadfilename = clean_filename("{$this->course->shortname} $strgrades.ods");
44 /// Creating a workbook
45 $workbook = new MoodleODSWorkbook("-");
46 /// Sending HTTP headers
47 $workbook->send($downloadfilename);
48 /// Adding the worksheet
49 $myxls =& $workbook->add_worksheet($strgrades);
51 /// Print names of all the fields
52 $myxls->write_string(0,0,get_string("firstname"));
53 $myxls->write_string(0,1,get_string("lastname"));
54 $myxls->write_string(0,2,get_string("idnumber"));
55 $myxls->write_string(0,3,get_string("institution"));
56 $myxls->write_string(0,4,get_string("department"));
57 $myxls->write_string(0,5,get_string("email"));
58 $pos=6;
59 foreach ($this->columns as $grade_item) {
60 $myxls->write_string(0, $pos++, $this->format_column_name($grade_item));
62 /// add a column_feedback column
63 if ($this->export_feedback) {
64 $myxls->write_string(0, $pos++, $this->format_column_name($grade_item, true));
68 /// Print all the lines of data.
69 $i = 0;
70 $geub = new grade_export_update_buffer();
71 $gui = new graded_users_iterator($this->course, $this->columns, $this->groupid);
72 $gui->init();
73 while ($userdata = $gui->next_user()) {
74 $i++;
75 $user = $userdata->user;
77 $myxls->write_string($i,0,$user->firstname);
78 $myxls->write_string($i,1,$user->lastname);
79 $myxls->write_string($i,2,$user->idnumber);
80 $myxls->write_string($i,3,$user->institution);
81 $myxls->write_string($i,4,$user->department);
82 $myxls->write_string($i,5,$user->email);
83 $j=6;
84 foreach ($userdata->grades as $itemid => $grade) {
85 if ($export_tracking) {
86 $status = $geub->track($grade);
89 $gradestr = $this->format_grade($grade);
90 if (is_numeric($gradestr)) {
91 $myxls->write_number($i,$j++,$gradestr);
93 else {
94 $myxls->write_string($i,$j++,$gradestr);
97 // writing feedback if requested
98 if ($this->export_feedback) {
99 $myxls->write_string($i, $j++, $this->format_feedback($userdata->feedbacks[$itemid]));
103 $gui->close();
104 $geub->close();
106 /// Close the workbook
107 $workbook->close();
109 exit;