]> git.mjollnir.org Git - moodle.git/commitdiff
fix for MDL-9137, adding support for gradebook plugins for db, cron, events, permissi...
authortoyomoyo <toyomoyo>
Thu, 24 May 2007 02:16:31 +0000 (02:16 +0000)
committertoyomoyo <toyomoyo>
Thu, 24 May 2007 02:16:31 +0000 (02:16 +0000)
admin/cron.php
admin/index.php
grade/export/lib.php
grade/export/xml/index.php
grade/import/xml/index.php [new file with mode: 0755]
lib/accesslib.php
lib/eventslib.php

index 213456a1e85f140e40ac622a99312b034b3cdf0b..c3c17fb9a7c33a329182600f931de52aeeb19629 100644 (file)
             }
         }
     }
+    
+    // run gradebook import/export/report cron
+    if ($gradeimports = get_list_of_plugins('grade/import')) {
+        foreach ($gradeimports as $gradeimport) {           
+            if (file_exists($CFG->dirroot.'/grade/import/lib.php')) {
+                require_once($CFG->dirroot.'/grade/import/lib.php');
+                $cron_function = 'gradeimport_'.$gradeimport.'_cron';                                    
+                if (function_exists($cron_function)) {
+                    mtrace("Processing gradebook import function $cron_function ...", '');
+                    $cron_function;  
+                }
+            }
+        }      
+    }
+
+    if ($gradeexports = get_list_of_plugins('grade/export')) {
+        foreach ($gradeexports as $gradeexport) {           
+            if (file_exists($CFG->dirroot.'/grade/export/lib.php')) {
+                require_once($CFG->dirroot.'/grade/export/lib.php');
+                $cron_function = 'gradeexport_'.$gradeexport.'_cron';                                    
+                if (function_exists($cron_function)) {
+                    mtrace("Processing gradebook export function $cron_function ...", '');
+                    $cron_function;  
+                }
+            }
+        }
+    }
+    
+    if ($gradereports = get_list_of_plugins('grade/report')) {
+        foreach ($gradereports as $gradereport) {           
+            if (file_exists($CFG->dirroot.'/grade/report/lib.php')) {
+                require_once($CFG->dirroot.'/grade/report/lib.php');
+                $cron_function = 'gradereport_'.$gradereport.'_cron';                                    
+                if (function_exists($cron_function)) {
+                    mtrace("Processing gradebook report function $cron_function ...", '');
+                    $cron_function;  
+                }
+            }
+        }
+    }
 
     //Unset session variables and destroy it
     @session_unset();
index 3bbd7a11882ed9a1f96e7a29c88b32f69988a8d7..9eda697019885c18d38077c481b008ad10f8ebaf 100644 (file)
     require_once($CFG->dirroot.'/admin/mnet/adminlib.php');
     upgrade_RPC_functions("$CFG->wwwroot/$CFG->admin/index.php");  // Return here afterwards
 
+/// Upgrade all plugins for gradebook
+    upgrade_plugins('gradeexport', 'grade/export', "$CFG->wwwroot/$CFG->admin/index.php");
+    upgrade_plugins('gradeimport', 'grade/import', "$CFG->wwwroot/$CFG->admin/index.php");
+    upgrade_plugins('gradereport', 'grade/report', "$CFG->wwwroot/$CFG->admin/index.php");
 
 /// just make sure upgrade logging is properly terminated
     upgrade_log_finish();
index bdf916d82609fd28e92d3829b2e936a885a64312..651389e0f13aa019edc6e6625540c6f40fc123ec 100755 (executable)
@@ -22,7 +22,7 @@
 //          http://www.gnu.org/copyleft/gpl.html                         //
 //                                                                       //
 ///////////////////////////////////////////////////////////////////////////
