. /** * Online users block. * * @package block_online_users * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ use block_online_users\fetcher; /** * This block needs to be reworked. * The new roles system does away with the concepts of rigid student and * teacher roles. */ class block_online_users extends block_base { function init() { $this->title = get_string('pluginname','block_online_users'); } function has_config() { return true; } function get_content() { global $USER, $CFG, $DB, $OUTPUT; if ($this->content !== NULL) { return $this->content; } $this->content = new stdClass; $this->content->text = ''; $this->content->footer = ''; if (empty($this->instance)) { return $this->content; } $timetoshowusers = 300; //Seconds default if (isset($CFG->block_online_users_timetosee)) { $timetoshowusers = $CFG->block_online_users_timetosee * 60; } $now = time(); //Calculate if we are in separate groups $isseparategroups = ($this->page->course->groupmode == SEPARATEGROUPS && $this->page->course->groupmodeforce && !has_capability('moodle/site:accessallgroups', $this->page->context)); //Get the user current group $currentgroup = $isseparategroups ? groups_get_course_group($this->page->course) : NULL; $sitelevel = $this->page->course->id == SITEID || $this->page->context->contextlevel < CONTEXT_COURSE; $onlineusers = new fetcher($currentgroup, $now, $timetoshowusers, $this->page->context, $sitelevel, $this->page->course->id); //Calculate minutes $minutes = floor($timetoshowusers/60); $periodminutes = get_string('periodnminutes', 'block_online_users', $minutes); // Count users. $usercount = $onlineusers->count_users(); if ($usercount === 0) { $usercount = get_string('nouser', 'block_online_users'); } else if ($usercount === 1) { $usercount = get_string('numuser', 'block_online_users', $usercount); } else { $usercount = get_string('numusers', 'block_online_users', $usercount); } $this->content->text = '
'.$usercount.' ('.$periodminutes.')
'; // Verify if we can see the list of users, if not just print number of users if (!has_capability('block/online_users:viewlist', $this->page->context)) { return $this->content; } $userlimit = 50; // We'll just take the most recent 50 maximum. if ($users = $onlineusers->get_users($userlimit)) { foreach ($users as $user) { $users[$user->id]->fullname = fullname($user); } } else { $users = array(); } //Now, we have in users, the list of users to show //Because they are online if (!empty($users)) { $this->page->requires->js_call_amd('block_online_users/change_user_visibility', 'init'); //Accessibility: Don't want 'Alt' text for the user picture; DO want it for the envelope/message link (existing lang string). //Accessibility: Converted
to