"MDL-12304, fix double text"
[moodle-linuxchix.git] / grade / export / xls / grade_export_xls.php
blob2f473d3e75da8554e2ea6c77bba85a1ec632ccc6
1 <?php //$Id$
3 ///////////////////////////////////////////////////////////////////////////
4 // //
5 // NOTICE OF COPYRIGHT //
6 // //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
9 // //
10 // Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
11 // //
12 // This program is free software; you can redistribute it and/or modify //
13 // it under the terms of the GNU General Public License as published by //
14 // the Free Software Foundation; either version 2 of the License, or //
15 // (at your option) any later version. //
16 // //
17 // This program is distributed in the hope that it will be useful, //
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20 // GNU General Public License for more details: //
21 // //
22 // http://www.gnu.org/copyleft/gpl.html //
23 // //
24 ///////////////////////////////////////////////////////////////////////////
26 require_once($CFG->dirroot.'/grade/export/lib.php');
28 class grade_export_xls extends grade_export {
30 var $plugin = 'xls';
32 /**
33 * To be implemented by child classes
35 function print_grades() {
36 global $CFG;
37 require_once($CFG->dirroot.'/lib/excellib.class.php');
39 $export_tracking = $this->track_exports();
41 $strgrades = get_string('grades');
43 /// Calculate file name
44 $downloadfilename = clean_filename("{$this->course->shortname} $strgrades.xls");
45 /// Creating a workbook
46 $workbook = new MoodleExcelWorkbook("-");
47 /// Sending HTTP headers
48 $workbook->send($downloadfilename);
49 /// Adding the worksheet
50 $myxls =& $workbook->add_worksheet($strgrades);
52 /// Print names of all the fields
53 $myxls->write_string(0,0,get_string("firstname"));
54 $myxls->write_string(0,1,get_string("lastname"));
55 $myxls->write_string(0,2,get_string("idnumber"));
56 $myxls->write_string(0,3,get_string("institution"));
57 $myxls->write_string(0,4,get_string("department"));
58 $myxls->write_string(0,5,get_string("email"));
59 $pos=6;
60 foreach ($this->columns as $grade_item) {
61 $myxls->write_string(0, $pos++, $this->format_column_name($grade_item));
63 /// add a column_feedback column
64 if ($this->export_feedback) {
65 $myxls->write_string(0, $pos++, $this->format_column_name($grade_item, true));
69 /// Print all the lines of data.
70 $i = 0;
71 $geub = new grade_export_update_buffer();
72 $gui = new graded_users_iterator($this->course, $this->columns, $this->groupid);
73 $gui->init();
74 while ($userdata = $gui->next_user()) {
75 $i++;
76 $user = $userdata->user;
78 $myxls->write_string($i,0,$user->firstname);
79 $myxls->write_string($i,1,$user->lastname);
80 $myxls->write_string($i,2,$user->idnumber);
81 $myxls->write_string($i,3,$user->institution);
82 $myxls->write_string($i,4,$user->department);
83 $myxls->write_string($i,5,$user->email);
84 $j=6;
85 foreach ($userdata->grades as $itemid => $grade) {
86 if ($export_tracking) {
87 $status = $geub->track($grade);
90 $gradestr = $this->format_grade($grade);
91 if (is_numeric($gradestr)) {
92 $myxls->write_number($i,$j++,$gradestr);
94 else {
95 $myxls->write_string($i,$j++,$gradestr);
98 // writing feedback if requested
99 if ($this->export_feedback) {
100 $myxls->write_string($i, $j++, $this->format_feedback($userdata->feedbacks[$itemid]));
104 $gui->close();
105 $geub->close();
107 /// Close the workbook
108 $workbook->close();
110 exit;