\n".
get_string('showactions'),' ';
choose_from_menu($actionoptions,'action',0,'');
diff --git a/lang/en_utf8/error.php b/lang/en_utf8/error.php
index 9277ea5a73a..e44be2a8110 100644
--- a/lang/en_utf8/error.php
+++ b/lang/en_utf8/error.php
@@ -37,6 +37,7 @@ $string['invalidfieldname'] = '\"$a\" is not a valid field name';
$string['invalidfiletype'] = '\"$a\" is not a valid file type';
$string['invalidmd5'] = 'Invalid md5';
$string['invalidxmlfile'] = '\"$a\" is not a valid XML file';
+$string['invalidrole'] = 'Invalid role';
$string['missingfield'] = 'Field \"$a\" is missing';
$string['missingrequiredfield'] = 'Some required field is missing';
$string['modulerequirementsnotmet'] = 'Module \"$a->modulename\" ($a->moduleversion) could not be installed. It requires a newer version of Moodle (currently you are using $a->currentmoodle, you need $a->requiremoodle).';
diff --git a/lib/statslib.php b/lib/statslib.php
index 1d7cc22e6d4..7383fb33d48 100644
--- a/lib/statslib.php
+++ b/lib/statslib.php
@@ -138,26 +138,7 @@ function stats_cron_daily () {
continue;
}
- $primary_roles = 'SELECT ra.userid,
- ra.roleid AS primary_roleid,
- ra.contextid,
- r.sortorder,
- r.name,
- r.description,
- r.shortname,
- c.instanceid AS courseid,
- c.contextlevel
- FROM '.$CFG->prefix.'role_assignments ra
- INNER JOIN '.$CFG->prefix.'role r ON ra.roleid = r.id
- INNER JOIN '.$CFG->prefix.'context c ON ra.contextid = c.id
- WHERE NOT EXISTS (
- SELECT 1
- FROM '.$CFG->prefix.'role_assignments i_ra
- INNER JOIN '.$CFG->prefix.'role i_r ON i_ra.roleid = i_r.id
- WHERE ra.userid = i_ra.userid AND
- ra.contextid = i_ra.contextid AND
- i_r.sortorder < r.sortorder) ';
-
+ $primary_roles = stats_get_primary_role_subselect();
foreach ($roles as $role) {
// ENROLMENT FIRST....
// ALL users with this role...
@@ -1334,4 +1315,28 @@ function stats_upgrade_table_for_roles ($period) {
return true;
}
+function stats_get_primary_role_subselect() {
+ global $CFG;
+ return 'SELECT ra.userid,
+ ra.roleid AS primary_roleid,
+ ra.contextid,
+ r.sortorder,
+ r.name,
+ r.description,
+ r.shortname,
+ c.instanceid AS courseid,
+ c.contextlevel
+ FROM '.$CFG->prefix.'role_assignments ra
+ INNER JOIN '.$CFG->prefix.'role r ON ra.roleid = r.id
+ INNER JOIN '.$CFG->prefix.'context c ON ra.contextid = c.id
+ WHERE NOT EXISTS (
+ SELECT 1
+ FROM '.$CFG->prefix.'role_assignments i_ra
+ INNER JOIN '.$CFG->prefix.'role i_r ON i_ra.roleid = i_r.id
+ WHERE ra.userid = i_ra.userid AND
+ ra.contextid = i_ra.contextid AND
+ i_r.sortorder < r.sortorder
+ ) ';
+}
+
?>