MDL-13836 - When grades are imported, list users who had grades imported, but who are not currenly in the course.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -490,6 +490,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';
|
||||
@@ -501,6 +502,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';
|
||||
|
||||
Reference in New Issue
Block a user