2 ///////////////////////////////////////////////////////////////////////////
4 // NOTICE OF COPYRIGHT //
6 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
7 // http://moodle.com //
9 // Copyright (C) 2001-2003 Martin Dougiamas http://dougiamas.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_ods
extends grade_export
{
29 var $format = 'ods'; // export format
32 * To be implemented by child classes
34 function print_grades() {
36 require_once($CFG->dirroot
.'/lib/odslib.class.php');
38 /// Calculate file name
39 $downloadfilename = clean_filename("$course->shortname $this->strgrades.ods");
40 /// Creating a workbook
41 $workbook = new MoodleODSWorkbook("-");
42 /// Sending HTTP headers
43 $workbook->send($downloadfilename);
44 /// Adding the worksheet
45 $myxls =& $workbook->add_worksheet($this->strgrades
);
47 /// Print names of all the fields
48 $myxls->write_string(0,0,get_string("firstname"));
49 $myxls->write_string(0,1,get_string("lastname"));
50 $myxls->write_string(0,2,get_string("idnumber"));
51 $myxls->write_string(0,3,get_string("institution"));
52 $myxls->write_string(0,4,get_string("department"));
53 $myxls->write_string(0,5,get_string("email"));
55 foreach ($this->columns
as $column) {
56 $myxls->write_string(0,$pos++
,strip_tags($column));
58 $myxls->write_string(0,$pos,get_string("total"));
60 /// Print all the lines of data.
62 if (!empty($this->grades
)) {
63 foreach ($this->grades
as $studentid => $studentgrades) {
65 $student = $students[$studentid];
66 if (empty($this->totals
[$student->id
])) {
67 $this->totals
[$student->id
] = '';
70 $myxls->write_string($i,0,$student->firstname
);
71 $myxls->write_string($i,1,$student->lastname
);
72 $myxls->write_string($i,2,$student->idnumber
);
73 $myxls->write_string($i,3,$student->institution
);
74 $myxls->write_string($i,4,$student->department
);
75 $myxls->write_string($i,5,$student->email
);
77 foreach ($studentgrades as $grade) {
78 if (is_numeric($grade)) {
79 $myxls->write_number($i,$j++
,strip_tags($grade));
82 $myxls->write_string($i,$j++
,strip_tags($grade));
85 $myxls->write_number($i,$j,$this->totals
[$student->id
]);
89 /// Close the workbook