eZ Community » Forums » Developer » Fetching logged in users using PHP
expandshrink

Fetching logged in users using PHP

Fetching logged in users using PHP

Thursday 14 January 2010 9:53:41 am - 3 replies

Hi there,

I have a problem fetching users and filtering them by "logged in" status :

$membres = eZContentObjectTreeNode::subTreeByNodeID(false, 253);
 
foreach($membres as $membre){
 
    $usr = eZUser::instance($membre->ContentObjectID);
    $nod = eZContentObject::fetch($membre->ContentObjectID);
 
    if($usr->isLoggedIn() == true)
        $liste[] = array("nom" => $nod->Name, "id" => $nod->ID);
 
}

But when I look to my $liste, everybody is in, although everybody is not logged in. (verified in the administration panel)

For information, I really need this code because I need to filter the users by another added attribute too. And as the web site will have a lot of users. I prefer to do this kind of operations directly in PHP and not with the template language (for speed).

Thanks,

Damien

Modified on Wednesday 24 March 2010 9:17:57 am by Damien MARTIN

Thursday 14 January 2010 10:14:22 am

If speed is your concern, I'd suggest going for a custom sql request; With many users the above code will be doing a huge amount of queries, wasting time and memory...

Thursday 14 January 2010 10:21:30 am

I'm not sure why this would fail, but it might be more efficient to use eZUser::fetchLoggedInList(). But maybe you need to filter this list out by group, in which case custom code would indeed be required.

Thursday 14 January 2010 10:46:42 am

@Gaetano

I would like to create custom SQL queries but I don't have the time for now to look at the database.
I looked some months ago for a diagramm with all the tables and relations of the eZ database but unsuccessfully.

@Bertrand

eZUser::fetchLoggedInList() works very well for what I want to do. I just now have to fetch using eZContentObject::fetch() and all the datas I need are there.
I suppose it would be faster with this method (no more need to fetch eZUser).
I don't know when I haven't tried this method before...

Thank you very much guys !

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from