Hmmm ... Maybe the lasthit field is only updated when the user is in the Manager.
I think this snippet would do it, but it might take some time if you have a lot of users:
<?php
$allUsers = $modx->getCollection('modUser');
$count = 0;
foreach ($allUsers as $aUser) {
if ($aUser->hasSessionContext('web') ) {
$output .= "\n <li>" . $aUser->get('userName') . '</li>';
$count++;
}
}
if ($count) {
return "\n<ul>" . $output . "\n</ul>";
} else {
return '<p>No Users online</p>';
}
You could also do it (much faster) with a plugin tied to OnWebLogin and OnWebLogout that stored the username (and maybe the time) in a custom DB table on login and deleted it on logout. I don't know if OnWebLogout catches users who just close the browser, though, so you might have to delete old entries before getting the current list.