List of last loggedin user

Author Message

Michael Fürst

Wednesday 06 May 2009 3:21:12 pm

Hi guys,

I'm trying to create a list of the last loggedin users (with template functions). I've no problem with fetching the users (list), but I'm unable to order this list by login-timestamp descending - for example to show the last five loggedin users. The reason is, that i cannot find a login-timestamp.

Has anyone an idea or knows a tutorial for this problem?

Thanks & regards,
Mike

Łukasz Serwatka

Thursday 07 May 2009 12:07:34 am

Hi,

Information about user visit is stored in the ezuservisit table. ezuservisit. current_visit_timestamp and ezuservisit.last_visit_timestamp

Information about user last visit you can get from eZUser object as attribute $user.last_visit
which is actually a value from ezuservisit.last_visit_timestamp. Having this information you can build extended attribute filter.

You may also look on the logged_in_users[1] template fetch function and sort by activity.

[1] http://ez.no/doc/ez_publish/technical_manual/4_0/reference/modules/user/fetch_functions/logged_in_users

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Łukasz Serwatka

Thursday 07 May 2009 12:26:38 am

Aside note. I have added attribute current_visit to the eZUser object.
http://issues.ez.no/14870

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Michael Fürst

Thursday 07 May 2009 12:02:23 pm

Hi Lukasz,

I tried to fetch the users by they parent node. The reason is, that i only want to display users of group "registered users". Reason is, that i don't want to show the logins of users of group "Admin" or "Editors" and so on.

So i built the following fetch:

{def $registeredUserNodeId = 12} // ID of Node "Registered Users"
{def $latestLogins=fetch(content, list, hash( parent_node_id, $registeredUserNodeId,
                                                               sort_by, array('last_visit',true())
                                                             ) 
)}

But, as you can think, sorting like this doesn't work. Do you have an idea what to do to get the sorting?

Beside I've a caching problem - user list isn't update without clearing cache. But i think i can fix it with the viewcache.ini...

Thanks & regards,
Michael

Michael Fürst

Thursday 07 May 2009 12:37:43 pm

So, now I've tried to do it the other way round...

{def $latestLogins=fetch( 'user', 'logged_in_users',
                   hash( 'sort_by', array( array( 'activity', true() ) ) ) )}

{$latestLogins|attribute(show,1)}

But I've no idea, how to order the users by attribute "last_login"... seems there is no attribute filter on user-fetches!?

Michael Fürst

Tuesday 12 May 2009 1:43:42 pm

Ok, now I've tried many different solutions like this one the last days:

{def $latestLogins=fetch( 'user', 'logged_in_users',
                   hash( 'sort_by', array( 'last_visit', true() ) ) )}

But none of my solutions work as expected.
Has anyone another hint for me, how to get the ten last loggedin users?
In meantime I've upgraded to version 4.1.1...

Thanks in advance,
ciao,
Mike

André R.

Tuesday 12 May 2009 2:19:29 pm

Could use custom sql using a simple template operator, you'll find the data you need in ezsession / ezuservisit tables. Alternatively there are some functions in eZUser class, for instance 'fetchLoggedInList', it uses ezsession.expiration_time if you set sort by parameter to array('activity', true ). But it is probably best to use ezuservisit.current_visit_timestamp, witch is updated on login.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Michael Fürst

Thursday 14 May 2009 2:57:49 am

Hi Andre,
Do you know a tutorial for developing own template operators!? I think this would be the best way...

Cheers,
Mike

André R.

Thursday 14 May 2009 6:08:12 am

A simple example would be:
http://pubsvn.ez.no/community/trunk/extension/is_ssl/

A more full example with named parameters could be(just the operator, look at above example for the other files you need):
http://svn.ez.no/svn/extensions/ezwebin/trunk/packages/ezwebin_extension/ezextension/ezwebin/autoloads/eztagcloud.php

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Michael Fürst

Thursday 14 May 2009 7:20:26 am

Hi Andre,

