]> git.mjollnir.org Git - moodle.git/commitdiff
allow comments, lock checking for xml plugin
authortoyomoyo <toyomoyo>
Tue, 17 Jul 2007 08:40:35 +0000 (08:40 +0000)
committertoyomoyo <toyomoyo>
Tue, 17 Jul 2007 08:40:35 +0000 (08:40 +0000)
grade/import/csv/index.php
grade/import/grade_import_form.php
grade/import/xml/index.php

index 6782547ee294fa671a7f3c1219c6856424657bcf..b363f30d11cd8e5f62568215b26101a42ae1813d 100755 (executable)
@@ -2,7 +2,6 @@
 require_once('../../../config.php');
 include_once($CFG->libdir.'/gradelib.php');
 
-
 $id = required_param('id', PARAM_INT); // course id
 $course = get_record('course', 'id', $id); // actual course
 
@@ -65,6 +64,23 @@ if (($formdata = data_submitted()) && !empty($formdata->map)) {
     // if mapping informatioin is supplied
     $map[clean_param($formdata->mapfrom, PARAM_RAW)] = clean_param($formdata->mapto, PARAM_RAW);
 
+    // check for mapto collisions
+    $maperrors = array();
+    foreach ($map as $i=>$j) {
+        if ($j == 0) {
+            // you can have multiple ignores
+            continue;  
+        } else {
+            if (!isset($maperrors[$j])) {
+                $maperrors[$j] = true;      
+            } else {
+                // collision  
+                unlink($filename); // needs to be uploaded again, sorry
+                error('mapping collision detected, 2 fields maps to the same grdae item '.$j);
+            }
+        }
+    }
+
     // 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.
@@ -184,12 +200,12 @@ if (($formdata = data_submitted()) && !empty($formdata->map)) {
                         // if not, put it in                        
                         // else, insert grade into the table
                     break;
-                    case 'feeback':
+                    case 'feedback':
                         if ($t1) {
                             // t1 is the id of the grade item
                             $feedback -> itemid = $t1;
                             $feedback -> feedback = $value;
-                            $newfeedback[] = $feedback;
+                            $newfeedbacks[] = $feedback;
                         }
                     break;                  
                     default:
@@ -197,7 +213,9 @@ if (($formdata = data_submitted()) && !empty($formdata->map)) {
                         if (!empty($map[$key]) && $value!=="") {
                             
                             // non numeric grade value supplied, possibly mapped wrong column
-                            if (!is_numeric($value)) {                                
+                            if (!is_numeric($value)) {
+                                echo "<br/>t0 is $t0";
+                                echo "<br/>grade is $value";
                                 $status = false;                                
                                 import_cleanup($importcode);
                                 notify(get_string('badgrade', 'grades'));
@@ -274,7 +292,7 @@ if (($formdata = data_submitted()) && !empty($formdata->map)) {
             // updating/inserting all comments here
             if (!empty($newfeedbacks)) {
                 foreach ($newfeedbacks as $newfeedback) {
-                    if ($feedback = get_record('grade_import_values', 'importcode', $importcode, 'userid', $studentid, 'itemid', $newfeedback->itemid)) {
+                    if ($feedback = get_record('grade_import_values', 'import_code', $importcode, 'userid', $studentid, 'itemid', $newfeedback->itemid)) {
                         $newfeedback ->id = $feedback ->id;
                         update_record('grade_import_values', $newfeedback);
                     } else {
index 4ab0777e91dc4eb206d54e510f719b299dc9bcf3..9f1685ead57aed80d9c9d083c652376afc29699c 100755 (executable)
@@ -37,7 +37,6 @@ class grade_import_mapping_form extends moodleform {
     
     function definition () {
         global $CFG;
-        
         $mform =& $this->_form;
 
         // this is an array of headers
@@ -48,7 +47,7 @@ class grade_import_mapping_form extends moodleform {
 
         $mform->addElement('header', 'general', get_string('identifier', 'grades'));
         $mapfromoptions = array();
-        
+
         if ($header) {
             foreach ($header as $i=>$h) {
                 $mapfromoptions[$i] = $h;
@@ -63,35 +62,41 @@ class grade_import_mapping_form extends moodleform {
         
         $mform->addElement('header', 'general', get_string('mappings', 'grades'));
         
-        $gradeitems = $this->_customdata['gradeitems'];
+        // add a comment option
+
+        if ($gradeitems = $this->_customdata['gradeitems']) {
+            $comments = array();            
+            foreach ($gradeitems as $itemid => $itemname) {
+                $comments['feedback_'.$itemid] = 'comments for '.$itemname;            
+            }  
+        }
 
         include_once($CFG->libdir.'/gradelib.php');
 
         if ($header) {          
             $i = 0; // index
             foreach ($header as $h) {
-                $h = trim($h);
-                // this is the order of the headers
-                // $mform->addElement('hidden', 'maps[]', $h);
-                
-                // this is what they map to        
-                $mapfromoptions = array('0'=>'ignore', 'new'=>'new gradeitem') + $gradeitems;
 
-                $mform->addElement('select', 'mapping_'.$i, s($h), $mapfromoptions);
+                $h = trim($h);
+                // this is what each header maps to        
+                $mform->addElement('selectgroups', 
+                                   'mapping_'.$i, s($h), 
+                                   array('others'=>array('0'=>'ignore', 'new'=>'new gradeitem'), 
+                                         'gradeitems'=>$gradeitems, 
+                                         'comments'=>$comments));
                 $i++;
             }
         }
-        
+
         // find a non-conflicting file name based on time stamp
         $newfilename = 'cvstemp_'.time();
         while (file_exists($CFG->dataroot.'/temp/'.$newfilename)) {
             $newfilename = 'cvstemp_'.time();
         }
-        
+
         // move the uploaded file
         move_uploaded_file($filename, $CFG->dataroot.'/temp/'.$newfilename);
-        
+
         // course id needs to be passed for auth purposes
         $mform->addElement('hidden', 'map', 1);
         $mform->setType('map', PARAM_INT);
@@ -101,7 +106,7 @@ class grade_import_mapping_form extends moodleform {
         $mform->addElement('hidden', 'filename', $newfilename);
         $mform->setType('filename', PARAM_FILE);
         $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));        
-        
+
     }
 }
 ?>
index a2478d22232e377c50e148e6fed46a280dcb57df..697839661cf40abb37200e820b5a8aba5cf696d2 100755 (executable)
@@ -10,12 +10,14 @@ $id = required_param('id', PARAM_INT); // course id
 $course = get_record('course', 'id', $id); // actual course
 
 // capability check
+require_login($id);
 require_capability('moodle/course:managegrades', get_context_instance(CONTEXT_COURSE, $course->id));
 
 require_once('../lib.php');
 require_once('../grade_import_form.php');
 require_once($CFG->dirroot.'/grade/lib.php');
 
+// print header
 $strgrades = get_string('grades', 'grades');
 $actionstr = get_string('importxml', 'grades');
 $gradenav = "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>";
@@ -87,6 +89,22 @@ if ( $formdata = $mform->get_data()) {
                 break;
             }
             
+            // grade item locked, abort
+            if ($gradeitem->locked) {
+                $status = false;
+                notify(get_string('gradeitemlocked', 'grades'));
+                break 3;  
+            }                    
+            
+            // check if grade_grades is locked and if so, abort
+            if ($grade_grades = new grade_grades(array('itemid'=>$gradeitem->id, 'userid'=>$result['#']['student'][0]['#']))) {
+                if ($grade_grades->locked) {
+                    // individual grade locked, abort
+                    $status = false;
+                    notify(get_string('gradegradeslocked', 'grades'));
+                    break 2;
+                }
+            }
             unset($newgrade);
 
             if (isset($result['#']['score'][0]['#'])) {
@@ -109,7 +127,7 @@ if ( $formdata = $mform->get_data()) {
                     notify(get_string('baduserid', 'grades'));
                     notify(get_string('importfailed', 'grades'));
                     break;
-                }
+                }           
           
                 // check grade value is a numeric grade
                 if (!is_numeric($newgrade->rawgrade)) {