]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-13836 - When grades are imported, list users who had grades imported, but who...
authortjhunt <tjhunt>
Fri, 7 Mar 2008 17:30:54 +0000 (17:30 +0000)
committertjhunt <tjhunt>
Fri, 7 Mar 2008 17:30:54 +0000 (17:30 +0000)
grade/import/lib.php
lang/en_utf8/grades.php

index 255925809ef7ab1249fc99754584ce3d64b310cc..dc55db553f755e3ca729c06d8f5ea7d9d16dd811 100755 (executable)
@@ -137,6 +137,16 @@ function grade_import_commit($courseid, $importcode, $importfeedback=true, $verb
 
     if ($verbose) {
         notify(get_string('importsuccess', 'grades'), 'notifysuccess');
+        $unenrolledusers = get_unenrolled_users_in_import($importcode, $courseid);
+        if ($unenrolledusers) {
+            $list = "<ul>\n";
+            foreach ($unenrolledusers as $u) {
+                $u->fullname = fullname($u);
+                $list .= '<li>' . get_string('usergrade', 'grades', $u) . '</li>';
+            }
+            $list .= "</ul>\n";
+            notify(get_string('unenrolledusersinimport', 'grades', $list), 'notifysuccess');
+        }
         print_continue($CFG->wwwroot.'/grade/index.php?id='.$courseid);
     }
     // clean up
@@ -145,6 +155,39 @@ function grade_import_commit($courseid, $importcode, $importfeedback=true, $verb
     return true;
 }
 
+/**
+ * This function returns an array of grades that were included in the import,
+ * but wherer the user does not currenly have a graded role on the course. These gradse 
+ * are still stored in the database, but will not be visible in the gradebook unless
+ * this user subsequently enrols on the course in a graded roles.
+ *
+ * The returned objects have fields user firstname, lastname and useridnumber, and gradeidnumber.
+ *
+ * @param integer $importcode import batch identifier
+ * @param integer $courseid the course we are importing to.
+ * @return mixed and array of user objects, or false if none.
+ */
+function get_unenrolled_users_in_import($importcode, $courseid) {
+    global $CFG;
+    $relatedctxcondition = get_related_contexts_string(get_context_instance(CONTEXT_COURSE, $courseid));
+    
+    $sql = "SELECT giv.id, u.firstname, u.lastname, u.idnumber AS useridnumber, 
+                COALESCE(gi.idnumber, gin.itemname) AS gradeidnumber
+            FROM
+                {$CFG->prefix}grade_import_values giv
+                JOIN {$CFG->prefix}user u ON giv.userid = u.id
+                LEFT JOIN {$CFG->prefix}grade_items gi ON gi.id = giv.itemid
+                LEFT JOIN {$CFG->prefix}grade_import_newitem gin ON gin.id = giv.newgradeitem
+                LEFT JOIN {$CFG->prefix}role_assignments ra ON (giv.userid = ra.userid AND
+                    ra.roleid IN ($CFG->gradebookroles) AND
+                    ra.contextid $relatedctxcondition)
+                WHERE giv.importcode = $importcode
+                    AND ra.id IS NULL
+                ORDER BY gradeidnumber, u.lastname, u.firstname";
+
+    return get_records_sql($sql);
+}
+
 /**
  * removes entries from grade import buffer tables grade_import_value and grade_import_newitem
  * after a successful import, or during an import abort
index 47dc41b600dfd2e2dc9d7254b911f7bc8b692869..1ecff99884fa5b89456ca8ceaff5afcd2090bd9f 100644 (file)
@@ -489,6 +489,7 @@ $string['typevalue'] = 'Value';
 $string['updatedgradesonly'] = 'Export new or updated grades only';
 $string['uncategorised'] = 'Uncategorised';
 $string['unchangedgrade'] = 'Grade unchanged';
+$string['unenrolledusersinimport'] = 'This import included the following grades for users not currently enrolled in this course: $a';
 $string['unlock'] = 'Unlock';
 $string['unlockverbose'] = 'Unlock $a->category$a->itemmodule $a->itemname';
 $string['unused'] = 'Unused';
@@ -500,6 +501,7 @@ $string['usenooutcome'] = 'Use no outcome';
 $string['usenoscale'] = 'Use no scale';
 $string['usepercent'] = 'Use percent';
 $string['user'] = 'User';
+$string['usergrade'] = 'User $a->fullname ($a->useridnumber) on item $a->gradeidnumber';
 $string['userkeyhelp'] = 'Select a saved key that will give users access to the data published by this export plugin, without having to log into Moodle. Select `create a new user key` to generate a new key when submitting this form.';
 $string['userpreferences'] = 'User preferences';
 $string['useweighted'] = 'Use weighted';