Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/grade/export/xls/grade_export_xls.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 require_once($CFG->dirroot.'/grade/export/lib.php');
00019 
00020 class grade_export_xls extends grade_export {
00021 
00022     public $plugin = 'xls';
00023 
00027     public function print_grades() {
00028         global $CFG;
00029         require_once($CFG->dirroot.'/lib/excellib.class.php');
00030 
00031         $export_tracking = $this->track_exports();
00032 
00033         $strgrades = get_string('grades');
00034 
00036         $shortname = format_string($this->course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $this->course->id)));
00037         $downloadfilename = clean_filename("$shortname $strgrades.xls");
00039         $workbook = new MoodleExcelWorkbook("-");
00041         $workbook->send($downloadfilename);
00043         $myxls =& $workbook->add_worksheet($strgrades);
00044 
00046         $myxls->write_string(0,0,get_string("firstname"));
00047         $myxls->write_string(0,1,get_string("lastname"));
00048         $myxls->write_string(0,2,get_string("idnumber"));
00049         $myxls->write_string(0,3,get_string("institution"));
00050         $myxls->write_string(0,4,get_string("department"));
00051         $myxls->write_string(0,5,get_string("email"));
00052         $pos=6;
00053         foreach ($this->columns as $grade_item) {
00054             $myxls->write_string(0, $pos++, $this->format_column_name($grade_item));
00055 
00057             if ($this->export_feedback) {
00058                 $myxls->write_string(0, $pos++, $this->format_column_name($grade_item, true));
00059             }
00060         }
00061 
00063         $i = 0;
00064         $geub = new grade_export_update_buffer();
00065         $gui = new graded_users_iterator($this->course, $this->columns, $this->groupid);
00066         $gui->init();
00067         while ($userdata = $gui->next_user()) {
00068             $i++;
00069             $user = $userdata->user;
00070 
00071             $myxls->write_string($i,0,$user->firstname);
00072             $myxls->write_string($i,1,$user->lastname);
00073             $myxls->write_string($i,2,$user->idnumber);
00074             $myxls->write_string($i,3,$user->institution);
00075             $myxls->write_string($i,4,$user->department);
00076             $myxls->write_string($i,5,$user->email);
00077             $j=6;
00078             foreach ($userdata->grades as $itemid => $grade) {
00079                 if ($export_tracking) {
00080                     $status = $geub->track($grade);
00081                 }
00082 
00083                 $gradestr = $this->format_grade($grade);
00084                 if (is_numeric($gradestr)) {
00085                     $myxls->write_number($i,$j++,$gradestr);
00086                 }
00087                 else {
00088                     $myxls->write_string($i,$j++,$gradestr);
00089                 }
00090 
00091                 // writing feedback if requested
00092                 if ($this->export_feedback) {
00093                     $myxls->write_string($i, $j++, $this->format_feedback($userdata->feedbacks[$itemid]));
00094                 }
00095             }
00096         }
00097         $gui->close();
00098         $geub->close();
00099 
00101         $workbook->close();
00102 
00103         exit;
00104     }
00105 }
00106 
00107 
 All Data Structures Namespaces Files Functions Variables Enumerations