-include_once('../../../config.php');
+
 include_once($CFG->dirroot.'/lib/gradelib.php');
 include_once($CFG->dirroot.'/grade/lib.php');
 /**
@@ -30,10 +30,15 @@ include_once($CFG->dirroot.'/grade/lib.php');
  * @input int id - course id
  */
 function print_gradeitem_selections($id, $params = NULL) {
-    
+    global $CFG;
     // print all items for selections
     // make this a standard function in lib maybe
-    if ($grade_items = grade_get_items($id)) {
+    //if ($grade_items = grade_get_items($id)) {
+        include_once('grade_export_form.php');
+        $mform = new grade_export_form(qualified_me(), array('id'=>$id));
+        $mform->display();
+    /*    
+        
         echo '<form action="index.php" method="post">';
         echo '<div>';
         foreach ($grade_items as $grade_item) {
@@ -52,7 +57,8 @@ function print_gradeitem_selections($id, $params = NULL) {
         echo '<input type="submit" value="'.get_string('submit').'" />';
         echo '</div>';
         echo '</form>';
-    }
+    */
+    //}
 }
 /**
  * Base export class
@@ -155,16 +161,19 @@ class grade_export {
                         $maxgrade = "$strmax: $gradeitem->grademax";
                     } else {
                         $maxgrade = "";
-                    } 
+                    }                    
                     
                     if (!empty($this->students)) {                    
                         foreach ($this->students as $student) {
-                      
+                            unset($studentgrade);
                             // add support for comment here MDL-9634
-                            $studentgrade = $itemgrades[$student->id];            
+                            
+                            if (!empty($itemgrades[$student->id])) {
+                                $studentgrade = $itemgrades[$student->id];
+                            }
                             
                             if (!empty($studentgrade->gradevalue)) {
-                                $this->grades[$student->id][$gradeitem->id] = $currentstudentgrade = $studentgrade->gradevalue;
+                                $this->grades[$student->id][$gradeitem->id] = $currentstudentgrade = $studentgrade->gradevalue;                                    
                             } else {
                                 $this->grades[$student->id][$gradeitem->id] = $currentstudentgrade = "";
                                 $this->gradeshtml[$student->id][$gradeitem->id] = "";
@@ -175,13 +184,14 @@ class grade_export {
                                 $this->totals[$student->id] = (float)($this->totals[$student->id]) + 0;
                             }
                             
-                            // load comments here
-                            $studentgrade->load_text();
-                            // get the actual comment
-                            $comment = $studentgrade->grade_grades_text->feedback;
-                            
-                            if (!empty($comment)) {
-                                $this->comments[$student->id][$gradeitem->id] = $comment;
+                            if (!empty($comment)) {                            
+                                // load comments here
+                                if ($studentgrade) {
+                                    $studentgrade->load_text();
+                                    // get the actual comment
+                                    $comment = $studentgrade->grade_grades_text->feedback;
+                                    $this->comments[$student->id][$gradeitem->id] = $comment;
+                                }
                             } else {
                                 $this->comments[$student->id][$gradeitem->id] = '';  
                             }
index 6c05ef18411c89a346598643641515fbef1cc098..280bf9a7a30ec6497890367f2c2a14548c5544de 100755 (executable)
@@ -39,7 +39,7 @@ if (($data = data_submitted()) && confirm_sesskey()) {
         
     // print the grades on screen for feedbacks
     $course = get_record('course', 'id', $id);
-    $action = 'exporttxt';
+    $action = 'exportxml';
     print_header($course->shortname.': '.get_string('grades'), $course->fullname, grade_nav($course, $action));
     
     $export = new grade_export($id, $data->itemids);
@@ -47,7 +47,7 @@ if (($data = data_submitted()) && confirm_sesskey()) {
     
     // this redirect should trigger a download prompt
     redirect('export.php?id='.$id.'&amp;itemids='.$itemidsurl);
-    exit; 
+    exit;
 }
 $course = get_record('course', 'id', $id);
 $action = 'exportxml';
diff --git a/grade/import/xml/index.php b/grade/import/xml/index.php
new file mode 100755 (executable)
index 0000000..4f6e3b8
--- /dev/null
@@ -0,0 +1,86 @@
+<?php
+
+/*
+ This is development code, and it is not finished
+$form = new custom_form_subclass(qualified_me(), array('somefield' => 'somevalue', 'someotherfield' => 'someothervalue') );
+and then in your subclass, in definition, you can access
+$this->_customdata['somefield']
+*/
+
+require_once('../../../config.php');
+
+// capability check
+$id = required_param('id', PARAM_INT); // course id
+// require_capability('moodle/site:uploadusers', get_context_instance(CONTEXT_SYSTEM));
+
+require_once('../grade_import_form.php');
+
+
+require_once($CFG->dirroot.'/grade/lib.php');
+$course = get_record('course', 'id', $id);
+$action = 'importxml';
+print_header($course->shortname.': '.get_string('grades'), $course->fullname, grade_nav($course, $action));
+
+$mform = new grade_import_form();
+
+//$mform2 = new grade_import_mapping_form();
+
+//if ($formdata = $mform2->get_data() ) {
+
+if ( $formdata = $mform->get_data() ) {
+
+    $filename = $mform->get_userfile_name();
+    
+    // Large files are likely to take their time and memory. Let PHP know
+    // that we'll take longer, and that the process should be recycled soon
+    // to free up memory.
+    @set_time_limit(0);
+    @raise_memory_limit("192M");
+    if (function_exists('apache_child_terminate')) {
+        @apache_child_terminate();
+    }
+
+    $text = my_file_get_contents($filename);
+    // trim utf-8 bom
+    $textlib = new textlib();
+    $text = $textlib->trim_utf8_bom($text);
+    // Fix mac/dos newlines
+    $text = preg_replace('!\r\n?!',"\n",$text);
+
+    // text is the text, we should xmlize it
+    include_once($CFG->dirroot.'/lib/xmlize.php');   
+    $content = xmlize($text);    
+    
+    if ($results = $content['results']['#']['result']) {
+        foreach ($results as $result) {
+            unset ($eventdata);
+            
+            $eventdata->idnumber = $result['#']['assignment'][0]['#'];
+            $eventdata->userid = $result['#']['student'][0]['#'];
+            $eventdata->gradevalue = $result['#']['score'][0]['#'];
+            
+            trigger_event('grade_added', $eventdata);           
+            echo "<br/>triggering event for $eventdata->idnumber... student id is $eventdata->userid and grade is $eventdata->gradevalue";          
+        }      
+    }    
+  
+} else {
+    $mform->display();
+}
+print_footer();
+
+function my_file_get_contents($filename, $use_include_path = 0) {
+    /// Returns the file as one big long string
+
+    $data = "";
+    $file = @fopen($filename, "rb", $use_include_path);
+    if ($file) {
+        while (!feof($file)) {
+            $data .= fread($file, 1024);
+        }
+        fclose($file);
+    }
+    return $data;
+}
+?>
\ No newline at end of file
index ec9fe5dcc3a4aaba2bef90faf8e516f31d029683..0ae8659c21d31625045eb7bce1fbc8f87587d67b 100755 (executable)
@@ -2406,10 +2406,19 @@ function load_capability_def($component) {
                                 's/'.$compparts[1].'/db/access.php';
             $varprefix = $compparts[0].'_'.$compparts[1];
         } else if ($compparts[0] == 'format') {
-            // Similar to the above, course formats are 'format' while they 
+            // Similar to the above, course formats are 'format' while they
             // are stored in 'course/format'.
             $defpath = $CFG->dirroot.'/course/'.$component.'/db/access.php';
             $varprefix = $compparts[0].'_'.$compparts[1];
+        } else if ($compparts[0] == 'gradeimport') {
+            $defpath = $CFG->dirroot.'/grade/import/'.$component.'/db/access.php';
+            $varprefix = $component;
+        } else if ($compparts[0] == 'gradeexport') {
+            $defpath = $CFG->dirroot.'/grade/export/'.$component.'/db/access.php';
+            $varprefix = $component;
+        } else if ($compparts[0] == 'gradereport') {
+            $defpath = $CFG->dirroot.'/grade/report/'.$component.'/db/access.php';
+            $varprefix = $component;
         } else {
             $defpath = $CFG->dirroot.'/'.$component.'/db/access.php';
             $varprefix = str_replace('/', '_', $component);
index 1620b6c184545d063ddcd5e090d83dabf0271c2f..3550962ba44d0a107f8a30131c4385fb4eacdf52 100755 (executable)
@@ -39,6 +39,15 @@ function events_load_def($component) {
             // are stored in 'course/format'.
             $defpath = $CFG->dirroot.'/course/format/'.$compparts[1].'/db/events.php';
 
+        } else if ($compparts[0] == 'gradeimport') {
+            $defpath = $CFG->dirroot.'/grade/import/'.$compparts[1].'/db/events.php';  
+        
+        } else if ($compparts[0] == 'gradeexport') {
+            $defpath = $CFG->dirroot.'/grade/export/'.$compparts[1].'/db/events.php'; 
+        
+        } else if ($compparts[0] == 'gradereport') {
+            $defpath = $CFG->dirroot.'/grade/report/'.$compparts[1].'/db/events.php'; 
+        
         } else {
             $defpath = $CFG->dirroot.'/'.$component.'/db/events.php';
         }