namespace core_user;
+use context;
+use DateTime;
+use html_writer;
+
defined('MOODLE_INTERNAL') || die;
global $CFG;
protected $extrafields;
/**
- * @var \stdClass The course details.
+ * @var \stdClass $course The course details.
*/
protected $course;
/**
- * @var \context The course context.
+ * @var context $context The course context.
*/
protected $context;
// Get the context.
$this->course = get_course($courseid);
$context = \context_course::instance($courseid, MUST_EXIST);
+ $this->context = $context;
// Define the headers and columns.
$headers = [];
$columns[] = 'lastaccess';
}
+ $canreviewenrol = has_capability('moodle/course:enrolreview', $context);
+ if ($canreviewenrol) {
+ $columns[] = 'status';
+ $headers[] = get_string('participationstatus', 'enrol');
+ $this->no_sorting('status');
+ };
+
$this->define_columns($columns);
$this->define_headers($headers);
return get_string('never');
}
+ /**
+ * Generate the status column.
+ *
+ * @param stdClass $data The data object.
+ * @return string
+ */
+ public function col_status($data) {
+ global $CFG, $OUTPUT, $PAGE;
+
+ $enrolstatusoutput = '';
+ $canreviewenrol = has_capability('moodle/course:enrolreview', $this->context);
+ if ($canreviewenrol) {
+ $fullname = fullname($data);
+ require_once($CFG->dirroot . '/enrol/locallib.php');
+ $manager = new \course_enrolment_manager($PAGE, $this->course);
+ $userenrolments = $manager->get_user_enrolments($data->id);
+ foreach ($userenrolments as $ue) {
+ $enrolactions = $ue->enrolmentplugin->get_user_enrolment_actions($manager, $ue);
+ $timestart = $ue->timestart;
+ $timeend = $ue->timeend;
+ $status = '';
+ $dimmed = '';
+ switch ($ue->status) {
+ case ENROL_USER_ACTIVE:
+ $currentdate = new DateTime();
+ $now = $currentdate->getTimestamp();
+ if ($timestart <= $now && ($timeend == 0 || $timeend >= $now)) {
+ $status = get_string('participationactive', 'enrol');
+ } else {
+ $status = get_string('participationnotcurrent', 'enrol');
+ $dimmed = 'dimmed_text';
+ }
+ break;
+ case ENROL_USER_SUSPENDED:
+ $status = get_string('participationsuspended', 'enrol');
+ $dimmed = 'dimmed_text';
+ break;
+ }
+ $statusout = html_writer::span($status, $dimmed, ['title' => "{$ue->enrolmentinstancename}: {$status}"]);
+ $enrolactionsout = '';
+ foreach ($enrolactions as $action) {
+ $icon = $OUTPUT->render($action->get_icon());
+ $attributes = $action->get_attributes();
+ $attributes['data-fullname'] = $fullname;
+ $attributes['data-coursename'] = $this->course->fullname;
+ $enrolactionsout .= html_writer::link($action->get_url(), $icon, $attributes);
+ }
+ $enrolstatusoutput .= html_writer::div($statusout . $enrolactionsout);
+ }
+ }
+ return $enrolstatusoutput;
+ }
+
/**
* This function is used for the extra user fields.
*
$isfrontpage = ($courseid == SITEID);
- list($esql, $params) = get_enrolled_sql($context, null, $groupid, true);
+ // Show active users only if the user doesn't have the 'moodle/course:enrolreview' capability.
+ $onlyactive = !has_capability('moodle/course:enrolreview', $context);
+ list($esql, $params) = get_enrolled_sql($context, null, $groupid, $onlyactive);
$joins = array('FROM {user} u');
$wheres = array();