From c9de75091a8c272a719fbbd5462e4bfcc7921b2a Mon Sep 17 00:00:00 2001 From: Gregory Faller Date: Thu, 7 Nov 2013 10:47:00 +1030 Subject: [PATCH] Fix missing language strings and enable groupings Fix missing language strings and enable groupings and enablegroupmembersonly. Most places already support groupings. --- add_form.php | 4 ++-- lang/en/attendance.php | 3 +++ lib.php | 8 ++------ locallib.php | 34 +++++++++++++++++++++++++++++----- renderer.php | 17 ++++++++++++++++- 5 files changed, 52 insertions(+), 14 deletions(-) diff --git a/add_form.php b/add_form.php index 4026324..9fc813a 100644 --- a/add_form.php +++ b/add_form.php @@ -78,9 +78,9 @@ class mod_attendance_add_form extends moodleform { } if ($groupmode == SEPARATEGROUPS or $groupmode == VISIBLEGROUPS) { if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $modcontext)) { - $groups = groups_get_all_groups ($course->id, $USER->id); + $groups = groups_get_all_groups ($course->id, $USER->id, $cm->groupingid); } else { - $groups = groups_get_all_groups($course->id); + $groups = groups_get_all_groups($course->id, 0, $cm->groupingid); } if ($groups) { $selectgroups = array(); diff --git a/lang/en/attendance.php b/lang/en/attendance.php index 3ade055..e8697a9 100755 --- a/lang/en/attendance.php +++ b/lang/en/attendance.php @@ -96,6 +96,7 @@ $string['displaymode'] = 'Display mode'; $string['downloadexcel'] = 'Download in Excel format'; $string['downloadooo'] = 'Download in OpenOffice format'; $string['downloadtext'] = 'Download in text format'; +$string['donotusepaging'] = 'Do not use paging'; $string['duration'] = 'Duration'; $string['editsession'] = 'Edit Session'; $string['endtime'] = 'Session end time'; @@ -158,6 +159,8 @@ $string['required'] = 'Required*'; $string['resetdescription'] = 'Remember that deleting attendance data will erase information from database. You can just hide older sessions having changed start date of course!'; $string['resetstatuses'] = 'Reset statuses to default'; $string['restoredefaults'] = 'Restore defaults'; +$string['resultsperpage'] = 'Results per page'; +$string['resultsperpage_desc'] = 'Number of students displayed on a page'; $string['save'] = 'Save attendance'; $string['session'] = 'Session'; $string['session_help'] = 'Session'; diff --git a/lib.php b/lib.php index 32d65e5..a13f2fe 100644 --- a/lib.php +++ b/lib.php @@ -35,14 +35,10 @@ function attendance_supports($feature) { return true; case FEATURE_GROUPS: return true; - // Artem Andreev: AFAIK it's not tested - // we need implement filtration of groups list by grouping. case FEATURE_GROUPINGS: - return false; - // Artem Andreev: AFAIK it's not tested - // harder "All courses" report. + return true; case FEATURE_GROUPMEMBERSONLY: - return false; + return true; case FEATURE_MOD_INTRO: return false; case FEATURE_BACKUP_MOODLE2: diff --git a/locallib.php b/locallib.php index e836788..4828047 100644 --- a/locallib.php +++ b/locallib.php @@ -913,7 +913,7 @@ class attendance { * MDL-27591 made this method obsolete. */ public function get_users($groupid = 0, $page = 1) { - global $DB; + global $DB, $CFG; // Fields we need from the user table. $userfields = user_picture::fields('u').',u.username'; @@ -925,12 +925,36 @@ class attendance { } if ($page) { - $totalusers = count_enrolled_users($this->context, 'mod/attendance:canbelisted', $groupid); $usersperpage = $this->pageparams->perpage; - $startusers = ($page - 1) * $usersperpage; - $users = get_enrolled_users($this->context, 'mod/attendance:canbelisted', $groupid, $userfields, $orderby, $startusers, $usersperpage); + if (!empty($CFG->enablegroupmembersonly) and $this->cm->groupmembersonly) { + $startusers = ($page - 1) * $usersperpage; + if ($groupid == 0) { + $groups = array_keys(groups_get_all_groups($this->cm->course, 0, $this->cm->groupingid, 'g.id')); + } else { + $groups = $groupid; + } + $users = get_users_by_capability($this->context, 'mod/attendance:canbelisted', + $userfields.',u.id, u.firstname, u.lastname, u.email', + $orderby, $startusers, $usersperpage, $groups, + '', false, true); + } else { + $startusers = ($page - 1) * $usersperpage; + $users = get_enrolled_users($this->context, 'mod/attendance:canbelisted', $groupid, $userfields, $orderby, $startusers, $usersperpage); + } } else { - $users = get_enrolled_users($this->context, 'mod/attendance:canbelisted', $groupid, $userfields, $orderby); + if (!empty($CFG->enablegroupmembersonly) and $this->cm->groupmembersonly) { + if ($groupid == 0) { + $groups = array_keys(groups_get_all_groups($this->cm->course, 0, $this->cm->groupingid, 'g.id')); + } else { + $groups = $groupid; + } + $users = get_users_by_capability($this->context, 'mod/attendance:canbelisted', + $userfields.',u.id, u.firstname, u.lastname, u.email', + $orderby, '', '', $groups, + '', false, true); + } else { + $users = get_enrolled_users($this->context, 'mod/attendance:canbelisted', $groupid, $userfields, $orderby); + } } // Add a flag to each user indicating whether their enrolment is active. diff --git a/renderer.php b/renderer.php index 5192f2a..c335682 100644 --- a/renderer.php +++ b/renderer.php @@ -348,6 +348,8 @@ class mod_attendance_renderer extends plugin_renderer_base { } private function construct_take_controls(attendance_take_data $takedata) { + GLOBAL $CFG; + $controls = ''; $group = 0; @@ -359,7 +361,20 @@ class mod_attendance_renderer extends plugin_renderer_base { } } - $totalusers = count_enrolled_users(get_context_instance(CONTEXT_MODULE, $takedata->cm->id), 'mod/attendance:canbelisted', $group); + if (!empty($CFG->enablegroupmembersonly) and $takedata->cm->groupmembersonly) { + if ($group == 0) { + $groups = array_keys(groups_get_all_groups($takedata->cm->course, 0, $takedata->cm->groupingid, 'g.id')); + } else { + $groups = $group; + } + $users = get_users_by_capability(get_context_instance(CONTEXT_MODULE, $takedata->cm->id), 'mod/attendance:canbelisted', + 'u.id, u.firstname, u.lastname, u.email', + '', '', '', $groups, + '', false, true); + $totalusers = count($users); + } else { + $totalusers = count_enrolled_users(get_context_instance(CONTEXT_MODULE, $takedata->cm->id), 'mod/attendance:canbelisted', $group); + } $usersperpage = $takedata->pageparams->perpage; if (!empty($takedata->pageparams->page) && $takedata->pageparams->page && $totalusers && $usersperpage) { $controls .= html_writer::empty_tag('br');