]> git.mjollnir.org Git - moodle.git/commitdiff
grade export plugins
authortoyomoyo <toyomoyo>
Thu, 10 May 2007 09:29:58 +0000 (09:29 +0000)
committertoyomoyo <toyomoyo>
Thu, 10 May 2007 09:29:58 +0000 (09:29 +0000)
grade/export/lib.php
grade/export/ods/grade_export_ods.php
grade/export/txt/grade_export_txt.php
grade/export/xls/grade_export_xls.php
grade/export/xml/grade_export_xml.php [new file with mode: 0755]

index 7ad1efd0310f2d23a37b54ea7e49d5fbe9c8ae96..92952754c9ac311519c6a26234df2cfb8932c435 100755 (executable)
@@ -34,6 +34,7 @@ class grade_export {
     var $totals = array();    // Collect all totals in this array
     var $columns = array();     // Accumulate column names in this array.
     var $columnhtml = array();  // Accumulate column html in this array. 
+    var $columnidnumbers = array(); // Collect all gradeitem id numbers
     var $course; // course
     
     // common strings
@@ -109,6 +110,7 @@ class grade_export {
             foreach ($gradeitems as $gradeitem) {
 
                 $this->columns[] = "$gradeitem->itemmodule: ".format_string($gradeitem->itemname,true)." - $gradeitem->maxgrade";
+                $this->columnidnumbers[] = $gradeitem->idnumber; // this might be needed for some export plugins  
             
                 if (!empty($gradeitem->maxgrade)) {
                     $maxgrade = "$strmax: $gradeitem->maxgrade";
index cb21fd078344ab1262377aab8e6cb09b9ab7c9db..6b38deddfb27357fee909ee17ca1a7a1f46fbc6b 100755 (executable)
@@ -31,7 +31,7 @@ class grade_export_ods extends grade_export {
     /**
      * To be implemented by child classes
      */
-    function print_grades() { 
+    function print_grades($feedback = false) { 
         
         require_once($CFG->dirroot.'/lib/odslib.class.php');
 
@@ -54,6 +54,11 @@ class grade_export_ods extends grade_export {
         $pos=6;
         foreach ($this->columns as $column) {
             $myxls->write_string(0,$pos++,strip_tags($column));
+            
+            /// add a column_feedback column            
+            if ($feedback) {
+                $myxls->write_string(0,$pos++,strip_tags($column."_feedback"));
+            }
         }
         $myxls->write_string(0,$pos,get_string("total"));
     
@@ -81,6 +86,11 @@ class grade_export_ods extends grade_export {
                     else {
                         $myxls->write_string($i,$j++,strip_tags($grade));
                     }
+                    
+                    // writing comment if requested
+                    if ($feedback) {
+                        $myxls->write_string($i,$j++,array_shift($this->comments[$student->id]));
+                    }   
                 }
                 $myxls->write_number($i,$j,$this->totals[$student->id]);
             }
index 664571e15b345538e73d40bcd455055f8ca18ced..144325a7b46860e871ceedfb80f0e538b264a274 100755 (executable)
@@ -31,7 +31,7 @@ class grade_export_txt extends grade_export {
     /**
      * To be implemented by child classes
      */
-    function print_grades() { 
+    function print_grades($feedback = false;) { 
         
 /// Print header to force download
 
@@ -50,6 +50,11 @@ class grade_export_txt extends grade_export {
         foreach ($this->columns as $column) {
             $column = strip_tags($column);
             echo "\t$column";
+        
+            /// add a column_feedback column            
+            if ($feedback) {
+                echo "\t{$column}_feedback";
+            }        
         }
         echo "\t".get_string("total")."\n";
     
@@ -62,7 +67,11 @@ class grade_export_txt extends grade_export {
             echo "$student->firstname\t$student->lastname\t$student->idnumber\t$student->institution\t$student->department\t$student->email";
             foreach ($studentgrades as $grade) {
                 $grade = strip_tags($grade);
-                echo "\t$grade";
+                echo "\t$grade";            
+                
+                if ($feedback) {
+                    echo "\t".array_shift($this->comments[$student->id]);
+                }       
             }
             echo "\t".$this->totals[$student->id];
             echo "\n";
index 412ff4c7e149eaee86c34be2788623c3c1f71959..c28bc26f19991a7a17b2dd8b25f9b8cc0a79d526 100755 (executable)
@@ -31,14 +31,14 @@ class grade_export_xls extends grade_export {
     /**
      * To be implemented by child classes
      */
-    function print_grades() { 
+    function print_grades($feedback = false) { 
         
         global $CFG; 
         
         require_once($CFG->dirroot.'/lib/excellib.class.php');
 
     /// Calculate file name
-        $downloadfilename = clean_filename("$course->shortname $this->strgrades.xls");
+        $downloadfilename = clean_filename("$this->course->shortname $this->strgrades.xls");
     /// Creating a workbook
         $workbook = new MoodleExcelWorkbook("-");
     /// Sending HTTP headers
@@ -56,6 +56,10 @@ class grade_export_xls extends grade_export {
         $pos=6;
         foreach ($this->columns as $column) {
             $myxls->write_string(0,$pos++,strip_tags($column));
+            /// add a column_feedback column            
+            if ($feedback) {
+                $myxls->write_string(0,$pos++,strip_tags($column."_feedback"));
+            }
         }
         $myxls->write_string(0,$pos,get_string("total"));
     
@@ -82,7 +86,12 @@ class grade_export_xls extends grade_export {
                     }
                     else {
                         $myxls->write_string($i,$j++,strip_tags($grade));
-                    }
+                    }                    
+                    
+                    // writing comment if requested
+                    if ($feedback) {
+                        $myxls->write_string($i,$j++,array_shift($this->comments[$student->id]));
+                    }   
                 }
                 $myxls->write_number($i,$j,$this->totals[$student->id]);
             }
diff --git a/grade/export/xml/grade_export_xml.php b/grade/export/xml/grade_export_xml.php
new file mode 100755 (executable)
index 0000000..c07c047
--- /dev/null
@@ -0,0 +1,101 @@
+<?php
+///////////////////////////////////////////////////////////////////////////
+//                                                                       //
+// NOTICE OF COPYRIGHT                                                   //
+//                                                                       //
+// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
+//          http://moodle.com                                            //
+//                                                                       //
+// Copyright (C) 2001-2003  Martin Dougiamas  http://dougiamas.com       //
+//                                                                       //
+// This program is free software; you can redistribute it and/or modify  //
+// it under the terms of the GNU General Public License as published by  //
+// the Free Software Foundation; either version 2 of the License, or     //
+// (at your option) any later version.                                   //
+//                                                                       //
+// This program is distributed in the hope that it will be useful,       //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
+// GNU General Public License for more details:                          //
+//                                                                       //
+//          http://www.gnu.org/copyleft/gpl.html                         //
+//                                                                       //
+///////////////////////////////////////////////////////////////////////////
+
+require_once($CFG->dirroot.'/grade/export/lib.php');
+
+class grade_export_xml extends grade_export {
+    
+    var $format = 'xml'; // export format
+    
+    /**
+     * To be implemented by child classes
+     */
+    function print_grades($feedback = false) { 
+        
+        global $CFG; 
+        
+        require_once($CFG->dirroot.'/lib/excellib.class.php');
+
+        /// Calculate file name
+        $downloadfilename = clean_filename("$this->course->shortname $this->strgrades.xml");        
+
+        header("Content-type: text/xml; charset=UTF-8"); 
+        header("Content-Disposition: attachment; filename=\"$downloadfilename\"");
+        
+        /// time stamp to ensure uniqueness of batch export
+        echo '<results batch="xml_export_'.time().'">';
+        foreach ($this->$columnidnumbers as $index => $idnumber) {
+            
+            // studentgrades[] index should match with corresponding $index 
+            foreach ($this->grades as $studentid => $studentgrades) {
+                echo '<result>';
+                
+                // state can be new, or regrade
+                // require comparing of timestamps in db
+                
+                $params->idnumber = $idnumber;
+                // get the grade item
+                $gradeitem = new grade_item($params);
+                
+                // we are trying to figure out if this is a new grade, or a regraded grade
+                // only relevant if this grade for this user is already exported
+                if ($gradeitem->exported) {
+                    
+                    // get the grade_grades_final for this user
+                    unset($params);
+                    $params->itemid = $gradeitem->id;
+                    $params->userid = $studentid;
+                
+                    $grade_grades_final = new grade_grades_final($params);
+                    
+                    // if exported, check grade_history, if modified after export, set state to regrade
+                
+                    if (record_exists_select('grade_hitory', 'itemid = '.$gradeitem->id.' AND userid = '.$studentid.' AND timemodified > '.$grade_grades_final->exported)) {
+                        $status = 'regrade';  
+                    } else {
+                        $status = 'new';  
+                    }
+                } else { 
+                    // never exported
+                    $status = 'new'; 
+                }
+                
+                echo '<state>'.$status.'</state>';
+                // only need id number
+                echo '<assignment>'.$idnumber.'</assignment>';
+                // this column should be customizable to use either student id, idnumber, uesrname or email.
+                echo '<student>'.$studentid.'</student>';
+                       echo '<score>'.$studentgrades[$index].'</score>';
+                       if ($feedback) {
+                    echo '<feedback>'.$this->comments[$studentid][$index].'</feedback>';  
+                       }
+                echo '</result>';
+            }           
+        }
+        echo '</results>';
+        exit; 
+    }
+}
+
+?>
\ No newline at end of file