Skip to content

Commit

Permalink
Fix #765 - prevent fatal error when users don't have access to any gr…
Browse files Browse the repository at this point in the history
…oups.
  • Loading branch information
danmarsden committed Sep 16, 2024
1 parent 01bfb89 commit de17325
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions classes/form/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down Expand Up @@ -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])) {
Expand Down

0 comments on commit de17325

Please sign in to comment.