. /** * Lists all the users within a given course. * * @copyright 1999 Martin Dougiamas http://dougiamas.com * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @package core_user */ require_once('../config.php'); require_once($CFG->dirroot.'/user/lib.php'); require_once($CFG->dirroot.'/course/lib.php'); require_once($CFG->dirroot.'/notes/lib.php'); require_once($CFG->libdir.'/tablelib.php'); require_once($CFG->libdir.'/filelib.php'); require_once($CFG->dirroot.'/enrol/locallib.php'); use core_table\local\filter\filter; use core_table\local\filter\integer_filter; use core_table\local\filter\string_filter; define('DEFAULT_PAGE_SIZE', 20); $page = optional_param('page', 0, PARAM_INT); // Which page to show. $perpage = optional_param('perpage', DEFAULT_PAGE_SIZE, PARAM_INT); // How many per page. $contextid = optional_param('contextid', 0, PARAM_INT); // One of this or. $courseid = optional_param('id', 0, PARAM_INT); // This are required. $newcourse = optional_param('newcourse', false, PARAM_BOOL); $roleid = optional_param('roleid', 0, PARAM_INT); $urlgroupid = optional_param('group', 0, PARAM_INT); $PAGE->set_url('/user/index.php', array( 'page' => $page, 'perpage' => $perpage, 'contextid' => $contextid, 'id' => $courseid, 'newcourse' => $newcourse)); if ($contextid) { $context = context::instance_by_id($contextid, MUST_EXIST); if ($context->contextlevel != CONTEXT_COURSE) { print_error('invalidcontext'); } $course = $DB->get_record('course', array('id' => $context->instanceid), '*', MUST_EXIST); } else { $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); $context = context_course::instance($course->id, MUST_EXIST); } // Not needed anymore. unset($contextid); unset($courseid); require_login($course); $systemcontext = context_system::instance(); $isfrontpage = ($course->id == SITEID); $frontpagectx = context_course::instance(SITEID); if ($isfrontpage) { $PAGE->set_pagelayout('admin'); course_require_view_participants($systemcontext); } else { $PAGE->set_pagelayout('incourse'); course_require_view_participants($context); } // Trigger events. user_list_view($course, $context); $bulkoperations = has_capability('moodle/course:bulkmessaging', $context); $PAGE->set_title("$course->shortname: ".get_string('participants')); $PAGE->set_heading($course->fullname); $PAGE->set_pagetype('course-view-participants'); $PAGE->set_docs_path('enrol/users'); $PAGE->add_body_class('path-user'); // So we can style it independently. $PAGE->set_other_editing_capability('moodle/course:manageactivities'); // Expand the users node in the settings navigation when it exists because those pages // are related to this one. $node = $PAGE->settingsnav->find('users', navigation_node::TYPE_CONTAINER); if ($node) { $node->force_open(); } echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('participants')); $filterset = new \core_user\table\participants_filterset(); $filterset->add_filter(new integer_filter('courseid', filter::JOINTYPE_DEFAULT, [(int)$course->id])); $participanttable = new \core_user\table\participants("user-index-participants-{$course->id}"); $canaccessallgroups = has_capability('moodle/site:accessallgroups', $context); $filtergroupids = $urlgroupid ? [$urlgroupid] : []; // Force group filtering if user should only see a subset of groups' users. if ($course->groupmode != NOGROUPS && !$canaccessallgroups) { if ($filtergroupids) { $filtergroupids = array_intersect( $filtergroupids, array_keys(groups_get_all_groups($course->id, $USER->id)) ); } else { $filtergroupids = array_keys(groups_get_all_groups($course->id, $USER->id)); } if (empty($filtergroupids)) { if ($course->groupmode == SEPARATEGROUPS) { // The user is not in a group so show message and exit. echo $OUTPUT->notification(get_string('notingroup')); echo $OUTPUT->footer(); exit(); } else { $filtergroupids = [(int) groups_get_course_group($course, true)]; } } } // Apply groups filter if included in URL or forced due to lack of capabilities. if (!empty($filtergroupids)) { $filterset->add_filter(new integer_filter('groups', filter::JOINTYPE_DEFAULT, $filtergroupids)); } // Display single group information if requested in the URL. if ($urlgroupid > 0 && ($course->groupmode != SEPARATEGROUPS || $canaccessallgroups)) { $grouprenderer = $PAGE->get_renderer('core_group'); $groupdetailpage = new \core_group\output\group_details($urlgroupid); echo $grouprenderer->group_details($groupdetailpage); } // Filter by role if passed via URL (used on profile page). if ($roleid) { $viewableroles = get_profile_roles($context); // Apply filter if the user can view this role. if (array_key_exists($roleid, $viewableroles)) { $filterset->add_filter(new integer_filter('roles', filter::JOINTYPE_DEFAULT, [$roleid])); } } // Manage enrolments. $manager = new course_enrolment_manager($PAGE, $course); $enrolbuttons = $manager->get_manual_enrol_buttons(); $enrolrenderer = $PAGE->get_renderer('core_enrol'); $enrolbuttonsout = ''; foreach ($enrolbuttons as $enrolbutton) { $enrolbuttonsout .= $enrolrenderer->render($enrolbutton); } echo html_writer::div($enrolbuttonsout, 'd-flex justify-content-end', [ 'data-region' => 'wrapper', 'data-table-uniqueid' => $participanttable->uniqueid, ]); // Render the user filters. $userrenderer = $PAGE->get_renderer('core_user'); echo $userrenderer->participants_filter($context, $participanttable->uniqueid); echo '