title = get_string('blockname','block_online_users'); $this->version = 2006030100; } function has_config() {return true;} function get_content() { global $USER, $CFG, $COURSE; 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; } $timefrom = time()-$timetoshowusers; // Get context so we can check capabilities. $context = get_context_instance(CONTEXT_COURSE, $COURSE->id); //Calculate if we are in separate groups $isseparategroups = ($COURSE->groupmode == SEPARATEGROUPS && $COURSE->groupmodeforce && !has_capability('moodle/site:accessallgroups', $context)); //Get the user current group $currentgroup = $isseparategroups ? get_current_group($COURSE->id) : NULL; $groupmembers = ""; $groupselect = ""; //Add this to the SQL to show only group users if ($currentgroup !== NULL) { $groupmembers = ", {$CFG->prefix}groups_members gm "; $groupselect .= " AND u.id = gm.userid AND gm.groupid = '$currentgroup'"; } if ($COURSE->id == SITEID) { // Site-level $courseselect = ''; $timeselect = "AND (ul.timeaccess > $timefrom OR u.lastaccess > $timefrom)"; } else { $courseselect = "AND ul.courseid = '".$COURSE->id."'"; $timeselect = "AND ul.timeaccess > $timefrom"; } $users = array(); $SQL = "SELECT u.id, u.username, u.firstname, u.lastname, u.picture, u.lastaccess, ul.timeaccess FROM {$CFG->prefix}user_lastaccess ul, {$CFG->prefix}user u $groupmembers WHERE ul.userid = u.id $courseselect $timeselect $groupselect ".sql_paging_limit(0,20); if ($pusers = get_records_sql($SQL)) { foreach ($pusers as $puser) { $puser->fullname = fullname($puser); $users[$puser->id] = $puser; } } //Calculate minutes $minutes = floor($timetoshowusers/60); $this->content->text = "
(".get_string("periodnminutes","block_online_users",$minutes).")
"; //Now, we have in users, the list of users to show //Because they are online if (!empty($users)) { //Accessibility: Don't want 'Alt' text for the user picture; DO want it for the envelope/message link (existing lang string). //Accessibility: Converted
to