Skip to content

Commit

Permalink
fixes to users online grid
Browse files Browse the repository at this point in the history
* add server_offset_time to displayed times
* fix query so that it actually displays the most recent activity of each user
  • Loading branch information
netProphET committed Mar 27, 2013
1 parent 1e68d96 commit 464b8ff
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions manager/controllers/default/dashboard/widget.grid-online.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,24 @@
*/
class modDashboardWidgetWhoIsOnline extends modDashboardWidgetInterface {
public function render() {
$timetocheck = (time()-(60*20))+$this->modx->getOption('server_offset_time',null,0);
$c = $this->modx->newQuery('modManagerLog');
$c->innerJoin('modUser','User');
$timetocheck = (time()-(60*20));

$c = $this->modx->newQuery('modManagerLog');
$c->innerJoin('modUser','User');
$c->where(array(
'occurred:>' => strftime('%Y-%m-%d, %H:%M:%S',$timetocheck),
));
$c->where(
"occurred = (SELECT MAX(`occurred`)
FROM {$this->modx->getTableName('modManagerLog')} AS log2
WHERE `log2`.`user` = `modManagerLog`.`user`
GROUP BY `user`)"
);
$data['total'] = $this->modx->getCount('modManagerLog',$c);

$c->select($this->modx->getSelectColumns('modManagerLog','modManagerLog'));
$c->select($this->modx->getSelectColumns('modUser','User','',array('username')));
$c->sortby('occurred','DESC');
$c->groupby('user');
$ausers = $this->modx->getIterator('modManagerLog',$c);

$users = array();
Expand All @@ -33,14 +36,14 @@ public function render() {
foreach ($ausers as $user) {
$userArray = $user->toArray();
$userArray['currentAction'] = $user->get('action');
$userArray['occurred'] = strftime('%b %d, %Y - %I:%M %p',strtotime($user->get('occurred')));
$userArray['occurred'] = strftime('%b %d, %Y - %I:%M %p',strtotime($user->get('occurred'))+floatval($this->modx->getOption('server_offset_time',null,0)) * 3600);
$userArray['class'] = $alt ? 'alt' : '';
$users[] = $this->getFileChunk('dashboard/onlineusers.row.tpl',$userArray);
}

$output = $this->getFileChunk('dashboard/onlineusers.tpl',array(
'users' => implode("\n",$users),
'curtime' => strftime('%I:%M %p',time()+$this->modx->getOption('server_offset_time',null,0)),
'curtime' => strftime('%I:%M %p',time()+floatval($this->modx->getOption('server_offset_time',null,0)) * 3600),
));
return $output;
}
Expand Down

0 comments on commit 464b8ff

Please sign in to comment.