Expression to return the total number of users

Permalink
Hi All,

Hoping someone can help me with what should be an easy one (but not easy for me).

I want to include the total number of members I have on my site. I'm using Magic Data to give me the number of active users but I can't for the life of me work out how to display the total number of members.

Any ideas guys?

Thanks,
Mike

designserve
 
JohntheFish replied on at Permalink Reply
JohntheFish
There isn't anything that does this directly. So you will need a simple expression
"Registered Users" AS_GROUP LIST_USERS 1000 COUNT_LIST

This finds the group "Registered Users" (or whatever group your site members are in), lists all the users in that group (up to 1000), then counts the size of the list.

It isn't the most efficient way to solve the problem, so if you have a lot of users it could become slow. One way round that would be by caching the result, to put the expression in a block in a stack and load the stack using Universal Content Puller with a very long cache time (24 hours?). A second way round that would be to write some php as a custom symbol that counted the number of users in a group in the database without listing them all.
designserve replied on at Permalink Reply
designserve
Thanks John,

I've been using the following to show how many users "are online":

[% "last hour" LIST_ACTIVE_USERS %]


But that is giving me a figure that looks far to high for members to believe. At this momet it is reporting 156. When I use the following I understand that it should default to the last 15 minutes?

[% LIST_ACTIVE_USERS %]


But it always returns "1", when I know that there are users on the site from Google Analytics.

I have around 2500 members. The Search Users page in the dashboard reports the total number of users but not being very php-savvy I can't find the portion of code that is returning this result despite searching for ages.

What I'm trying to do is...

"2487 Members, 49 Online Now" (reporting the last 15 minutes or 30 minutes say)

Many thanks,
Mike
JohntheFish replied on at Permalink Reply
JohntheFish
As with any MD list command, LIST_ACTIVE_USERS defaults to returning just 1 item. You need to specify a maximum number returned and then count the list. At the moment your expression it is just returning the id of the first user it finds who is 'active' - perhaps you - the super admin with id 1, or the user id 156.

Any time preceding it is best turned into a time using "AS_TIME" - that takes into account all sorts of relaxed ways of specifying time.

When no users are returned, the list is actually a single null entry, so you will need to extract that special case with a zero as then end

SET "last hour" AS_TIME LIST_ACTIVE_USERS 1000 ZERO_AS_THEN_END "None" COUNT_LIST


A final point, LIST_ACTIVE_USERS interfaces to a sql query that makes assumptions about activity indicators from the PageStatistics table, so you are unlikely to ever get a result that is really accurate and it won't work at all if Page Statistics are disabled.

... and disabling Page Statistics is usually a good practice unless you really need it as it slows a site down.
designserve replied on at Permalink Reply
designserve
Thanks for the explanations John. Yes I did find that I had to tun on page stats and I don't want to do that really so I'll have to find another way in due course.

It's not really a crucial feature I suppose, just nice to have. There are quite a few posts from people asking about this sort of basic function and only one addon which doesn't seem to be working for the current version so I haven't installed it.

Anyway, thanks for the response I appreciate it.
JohntheFish replied on at Permalink Reply
JohntheFish
I suspect any addon that doesn't use page stats for this would be updating an equivalent table or data just for user stats, so would likely run into similar performance overheads.
WillemAnchor replied on at Permalink Reply
WillemAnchor
'User Info' can count visitors for 5.7 sites
Doesn't require stats. It does indeed use a table like John said.
For better performance, it requests the data after the document is ready and sets a timer to check it again regularly.
You can set the timing parameters.

It currently does not count the registered members, but it does count
- the total online visitors,
- online registered users
- online guests
- number of visitors on the current page.

Besides this, it can show a lot more info about the current user, or the creator of the page.
Like name, last login, avatars, badges, etc
Also it can show user attributes.
This all works with {ui_tags} embedded in a content-block style editor.

http://www.concrete5.org/marketplace/addons/user-info1/...