mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 20:42:22 +02:00
changing sql calls from user_students table to role_assignments table
This commit is contained in:
parent
b1342e1869
commit
ea8158c118
@ -122,14 +122,25 @@
|
||||
echo "<input type=\"hidden\" name=\"users\" value=\"$count\">\n";
|
||||
echo '<br />';
|
||||
|
||||
$count = count_records('user_students');
|
||||
echo get_string("enrolments").": ".$count;
|
||||
echo "<input type=\"hidden\" name=\"enrolments\" value=\"$count\">\n";
|
||||
// total number of role assignments
|
||||
$count = count_records('role_assignments');
|
||||
echo get_string("roleassignments").": ".$count;
|
||||
echo "<input type=\"hidden\" name=\"roleassignments\" value=\"$count\">\n";
|
||||
echo '<br />';
|
||||
|
||||
$count = count_records('user_teachers');
|
||||
echo get_string("teachers").": ".$count;
|
||||
echo "<input type=\"hidden\" name=\"teachers\" value=\"$count\">\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 "<input type=\"hidden\" name=\"courseupdates\" value=\"$count\">\n";
|
||||
echo '<br />';
|
||||
|
||||
$count = count_records('forum_posts');
|
||||
|
@ -459,16 +459,11 @@
|
||||
|
||||
// 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 {
|
||||
|
@ -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)) {
|
||||
|
3
file.php
3
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);
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
$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_teachers 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")) {
|
||||
$teachers = array();
|
||||
}
|
||||
if (!$students = 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
|
||||
AND ($fullname $LIKE '%$searchtext%' OR u.email $LIKE '%$searchtext%')
|
||||
$except $order")) {
|
||||
$students = array();
|
||||
}
|
||||
return $teachers + $students;
|
||||
$except $order");
|
||||
}
|
||||
return $users;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user