MDL-80565 report: Revert MDL-41465 changes

* Partial revert of changes made in MDL-41465,
while keeping the API changes made in enrol/lib.
This commit is contained in:
Laurent David
2024-03-11 14:30:54 +01:00
parent fde6c3c7ef
commit 0f235f56c1
4 changed files with 13 additions and 230 deletions
+12 -45
View File
@@ -93,9 +93,6 @@ class report_log_renderable implements renderable {
/** @var table_log table log which will be used for rendering logs */
public $tablelog;
/** @var array group ids */
public $grouplist;
/**
* Constructor.
*
@@ -346,40 +343,30 @@ class report_log_renderable implements renderable {
}
/**
* Return list of groups that are used in this course. This is done when groups are used in the course
* and the user is allowed to see all groups or groups are visible anyway. If groups are used but the
* mode is separate groups and the user is not allowed to see all groups, the list contains the groups
* only, where the user is member.
* If the course uses no groups, the list is empty.
* Return list of groups.
*
* @return array list of groups.
*/
public function get_group_list() {
global $USER;
if ($this->grouplist !== null) {
return $this->grouplist;
}
// No groups for system.
if (empty($this->course)) {
$this->grouplist = [];
return $this->grouplist;
return array();
}
$context = context_course::instance($this->course->id);
$this->grouplist = [];
$groups = array();
$groupmode = groups_get_course_groupmode($this->course);
$cgroups = [];
if (($groupmode == VISIBLEGROUPS) ||
($groupmode == SEPARATEGROUPS && has_capability('moodle/site:accessallgroups', $context))) {
$cgroups = groups_get_all_groups($this->course->id);
} else if ($groupmode == SEPARATEGROUPS && !has_capability('moodle/site:accessallgroups', $context)) {
$cgroups = groups_get_all_groups($this->course->id, $USER->id);
($groupmode == SEPARATEGROUPS and has_capability('moodle/site:accessallgroups', $context))) {
// Get all groups.
if ($cgroups = groups_get_all_groups($this->course->id)) {
foreach ($cgroups as $cgroup) {
$groups[$cgroup->id] = $cgroup->name;
}
}
}
foreach ($cgroups as $cgroup) {
$this->grouplist[$cgroup->id] = $cgroup->name;
}
return $this->grouplist;
return $groups;
}
/**
@@ -398,29 +385,9 @@ class report_log_renderable implements renderable {
$limitfrom = empty($this->showusers) ? 0 : '';
$limitnum = empty($this->showusers) ? COURSE_MAX_USERS_PER_DROPDOWN + 1 : '';
$userfieldsapi = \core_user\fields::for_name();
// Get the groups of that course.
$groups = $this->get_group_list();
// Check here if we are not in group mode, or in group mode but narrow the group selection
// to the group of the user.
if (empty($groups) || !empty($this->groupid) && isset($groups[(int)$this->groupid])) {
// No groups are used in that course, therefore get all users (maybe limited to one group).
$courseusers = get_enrolled_users($context, '', $this->groupid, 'u.id, ' .
$courseusers = get_enrolled_users($context, '', $this->groupid, 'u.id, ' .
$userfieldsapi->get_sql('u', false, '', '', false)->selects,
null, $limitfrom, $limitnum);
} else {
// The course uses groups, get the users from these groups.
$groupids = array_keys($groups);
try {
$enrolments = enrol_get_course_users($courseid, false, [], [], $groupids);
$courseusers = [];
foreach ($enrolments as $enrolment) {
$courseusers[$enrolment->id] = $enrolment;
}
} catch (Exception $e) {
$courseusers = [];
}
}
if (count($courseusers) < COURSE_MAX_USERS_PER_DROPDOWN && !$this->showusers) {
$this->showusers = 1;