From de17325a999f283c9a977da5b424a64caf8a1906 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Mon, 16 Sep 2024 16:39:21 +1200 Subject: [PATCH] Fix #765 - prevent fatal error when users don't have access to any groups. --- classes/form/export.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/classes/form/export.php b/classes/form/export.php index 6dda9ae231..f9eb7cfb3a 100644 --- a/classes/form/export.php +++ b/classes/form/export.php @@ -43,6 +43,7 @@ public function definition() { $course = $this->_customdata['course']; $cm = $this->_customdata['cm']; $modcontext = $this->_customdata['modcontext']; + $grouplist = []; $mform->addElement('header', 'general', get_string('export', 'attendance')); @@ -76,11 +77,14 @@ public function definition() { return; } - list($gsql, $gparams) = $DB->get_in_or_equal(array_keys($grouplist), SQL_PARAMS_NAMED); - list($usql, $uparams) = $DB->get_in_or_equal(array_keys($userlist), SQL_PARAMS_NAMED); - $params = array_merge($gparams, $uparams); - $groupmembers = $DB->get_recordset_select('groups_members', "groupid {$gsql} AND userid {$usql}", $params, - '', 'groupid, userid'); + $groupmembers = []; + if (!empty($grouplist)) { + list($gsql, $gparams) = $DB->get_in_or_equal(array_keys($grouplist), SQL_PARAMS_NAMED); + list($usql, $uparams) = $DB->get_in_or_equal(array_keys($userlist), SQL_PARAMS_NAMED); + $params = array_merge($gparams, $uparams); + $groupmembers = $DB->get_recordset_select('groups_members', "groupid {$gsql} AND userid {$usql}", $params, + '', 'groupid, userid'); + } $groupmappings = []; foreach ($groupmembers as $groupmember) { if (!isset($groupmappings[$groupmember->groupid])) {