[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Online users block. 19 * 20 * @package block_online_users 21 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 use block_online_users\fetcher; 26 27 /** 28 * This block needs to be reworked. 29 * The new roles system does away with the concepts of rigid student and 30 * teacher roles. 31 */ 32 class block_online_users extends block_base { 33 function init() { 34 $this->title = get_string('pluginname','block_online_users'); 35 } 36 37 function has_config() { 38 return true; 39 } 40 41 function get_content() { 42 global $USER, $CFG, $DB, $OUTPUT, $PAGE; 43 44 if ($this->content !== NULL) { 45 return $this->content; 46 } 47 48 $this->content = new stdClass; 49 $this->content->text = ''; 50 $this->content->footer = ''; 51 52 if (empty($this->instance)) { 53 return $this->content; 54 } 55 56 $timetoshowusers = 300; //Seconds default 57 if (isset($CFG->block_online_users_timetosee)) { 58 $timetoshowusers = $CFG->block_online_users_timetosee * 60; 59 } 60 $now = time(); 61 62 //Calculate if we are in separate groups 63 $isseparategroups = ($this->page->course->groupmode == SEPARATEGROUPS 64 && $this->page->course->groupmodeforce 65 && !has_capability('moodle/site:accessallgroups', $this->page->context)); 66 67 //Get the user current group 68 $currentgroup = $isseparategroups ? groups_get_course_group($this->page->course) : NULL; 69 70 $sitelevel = $this->page->course->id == SITEID || $this->page->context->contextlevel < CONTEXT_COURSE; 71 72 $onlineusers = new fetcher($currentgroup, $now, $timetoshowusers, $this->page->context, 73 $sitelevel, $this->page->course->id); 74 75 //Calculate minutes 76 $minutes = floor($timetoshowusers/60); 77 78 // Verify if we can see the list of users, if not just print number of users 79 if (!has_capability('block/online_users:viewlist', $this->page->context)) { 80 if (!$usercount = $onlineusers->count_users()) { 81 $usercount = get_string("none"); 82 } 83 $this->content->text = "<div class=\"info\">".get_string("periodnminutes","block_online_users",$minutes).": $usercount</div>"; 84 return $this->content; 85 } 86 $userlimit = 50; // We'll just take the most recent 50 maximum. 87 if ($users = $onlineusers->get_users($userlimit)) { 88 foreach ($users as $user) { 89 $users[$user->id]->fullname = fullname($user); 90 } 91 } else { 92 $users = array(); 93 } 94 95 $usercount = $onlineusers->count_users(); 96 $usercount = ": $usercount"; 97 98 $this->content->text = "<div class=\"info\">(".get_string("periodnminutes","block_online_users",$minutes)."$usercount)</div>"; 99 100 //Now, we have in users, the list of users to show 101 //Because they are online 102 if (!empty($users)) { 103 //Accessibility: Don't want 'Alt' text for the user picture; DO want it for the envelope/message link (existing lang string). 104 //Accessibility: Converted <div> to <ul>, inherit existing classes & styles. 105 $this->content->text .= "<ul class='list'>\n"; 106 if (isloggedin() && has_capability('moodle/site:sendmessage', $this->page->context) 107 && !empty($CFG->messaging) && !isguestuser()) { 108 $canshowicon = true; 109 message_messenger_requirejs(); 110 } else { 111 $canshowicon = false; 112 } 113 foreach ($users as $user) { 114 $this->content->text .= '<li class="listentry">'; 115 $timeago = format_time($now - $user->lastaccess); //bruno to calculate correctly on frontpage 116 117 if (isguestuser($user)) { 118 $this->content->text .= '<div class="user">'.$OUTPUT->user_picture($user, array('size'=>16, 'alttext'=>false)); 119 $this->content->text .= get_string('guestuser').'</div>'; 120 121 } else { 122 $this->content->text .= '<div class="user">'; 123 $this->content->text .= '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&course='.$this->page->course->id.'" title="'.$timeago.'">'; 124 $this->content->text .= $OUTPUT->user_picture($user, array('size'=>16, 'alttext'=>false, 'link'=>false)) .$user->fullname.'</a></div>'; 125 } 126 if ($canshowicon and ($USER->id != $user->id) and !isguestuser($user)) { // Only when logged in and messaging active etc 127 $anchortagcontents = '<img class="iconsmall" src="'.$OUTPUT->pix_url('t/message') . '" alt="'. get_string('messageselectadd') .'" />'; 128 $anchorurl = new moodle_url('/message/index.php', array('id' => $user->id)); 129 $anchortag = html_writer::link($anchorurl, $anchortagcontents, array_merge( 130 message_messenger_sendmessage_link_params($user), 131 array('title' => get_string('messageselectadd')) 132 )); 133 134 $this->content->text .= '<div class="message">'.$anchortag.'</div>'; 135 } 136 $this->content->text .= "</li>\n"; 137 } 138 $this->content->text .= '</ul><div class="clearer"><!-- --></div>'; 139 } else { 140 $this->content->text .= "<div class=\"info\">".get_string("none")."</div>"; 141 } 142 143 return $this->content; 144 } 145 } 146 147
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |