mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 20:42:22 +02:00
MDL-44725 Availability: Replace groupmembersonly - quiz overrides (9)
This only affects the quiz overrides form, as groupmembersonly was not used elsewhere. The change simply restricts the list of users shown when selecting somebody for overrides. Some additional code is needed to (efficiently) load the $cm object as a cm_info so that the availability API can be used on it.
This commit is contained in:
parent
914027baf8
commit
c234c34085
@ -136,20 +136,14 @@ class quiz_override_form extends moodleform {
|
||||
'This is unexpected, and a problem because there is no way to pass these ' .
|
||||
'parameters to get_users_by_capability. See MDL-34657.');
|
||||
}
|
||||
if (!empty($CFG->enablegroupmembersonly) && $cm->groupmembersonly) {
|
||||
// Only users from the grouping.
|
||||
$groups = groups_get_all_groups($cm->course, 0, $cm->groupingid);
|
||||
if (!empty($groups)) {
|
||||
$users = get_users_by_capability($this->context, 'mod/quiz:attempt',
|
||||
'u.id, u.email, ' . get_all_user_name_fields(true, 'u'),
|
||||
$sort, '', '', array_keys($groups),
|
||||
'', false, true);
|
||||
}
|
||||
} else {
|
||||
$users = get_users_by_capability($this->context, 'mod/quiz:attempt',
|
||||
'u.id, u.email, ' . get_all_user_name_fields(true, 'u'),
|
||||
$sort, '', '', '', '', false, true);
|
||||
}
|
||||
$users = get_users_by_capability($this->context, 'mod/quiz:attempt',
|
||||
'u.id, u.email, ' . get_all_user_name_fields(true, 'u'),
|
||||
$sort, '', '', '', '', false, true);
|
||||
|
||||
// Filter users based on any fixed restrictions (groups, profile).
|
||||
$info = new \core_availability\info_module($cm);
|
||||
$users = $info->filter_user_list($users);
|
||||
|
||||
if (empty($users)) {
|
||||
// Generate an error.
|
||||
$link = new moodle_url('/mod/quiz/overrides.php', array('cmid'=>$cm->id));
|
||||
|
@ -43,17 +43,12 @@ if ($overrideid) {
|
||||
if (! $quiz = $DB->get_record('quiz', array('id' => $override->quiz))) {
|
||||
print_error('invalidcoursemodule');
|
||||
}
|
||||
if (! $cm = get_coursemodule_from_instance("quiz", $quiz->id, $quiz->course)) {
|
||||
print_error('invalidcoursemodule');
|
||||
}
|
||||
} else if ($cmid) {
|
||||
list($course, $cm) = get_course_and_cm_from_instance($quiz, 'quiz');
|
||||
|
||||
} else if ($cmid) {
|
||||
list($course, $cm) = get_course_and_cm_from_cmid($cmid, 'quiz');
|
||||
$quiz = $DB->get_record('quiz', array('id' => $cm->instance), '*', MUST_EXIST);
|
||||
|
||||
if (! $cm = get_coursemodule_from_id('quiz', $cmid)) {
|
||||
print_error('invalidcoursemodule');
|
||||
}
|
||||
if (! $quiz = $DB->get_record('quiz', array('id' => $cm->instance))) {
|
||||
print_error('invalidcoursemodule');
|
||||
}
|
||||
} else {
|
||||
print_error('invalidcoursemodule');
|
||||
}
|
||||
|
@ -32,13 +32,8 @@ require_once($CFG->dirroot.'/mod/quiz/override_form.php');
|
||||
$cmid = required_param('cmid', PARAM_INT);
|
||||
$mode = optional_param('mode', '', PARAM_ALPHA); // One of 'user' or 'group', default is 'group'.
|
||||
|
||||
if (! $cm = get_coursemodule_from_id('quiz', $cmid)) {
|
||||
print_error('invalidcoursemodule');
|
||||
}
|
||||
if (! $quiz = $DB->get_record('quiz', array('id' => $cm->instance))) {
|
||||
print_error('invalidcoursemodule');
|
||||
}
|
||||
$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
|
||||
list($course, $cm) = get_course_and_cm_from_cmid($cmid, 'quiz');
|
||||
$quiz = $DB->get_record('quiz', array('id' => $cm->instance), '*', MUST_EXIST);
|
||||
|
||||
// Get the course groups.
|
||||
$groups = groups_get_all_groups($cm->course);
|
||||
@ -138,9 +133,8 @@ foreach ($overrides as $override) {
|
||||
if (!has_capability('mod/quiz:attempt', $context, $override->userid)) {
|
||||
// User not allowed to take the quiz.
|
||||
$active = false;
|
||||
} else if (!empty($CFG->enablegroupmembersonly) && $cm->groupmembersonly &&
|
||||
!groups_has_membership($cm, $override->userid)) {
|
||||
// User does not belong to the current grouping.
|
||||
} else if (!\core_availability\info_module::is_user_visible($cm, $override->userid)) {
|
||||
// User cannot access the module.
|
||||
$active = false;
|
||||
}
|
||||
}
|
||||
@ -267,17 +261,9 @@ if ($groupmode) {
|
||||
} else {
|
||||
$users = array();
|
||||
// See if there are any students in the quiz.
|
||||
if (!empty($CFG->enablegroupmembersonly) && $cm->groupmembersonly) {
|
||||
// Restrict to grouping.
|
||||
$limitgroups = groups_get_all_groups($cm->course, 0, $cm->groupingid);
|
||||
if (!empty($limitgroups)) {
|
||||
$users = get_users_by_capability($context, 'mod/quiz:attempt', 'u.id',
|
||||
'', '', 1, array_keys($limitgroups)); // Limit to one user for speed.
|
||||
}
|
||||
} else {
|
||||
// Limit to one user for speed.
|
||||
$users = get_users_by_capability($context, 'mod/quiz:attempt', 'u.id');
|
||||
}
|
||||
$users = get_users_by_capability($context, 'mod/quiz:attempt', 'u.id');
|
||||
$info = new \core_availability\info_module($cm);
|
||||
$users = $info->filter_user_list($users);
|
||||
|
||||
if (empty($users)) {
|
||||
// There are no students.
|
||||
|
Loading…
x
Reference in New Issue
Block a user