From 2267e61012c286ffafbf346bcae769a7a51abdc7 Mon Sep 17 00:00:00 2001 From: gbateson Date: Wed, 11 Oct 2006 01:30:27 +0000 Subject: [PATCH] allow selection of groups in reports --- mod/hotpot/report.php | 49 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/mod/hotpot/report.php b/mod/hotpot/report.php index 4aa3644cd2..c9deae5570 100644 --- a/mod/hotpot/report.php +++ b/mod/hotpot/report.php @@ -81,9 +81,22 @@ hotpot_delete_selected_attempts($hotpot, $del); } + // check for groups + if (preg_match('/^group(\d*)$/', $formdata['reportusers'], $matches)) { + // validate groupid + if (is_numeric($matches[1]) && get_field('groups', 'courseid', 'id', $matches[1])===$course->id) { + $formdata['reportusers'] = 'group'; + $formdata['reportgroupid'] = $matches[1]; + } else { + $formdata['reportgroupid'] = 0; // groupid is invalid + } + } + $user_ids = ''; $users = array(); + switch ($formdata['reportusers']) { + case 'allusers': // anyone who has ever attempted this hotpot if ($records = get_records_select('hotpot_attempts', "hotpot=$hotpot->id", '', 'id,userid')) { @@ -94,6 +107,15 @@ } break; + case 'group': + // group members + if ($records = get_records_select('groups_members', "groupid=".$formdata['reportgroupid'], '', 'id,userid')) { + foreach ($records as $record) { + $users[$record->userid] = 1; // "1" signifies currently recognized participant + } + } + break; + case 'allparticipants': // anyone currently allowed to attempt this HotPot if ($records = get_users_by_capability($modulecontext, 'mod/hotpot:attempt', 'u.id,u.id', 'u.id')) { @@ -423,7 +445,17 @@ function hotpot_print_report_selector(&$course, &$hotpot, &$formdata) { } } - $menus['reportusers'] = array('allusers' => get_string('allusers', 'hotpot')); + $menus['reportusers'] = array( + 'allusers' => get_string('allusers', 'hotpot'), + 'allparticipants' => get_string('allparticipants') + ); + + // groups + if ($groups = get_records_select('groups', "courseid='$course->id'", '', 'id,name')) { + foreach ($groups as $group) { + $menus['reportusers']["group$group->id"] = get_string('group').': '.$group->name; + } + } // get users who have ever atetmpted this HotPot $users = get_records_sql(" @@ -446,29 +478,30 @@ function hotpot_print_report_selector(&$course, &$hotpot, &$formdata) { $teachers = get_users_by_capability($modulecontext, 'mod/hotpot:viewreport', 'u.id,u.firstname,u.lastname', 'u.lastname'); $students = get_users_by_capability($modulecontext, 'mod/hotpot:attempt', 'u.id,u.firstname,u.lastname', 'u.lastname'); + // current students if (!empty($students)) { $firsttime = true; - foreach ($students as $id=>$user) { - if (isset($users[$id]) && empty($teachers[$id])) { + foreach ($students as $user) { + if (isset($users[$user->id])) { if ($firsttime) { $firsttime = false; // so we only do this once - $menus['reportusers']['allparticipants'] = get_string('allparticipants'); $menus['reportusers']['existingstudents'] = get_string('existingstudents'); $menus['reportusers'][] = '------'; } - $menus['reportusers']["$id"] = fullname($user); - unset($users[$id]); + $menus['reportusers']["$user->id"] = fullname($user); + unset($users[$user->id]); } } } + // others (former students, teachers, admins, course creators) if (!empty($users)) { $firsttime = true; - foreach ($users as $id=>$user) { + foreach ($users as $user) { if ($firsttime) { $firsttime = false; // so we only do this once $menus['reportusers'][] = '======'; } - $menus['reportusers']["$id"] = fullname($user); + $menus['reportusers']["$user->id"] = fullname($user); } } -- 2.39.5