I’m trying to get an array of currently logged in users.
I tried a getCollection() on modSession but i can’t figure out the data.
is there an easy way to accomplish this?
This will get users active in the last 20 minutes:
<?php
$timetocheck = (time()-(60*20))+$serverOffset;
$c = $modx->newQuery('modActiveUser');
$c->where(array('lasthit:>' => $timetocheck));
$c->sortby($modx->getSelectColumns('modActiveUser','modActiveUser','',array('username')),'ASC');
$ausers = $modx->getCollection('modActiveUser',$c);
foreach($ausers as $auser) {
$output .= $auser->get('username');
}
return $output;
Actually - I tried it, and it’s not exactly working.... the active users table only updates for manager users. is that the expected behavior for the modActiveUser class?
I should also mention that i’ve extended the modUser class.... could that be causing problems?
Quote from: neilness at Nov 15, 2010, 09:48 PM
Actually - I tried it, and it’s not exactly working.... the active users table only updates for manager users. is that the expected behavior for the modActiveUser class?
I should also mention that i’ve extended the modUser class.... could that be causing problems?
It may only work for Manager users. I don’t think extending modUser would be an issue.
You may have to add a plugin that listens to the login and logout events and saves the usernames somewhere (e.g., a file or custom db table) -- unless someone else has a better idea.