Thanks for this information.
Just another question: Shall the new operator be a function in "ezwebin/autoloads" (as ezTagCloud is which i've already extended some months ago) or shall the function for fetching the last loggedin users be an own extension (like "ezfind", "ezoe") in the extension directory?

Wich is the correct way?

Bye,
Mike

André R.

Thursday 14 May 2009 8:17:03 am

Either a custom extension of its own, or part of some extension you already use(but not in others extensions like ezwebin, just creates problems for your self when you want to update them..).
It basically depends on how reusable you think the operator is, in this case I would say an extension of its own and upload it to projects.ez.no ;)

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Michael Fürst

Thursday 14 May 2009 8:32:19 am

HI,

Ok, thanks :) That's a very important information for reuse of extensions and understanding of the system. Maybe you can give me a hint with my eZOE problem... I really have no more idea what to do to embed the images...

Thanks a lot Andre,
Cheers,
Michael

Nicolas Jessel

Wednesday 17 November 2010 8:06:48 am

Hello,

In my case, I fetch logged in users with:

fetch( "user", "logged_in_list",
hash( "sort_by", "activity" ) )

But, I've a SQL ERROR:

Error: eZMySQLiDB Nov 17 2010 16:58:02
Query error (1054): Unknown column 'ezuservisit.expiration_time' in 'where clause'. Query: SELECT ezuser.contentobject_id as user_id, ezcontentobject.name
FROM ezuservisit, ezuser, ezcontentobject
WHERE ezuservisit.user_id != '10' AND
      ezuservisit.expiration_time > '1290009422' AND
      ezuser.contentobject_id = ezuservisit.user_id AND
      ezcontentobject.id = ezuser.contentobject_id

I remplace, in eZUser::fetchLoggedInList(), ezuservisit.expiration_time by ezuservisit.last_visit_timestamp and it's working.

I hope it's exact ....

Bye

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 04:08:53
Script start
Timing: Jan 18 2025 04:08:53
Module start 'layout'
Timing: Jan 18 2025 04:08:53
Module start 'content'
Warning: PHP: E_DEPRECATED Jan 18 2025 04:08:54
trim(): Passing null to parameter #1 ($string) of type string is deprecated in /home/ze/public_html/share.se7enx.com/var/community/cache/template/compiled/table-02cf899a6d707917c58210ed54ffe2ff.php on line 147
Timing: Jan 18 2025 04:08:54
Module end 'content'
Timing: Jan 18 2025 04:08:54
Script end

Main resources:

Total runtime1.0419 sec
Peak memory usage4,096.0000 KB
Database Queries91

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0076 587.9141152.6250
Module start 'layout' 0.00760.0030 740.539139.4453
Module start 'content' 0.01051.0298 779.9844772.7109
Module end 'content' 1.04040.0015 1,552.695332.3750
Script end 1.0418  1,585.0703 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00390.3763160.0002
Check MTime0.00150.1446160.0001
Mysql Total
Database connection0.00090.086610.0009
Mysqli_queries0.899486.3209910.0099
Looping result0.00110.1059890.0000
Template Total1.011697.120.5058
Template load0.00260.247620.0013
Template processing1.009096.843020.5045
Template load and register function0.00020.014610.0002
states
state_id_array0.00080.079310.0008
state_identifier_array0.00150.142220.0007
Override
Cache load0.00250.2441970.0000
Sytem overhead
Fetch class attribute can translate value0.00160.157140.0004
Fetch class attribute name0.00210.1989160.0001
XML
Image XML parsing0.00220.209640.0005
class_abstraction
Instantiating content class attribute0.00010.0085250.0000
General
dbfile0.00130.1255310.0000
String conversion0.00000.000840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
12content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
13content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
27content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
15content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezxmltags/strong.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/strong.tplEdit templateOverride template
2content/datatype/view/ezxmltags/td.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/td.tplEdit templateOverride template
2content/datatype/view/ezxmltags/tr.tpl<No override>extension/community/design/community/templates/content/datatype/view/ezxmltags/tr.tplEdit templateOverride template
1content/datatype/view/ezxmltags/table.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/table.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 79
 Number of unique templates used: 11

Time used to render debug report: 0.0001 secs