$maintables = true;
$mtables = array("config", "course", "course_categories", "course_modules",
"course_sections", "log", "log_display", "modules",
- "user", "user_admins", "user_students", "user_teachers");
+ "user");
foreach ($mtables as $mtable) {
if (!in_array($CFG->prefix.$mtable, $tables)) {
$maintables = false;
$updateuser->idnumber = ""; // Clear this field to free it up
$updateuser->timemodified = time();
if (update_record("user", $updateuser)) {
- unenrol_student($user->id); // From all courses
- remove_teacher($user->id); // From all courses
- remove_admin($user->id);
+ // not sure if this is needed. unenrol_student($user->id); // From all courses
+ delete_records('role_assignments', 'userid', $user->id); // unassign all roles
+ // remove all context assigned on this user?
notify(get_string("deletedactivity", "", fullname($user, true)) );
} else {
notify(get_string("deletednot", "", fullname($user, true)));
$updateuser->deleted = "1";
$updateuser->timemodified = time();
if (update_record("user", $updateuser)) {
- unenrol_student($user->id); // From all courses
- remove_teacher($user->id); // From all courses
- remove_admin($user->id);
+ // unenrol_student($user->id); // From all courses
+ // remove_teacher($user->id); // From all courses
+ // remove_admin($user->id);
+ delete_records('role_assignments', 'userid', $user->id); // unassign all roles
notify(get_string("deletedactivity", "", fullname($user, true)) );
} else {
notify(get_string("deletednot", "", fullname($user, true)));
//$updateuser->email = ""; // Clear this field to free it up
$updateuser->timemodified = time();
if (update_record("user", $updateuser)) {
- unenrol_student($user->id); // From all courses
- remove_teacher($user->id); // From all courses
- remove_admin($user->id);
+ // unenrol_student($user->id); // From all courses
+ // remove_teacher($user->id); // From all courses
+ // remove_admin($user->id);
+ delete_records('role_assignments', 'userid', $user->id); // unassign all roles
notify(get_string("deletedactivity", "", fullname($user, true)) );
} else {
notify(get_string("deletednot", "", fullname($user, true)));
$tcourseids = '';
- if ($teachers = get_records_select('user_teachers', "userid = $USER->id AND editall = 1",'','id,course')) {
+ if ($teachers = get_user_capability_course('moodle/course:edit')) {
foreach ($teachers as $teacher) {
- if ($teacher->course != $course->id && $teacher->course != SITEID){
- $tcourseids .= $teacher->course.',';
+ if ($teacher->id != $course->id && $teacher->id != SITEID){
+ $tcourseids .= $teacher->id',';
}
}
}
<li>Improved handling of ratings for single forums when secureforms is on.</li>
<li>Multichoice question creation now defaults to a single correct answer format</li>
<li>Guests can no longer see email addresses if "show only to course participants" has been set by that user</li>
- <li>Primary admin is now the lowest-numbered entry in user_admins, rather than the admin with the lowest userid.</li>
+ <li>Primary admin is now the lowest-numbered entry in role_assignement with moodle/legacy:admin capability, rather than the admin with the lowest userid.</li>
<li>Modified flash MP3 plugin to improve brightness of Play button on darker screens</li>
<li>Various polishing and improvements in many language packs</li>
</ul>
return get_records_sql($SQL);
}
+/**
+ * This function gets the list of courses that this user has a particular capability in
+ * This is not the most efficient way of doing this
+ * @param string capability
+ * @param int $userid
+ * @return array
+ */
+function get_user_capability_course($capability, $userid='') {
+
+ global $USER;
+ if (!$userid) {
+ $userid = $USER->id;
+ }
+
+ $usercourses = array();
+ $courses = get_records_select('course', '', '', 'id, id');
+
+ foreach ($courses as $course) {
+ if (has_capability($capability, get_context_capability(CONTEXT_COURSE, $course->id))) {
+ $usercourses[] = $course;
+ }
+ }
+ return $usercourses;
+}
?>
return get_records_list('course', 'id', $courseids, $sort);
*/
-// The following is correct but VERY slow with large datasets
-//
-// return get_records_sql("SELECT c.*
-// FROM {$CFG->prefix}course c,
-// {$CFG->prefix}user_students s,
-// {$CFG->prefix}user_teachers t
-// WHERE (s.userid = '$userid' AND s.course = c.id)
-// OR (t.userid = '$userid' AND t.course = c.id)
-// GROUP BY c.id
-// ORDER BY $sort");
}
-
+
/**
* Ensure that a variable is set
*
}
}
-
/**
* Ensure that a variable is set
*
}
}
-
-
/**
* Determines if a user an admin
*
return false;
}
-
/**
* Determines if a user is allowed to edit a given course
*
return has_capability('moodle/legacy:guest', $context, $userid, false);
}
-
-
/**
* Enrols (or re-enrols) a student in a given course
*
return role_assign($role->id, $user->id, 0, $context->id, $timestart, $timeend, 0, $enrol);
}
-
/**
* Unenrols a student from a given course
*
*/
}
-
/**
* Counts the students in a given course (or site), or a subset of them
*
return 0;
}
-
/**
* Returns list of all teachers in this course
*
}
-
-
/**
* Returns an array of user objects
*
// This array stores the tables that need to be cleared, as
// table_name => column_name that contains the course id.
$tablestoclear = array(
- 'user_students' => 'course', // Delete any user stuff
- 'user_teachers' => 'course',
+ //'user_students' => 'course', // Delete any user stuff
+ //'user_teachers' => 'course',
'event' => 'courseid', // Delete events
'log' => 'course', // Delete logs
'course_sections' => 'course', // Delete any course stuff
} else {
$result = false;
}
+
/// Delete group members (but keep the groups)
if ($groups = get_records('groups', 'courseid', $data->courseid)) {
foreach ($groups as $group) {
message_print_search_results($frm);
} else {
- if ($teachers = get_records('user_teachers', 'userid', $USER->id, '', 'id, course')) {
-
+ // find all courses this use has readallmessages capabilities in
+ if ($teachers = get_user_capability_course('moodle/site:readallmessages')) {
$courses = get_courses('all', 'c.sortorder ASC', 'c.id, c.shortname');
$cs = '<select name="courseselect">';
foreach ($teachers as $tcourse) {
- $cs .= "<option value=\"$tcourse->course\">".$courses[$tcourse->course]->shortname."</option>\n";
+ $cs .= "<option value=\"$tcourse->course\">".$courses[$tcourse->id]->shortname."</option>\n";
}
$cs .= '</select>';
}
$except $order");
} else {
-
- if (!$teachers = get_records_sql("SELECT $fields
- 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%')
- $except $order")) {
- $teachers = array();
- }
- if (!$students = get_records_sql("SELECT $fields
- 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%')
- $except $order")) {
- $students = array();
- }
- return $teachers + $students;
+ $context = get_context_instance(CONTEXT_COURSE, $courseid);
+ $contextlists = get_related_contexts_string($context);
+
+ // everyone who has a role assignement in this course or higher
+ $users = get_records_sql("SELECT $fields
+ FROM {$CFG->prefix}user u,
+ {$CFG->prefix}role_assignments ra
+ WHERE $select
+ AND ra.contextid $contextlists
+ AND u.id = ra.userid
+ AND ($fullname $LIKE '%$searchtext%')
+ $except $order");
+
+ return $users;
}
}
$hotpot_ids = $hotpot->id;
break;
case 'all' :
- $records = get_records_select_menu('user_teachers', "userid='$USER->id'", 'course', 'id, course');
+ $records = get_user_capability_course('mod/hotpot:viewreport');
+ //$records = get_records_select_menu('user_teachers', "userid='$USER->id'", 'course', 'id, course');
$course_ids = join(',', array_values($records));
$records = get_records_select_menu('hotpot', "reference='$hotpot->reference'", 'reference', 'id, reference');
$users = array();
switch ($formdata['reportusers']) {
case 'all':
+ /*
$admin_ids = get_records_select_menu('user_admins');
if (is_array($admin_ids)) {
$users = array_merge($users, $admin_ids);
if (is_array($guest_id)) {
$users = array_merge($users, $guest_id);
}
+ */
// add students next
case 'students':
error("Could not find any question categories!"); // Something is really wrong
}
} else { // select only the categories to which the teacher has write access
- $sql = "SELECT c.*
- FROM {$CFG->prefix}question_categories AS c,
- {$CFG->prefix}user_teachers AS t
- WHERE t.userid = '$USER->id'
- AND t.course = c.course
- AND (c.course = '$course->id'
- OR (c.publish = '1' AND t.editall = '1'))
- ORDER BY c.parent ASC, c.sortorder ASC, c.name ASC";
- if (!$categories = get_records_sql($sql)) {
+ $cats = get_records('question_categories');
+ $categories = array();
+ foreach ($cats as $cat) {
+ if (has_capability('moodle/question:managecateory', get_context_instance(CONTEXT_COURSE, $cat->course))) {
+ $categories[] = $cat;
+ }
+ }
+ if (empty($categories)) {
error("Could not find any question categories!");
}
}