diff --git a/admin/register.php b/admin/register.php
index bf9ffc834d1bd..33bf0837eed63 100644
--- a/admin/register.php
+++ b/admin/register.php
@@ -122,14 +122,25 @@
echo "\n";
echo '
';
- $count = count_records('user_students');
- echo get_string("enrolments").": ".$count;
- echo "\n";
+ // total number of role assignments
+ $count = count_records('role_assignments');
+ echo get_string("roleassignments").": ".$count;
+ echo "\n";
echo '
';
- $count = count_records('user_teachers');
- echo get_string("teachers").": ".$count;
- echo "\n";
+ // first find all distinct roles with mod/course:update
+ // please change the name and strings to something appropriate to reflect the new data collected
+ $sql = "SLECT COUNT(DISTINCT u.id)
+ FROM {$CFG->prefix}role_capabilities rc,
+ {$CFG->prefix}role_assignments ra,
+ {$CFG->prefix}user u
+ WHERE (rc.capability = 'mod/course:update' or rc.capability='moodle/site:doanything')
+ AND rc.roleid = ra.roleid
+ AND u.id = ra.userid";
+
+ $count = count_records_sql($sql);
+ echo get_string("courseupdates").": ".$count;
+ echo "\n";
echo '
';
$count = count_records('forum_posts');
diff --git a/blog/lib.php b/blog/lib.php
index d49f3fe02c0ae..58e2bf5e4de33 100755
--- a/blog/lib.php
+++ b/blog/lib.php
@@ -459,16 +459,11 @@ function fetch_entries($userid, $postid='', $fetchlimit=10, $fetchstart='', $fil
// all users with a role assigned
$context = get_context_instance(CONTEXT_COURSE, $filterselect);
- if ($parents = get_parent_contexts($context)) {
- $contextlists = 'OR ra.contextid IN ('.implode(',', $parents).'))';
- } else {
- $contextlists = ')';
- }
$SQL = '(SELECT '.$requiredfields.' FROM '.$CFG->prefix.'post p, '.$tagtablesql
.$CFG->prefix.'role_assignments ra, '.$CFG->prefix.'user u
WHERE p.userid = ra.userid '.$tagquerysql.'
- AND (ra.contextid = '.$context->id.' '.$contextlists.'
+ AND ra.contextid '.get_related_contexts_string($context).'
AND u.id = p.userid
AND (p.publishstate = \'site\' OR p.publishstate = \'public\' OR p.userid = '.$USER->id.'))';
} else {
diff --git a/course/report/stats/report.php b/course/report/stats/report.php
index cfbc812290032..4e9ed321aaa7e 100644
--- a/course/report/stats/report.php
+++ b/course/report/stats/report.php
@@ -31,7 +31,13 @@
}
$sql .= " ORDER BY s.roleid ";
} else {
- $sql = 'SELECT s.userid,u.firstname,u.lastname,u.idnumber,1 AS roleid FROM '.$CFG->prefix.'user_students s JOIN '.$CFG->prefix.'user u ON u.id = s.userid WHERE course = '.$course->id;
+ $context = get_context_instance(CONTEXT_COURSE, $course->id);
+
+ $sql = 'SELECT ra.userid,u.firstname,u.lastname,u.idnumber,1 AS roleid
+ FROM '.$CFG->prefix.'role_assignments ra,
+ '.$CFG->prefix.'user u
+ WHERE u.id = ra.userid
+ AND ra.contextid '.get_related_contexts_string($context);
}
if (!$us = get_records_sql($sql)) {
diff --git a/file.php b/file.php
index e9e073c625090..ee170b83fb170 100644
--- a/file.php
+++ b/file.php
@@ -13,8 +13,7 @@
$lifetime = 86400; // Seconds for files to remain in caches
} else {
$lifetime = $CFG->filelifetime;
- }
-
+ }
$relativepath = get_file_argument('file.php');
$forcedownload = optional_param('forcedownload', 0, PARAM_BOOL);
diff --git a/lib/accesslib.php b/lib/accesslib.php
index 5371569c411e4..bdccb57cd2e82 100755
--- a/lib/accesslib.php
+++ b/lib/accesslib.php
@@ -1834,7 +1834,6 @@ function role_context_capabilities($roleid, $context, $cap='') {
return $capabilities;
}
-
/**
* Recursive function which, given a context, find all parent context ids,
* and return the array in reverse order, i.e. parent first, then grand
@@ -1930,7 +1929,18 @@ function get_parent_contexts($context) {
}
}
-
+/** gets a string for sql calls, searching for stuff
+ * in this context or above
+ * @param object $context
+ * @return string
+ */
+function get_related_contexts_string($context) {
+ if ($parents = get_parent_contexts($context)) {
+ return (' IN ('.$context->id.','.implode(',', $parents).')');
+ } else {
+ return (' ='.$context->id);
+ }
+}
/**
* This function gets the capability of a role in a given context.
* It is needed when printing override forms.
diff --git a/lib/datalib.php b/lib/datalib.php
index ce1932b0b2223..c1425b8a73912 100644
--- a/lib/datalib.php
+++ b/lib/datalib.php
@@ -111,7 +111,6 @@ function get_courses_notin_metacourse($metacourseid,$count=false) {
* @param string $sort ?
* @param string $exceptions ?
* @return object
- * @todo XXX Convert to Roles
*/
function search_users($courseid, $groupid, $searchtext, $sort='', $exceptions='') {
global $CFG;
@@ -149,24 +148,16 @@ function search_users($courseid, $groupid, $searchtext, $sort='', $exceptions=''
AND ($fullname $LIKE '%$searchtext%' OR u.email $LIKE '%$searchtext%')
$except $order");
} else {
- if (!$teachers = get_records_sql("SELECT u.id, u.firstname, u.lastname, u.email
- FROM {$CFG->prefix}user u,
- {$CFG->prefix}user_teachers s
- WHERE $select AND s.course = '$courseid' AND s.userid = u.id
- AND ($fullname $LIKE '%$searchtext%' OR u.email $LIKE '%$searchtext%')
- $except $order")) {
- $teachers = array();
- }
- if (!$students = get_records_sql("SELECT u.id, u.firstname, u.lastname, u.email
+ $context = get_context_instance(CONTEXT_COURSE, $courseid);
+ $contextlists = get_related_contexts_string($context);
+ $users = get_records_sql("SELECT u.id, u.firstname, u.lastname, u.email
FROM {$CFG->prefix}user u,
- {$CFG->prefix}user_students s
- WHERE $select AND s.course = '$courseid' AND s.userid = u.id
+ {$CFG->prefix}role_assignments ra
+ WHERE $select AND ra.contextid $contextlists AND ra.userid = u.id
AND ($fullname $LIKE '%$searchtext%' OR u.email $LIKE '%$searchtext%')
- $except $order")) {
- $students = array();
- }
- return $teachers + $students;
+ $except $order");
}
+ return $users;
}
}
diff --git a/lib/moodlelib.php b/lib/moodlelib.php
index 5d4c947bad1c6..137b8934dead1 100644
--- a/lib/moodlelib.php
+++ b/lib/moodlelib.php
@@ -2750,6 +2750,11 @@ function remove_course_contents($courseid, $showfeedback=true) {
include_once($CFG->libdir.'/questionlib.php');
question_delete_course($course, $showfeedback);
+ // deletes all role assignments, and local override, these have no courseid in table and needs separate process
+ $context = get_context_instance(CONTEXT_COUSE, $course->id);
+ delect_records('role_assignments', 'contextid', $context->id);
+ delect_records('role_role_capabilities', 'contextid', $context->id);
+
return $result;
}
@@ -2863,6 +2868,11 @@ function reset_course_userdata($data, $showfeedback=true) {
}
}
+ // deletes all role assignments, and local override, these have no courseid in table and needs separate process
+ $context = get_context_instance(CONTEXT_COUSE, $data->courseid);
+ delect_records('role_assignments', 'contextid', $context->id);
+ delect_records('role_role_capabilities', 'contextid', $context->id);
+
return $result;
}
diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php
index 64d863936839f..b27fcbae3d7cc 100644
--- a/mod/assignment/lib.php
+++ b/mod/assignment/lib.php
@@ -2129,7 +2129,17 @@ function assignment_log_info($log) {
function assignment_get_unmailed_submissions($starttime, $endtime) {
global $CFG;
+
return get_records_sql("SELECT s.*, a.course, a.name
+ FROM {$CFG->prefix}assignment_submissions s,
+ {$CFG->prefix}assignment a,
+ WHERE s.mailed = 0
+ AND s.timemarked <= $endtime
+ AND s.timemarked >= $starttime
+ AND s.assignment = a.id
+ AND s.userid = us.userid");
+
+ /* return get_records_sql("SELECT s.*, a.course, a.name
FROM {$CFG->prefix}assignment_submissions s,
{$CFG->prefix}assignment a,
{$CFG->prefix}user_students us
@@ -2139,6 +2149,7 @@ function assignment_get_unmailed_submissions($starttime, $endtime) {
AND s.assignment = a.id
AND s.userid = us.userid
AND a.course = us.course");
+ */
}
/**
@@ -2202,11 +2213,20 @@ function assignment_get_all_submissions($assignment, $sort="", $dir="DESC") {
$sort = "a.$sort $dir";
}
+ /* not sure this is needed at all since assignmenet already has a course define, so this join?
$select = "s.course = '$assignment->course' AND";
if ($assignment->course == SITEID) {
$select = '';
- }
+ }*/
+
return get_records_sql("SELECT a.*
+ FROM {$CFG->prefix}assignment_submissions a,
+ {$CFG->prefix}user u
+ WHERE u.id = a.userid
+ AND a.assignment = '$assignment->id'
+ ORDER BY $sort");
+
+ /* return get_records_sql("SELECT a.*
FROM {$CFG->prefix}assignment_submissions a,
{$CFG->prefix}user_students s,
{$CFG->prefix}user u
@@ -2214,6 +2234,7 @@ function assignment_get_all_submissions($assignment, $sort="", $dir="DESC") {
AND u.id = a.userid
AND $select a.assignment = '$assignment->id'
ORDER BY $sort");
+ */
}
@@ -2367,16 +2388,16 @@ function assignment_print_overview($courses, &$htmlarray) {
$context = get_context_instance(CONTEXT_MODULE,$this->cm->id);
if (has_capability('mod/assignment:grade', $context)) {
- $submissions = count_records_sql("SELECT COUNT(*)
- FROM {$CFG->prefix}assignment_submissions a,
- {$CFG->prefix}user_students s,
- {$CFG->prefix}user u
- WHERE a.userid = s.userid
- AND u.id = a.userid
- AND s.course = '{$assignment->course}'
- AND a.assignment = '{$assignment->id}'
- AND a.teacher = 0
- AND a.timemarked = 0");
+
+ // count how many people can submit
+ $submissions = 0; // init
+ $students = get_users_by_capability($context, 'mod/assignment:submit');
+ foreach ($student as $student) {
+ if (get_record('assignment_submissions', 'assignment', $assignment->id, 'userid', $student->id)) {
+ $submissions++;
+ }
+ }
+
if ($submissions) {
$str .= get_string('submissionsnotgraded', 'assignment', $submissions);
}
diff --git a/mod/hotpot/report.php b/mod/hotpot/report.php
index ee97ff1fdc095..22f1ff682b73e 100644
--- a/mod/hotpot/report.php
+++ b/mod/hotpot/report.php
@@ -118,7 +118,32 @@
// add students next
case 'students':
- $student_ids = get_records_select_menu('user_students', "course IN ($course_ids)", 'course', 'id, userid');
+
+ $contexts = array();
+ // first find all applicable contextids, put them in a bit array
+ foreach ($course_ids as $course_id) {
+
+ $context = get_context_instance(CONTEXT_COURSE, $course_id);
+
+ // first add self to list
+ if (!in_array($context->id, $contexts)) {
+ $contexts[] = $context->id;
+ }
+
+ // then add all parent contexts
+ if ($parents = get_parent_contexts($context)) {
+ foreach ($parents as $parent) {
+ if (!in_array($parent->id, $contexts)) {
+ $contexts[] = $parent->id;
+ }
+ }
+ }
+ }
+
+ $contextlists = implode(',', $contexts);
+
+ // this sort order might not make sense
+ $student_ids = get_records_select_menu('role_assignments', "contextid IN ($contextlists)", 'contextid', 'id, userid');
if (is_array($student_ids)) {
$users = array_merge($users, $student_ids);
}
@@ -439,17 +464,10 @@ function hotpot_print_report_selector(&$course, &$hotpot, &$formdata) {
'all' => get_string('allparticipants'),
'students' => get_string('students')
);
- $users = get_records_sql("
- SELECT
- u.*
- FROM
- {$CFG->prefix}user AS u,
- {$CFG->prefix}user_students AS us
- WHERE
- u.id = us.userid AND us.course=$course->id
- ORDER BY
- u.lastname
- ");
+
+ $context = get_context_instance(CONTEXT_COURSE, $course->id);
+ $users = get_users_by_capability($context, 'mod/hotpot:attempt', 'u.*', $sort='u.lastname');
+
if ($users) {
$menus['reportusers'][''] = '------'; // separator
foreach ($users as $id=>$user) {