Browse files

MDL-33815 Online Users block: Add query condition to filter out delet…

…ed users and lastaccess date greater than now
  • Loading branch information...
1 parent a8ce907 commit e09d4fcb8c723bf20e23037813799e73775eef43 @rwijaya rwijaya committed Oct 11, 2012
Showing with 17 additions and 7 deletions.
  1. +17 −7 blocks/online_users/block_online_users.php
View
24 blocks/online_users/block_online_users.php
@@ -31,7 +31,8 @@ function get_content() {
if (isset($CFG->block_online_users_timetosee)) {
$timetoshowusers = $CFG->block_online_users_timetosee * 60;
}
- $timefrom = 100 * floor((time()-$timetoshowusers) / 100); // Round to nearest 100 seconds for better query cache
+ $now = time();
+ $timefrom = 100 * floor(($now - $timetoshowusers) / 100); // Round to nearest 100 seconds for better query cache
//Calculate if we are in separate groups
$isseparategroups = ($this->page->course->groupmode == SEPARATEGROUPS
@@ -53,18 +54,23 @@ function get_content() {
}
$userfields = user_picture::fields('u', array('username'));
-
+ $params['now'] = $now;
+ $params['timefrom'] = $timefrom;
if ($this->page->course->id == SITEID or $this->page->context->contextlevel < CONTEXT_COURSE) { // Site-level
$sql = "SELECT $userfields, MAX(u.lastaccess) AS lastaccess
FROM {user} u $groupmembers
- WHERE u.lastaccess > $timefrom
+ WHERE u.lastaccess > :timefrom
+ AND u.lastaccess <= :now
+ AND u.deleted = 0
$groupselect
GROUP BY $userfields
ORDER BY lastaccess DESC ";
$csql = "SELECT COUNT(u.id)
FROM {user} u $groupmembers
- WHERE u.lastaccess > $timefrom
+ WHERE u.lastaccess > :timefrom
+ AND u.lastaccess <= :now
+ AND u.deleted = 0
$groupselect";
} else {
@@ -77,19 +83,23 @@ function get_content() {
$sql = "SELECT $userfields, MAX(ul.timeaccess) AS lastaccess
FROM {user_lastaccess} ul $groupmembers, {user} u
JOIN ($esqljoin) euj ON euj.id = u.id
- WHERE ul.timeaccess > $timefrom
+ WHERE ul.timeaccess > :timefrom
AND u.id = ul.userid
AND ul.courseid = :courseid
+ AND ul.timeaccess <= :now
+ AND u.deleted = 0
$groupselect
GROUP BY $userfields
ORDER BY lastaccess DESC";
$csql = "SELECT COUNT(u.id)
FROM {user_lastaccess} ul $groupmembers, {user} u
JOIN ($esqljoin) euj ON euj.id = u.id
- WHERE ul.timeaccess > $timefrom
+ WHERE ul.timeaccess > :timefrom
AND u.id = ul.userid
AND ul.courseid = :courseid
+ AND ul.timeaccess <= :now
+ AND u.deleted = 0
$groupselect";
$params['courseid'] = $this->page->course->id;
@@ -138,7 +148,7 @@ function get_content() {
}
foreach ($users as $user) {
$this->content->text .= '<li class="listentry">';
- $timeago = format_time(time() - $user->lastaccess); //bruno to calculate correctly on frontpage
+ $timeago = format_time($now - $user->lastaccess); //bruno to calculate correctly on frontpage
if (isguestuser($user)) {
$this->content->text .= '<div class="user">'.$OUTPUT->user_picture($user, array('size'=>16));

0 comments on commit e09d4fc

Please sign in to comment.