Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/grade/export/ods/grade_export_ods.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_ods extends grade_export {
00021 
00022     public $plugin = 'ods';
00023 
00027     function print_grades() {
00028         global $CFG;
00029         require_once($CFG->dirroot.'/lib/odslib.class.php');
00030 
00031         $export_tracking = $this->track_exports();
00032 
00033         $strgrades = get_string('grades');
00034 
00035         $shortname = format_string($this->course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $this->course->id)));
00036 
00038         $downloadfilename = clean_filename("$shortname $strgrades.ods");
00040         $workbook = new MoodleODSWorkbook("-");
00042         $workbook->send($downloadfilename);
00044         $myxls =& $workbook->add_worksheet($strgrades);
00045 
00047         $myxls->write_string(0,0,get_string("firstname"));
00048         $myxls->write_string(0,1,get_string("lastname"));
00049         $myxls->write_string(0,2,get_string("idnumber"));
00050         $myxls->write_string(0,3,get_string("institution"));
00051         $myxls->write_string(0,4,get_string("department"));
00052         $myxls->write_string(0,5,get_string("email"));
00053         $pos=6;
00054         foreach ($this->columns as $grade_item) {
00055             $myxls->write_string(0, $pos++, $this->format_column_name($grade_item));
00056 
00058             if ($this->export_feedback) {
00059                 $myxls->write_string(0, $pos++, $this->format_column_name($grade_item, true));
00060             }
00061         }
00062 
00064         $i = 0;
00065         $geub = new grade_export_update_buffer();
00066         $gui = new graded_users_iterator($this->course, $this->columns, $this->groupid);
00067         $gui->init();
00068         while ($userdata = $gui->next_user()) {
00069             $i++;
00070             $user = $userdata->user;
00071 
00072             $myxls->write_string($i,0,$user->firstname);
00073             $myxls->write_string($i,1,$user->lastname);
00074             $myxls->write_string($i,2,$user->idnumber);
00075             $myxls->write_string($i,3,$user->institution);
00076             $myxls->write_string($i,4,$user->department);
00077             $myxls->write_string($i,5,$user->email);
00078             $j=6;
00079             foreach ($userdata->grades as $itemid => $grade) {
00080                 if ($export_tracking) {
00081                     $status = $geub->track($grade);
00082                 }
00083 
00084                 $gradestr = $this->format_grade($grade);
00085                 if (is_numeric($gradestr)) {
00086                     $myxls->write_number($i,$j++,$gradestr);
00087                 }
00088                 else {
00089                     $myxls->write_string($i,$j++,$gradestr);
00090                 }
00091 
00092                 // writing feedback if requested
00093                 if ($this->export_feedback) {
00094                     $myxls->write_string($i, $j++, $this->format_feedback($userdata->feedbacks[$itemid]));
00095                 }
00096             }
00097         }
00098         $gui->close();
00099         $geub->close();
00100 
00102         $workbook->close();
00103 
00104         exit;
00105     }
00106 }
00107 
00108 
 All Data Structures Namespaces Files Functions Variables Enumerations