Could please someone say how to include login count of a user in a view. I took and cloned one of the user IP views and have now something I want with last login, online etc, but I cannot find the login count in the views UI.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ñull’s picture

From the code I see that login_count is implemented as a token, but how on earth do you include a token in a view?

ñull’s picture

Title: login count field in views » login count how to?
Component: Code » Documentation
FileSize
2.24 KB

Attached a hack to include login count in a view. I had a problem with duplicate values and apparently the DISTINCT function in views is not doing what it should ). The only work around I found was to remove the left join relation from the query. Either use the included patch user_stats.views.inc or patch it with login_count.user_stats.views.inc.patch

If there is a more elegant solution for the duplicate problem, then please contribute it. When a new Views release comes out, I will remove the work around and re-upload my patch here.

ñull’s picture

Title: login count how to? » login count field in views
Category: support » feature
Status: Active » Needs work
ñull’s picture

Component: Documentation » Code
ñull’s picture

Title: login count how to? » login count field in views
Component: Documentation » Code
FileSize
2.18 KB

After views 6.x-2.8 was released my work around became obsolete. Attached the new patch without it.

ñull’s picture

Status: Needs work » Needs review

Please could someone review it?

Liam McDermott’s picture

Version: 6.x-1.0-rc1 » 6.x-1.x-dev

Ah, thanks for posting this! I'm really swamped at the moment, but it'll get reviewed at some point in the near future.

User login count does suck pretty badly at the moment though; it literally only counts logins, not when someone leaves, comes back and resumes a previous session. Would be great if you created a new issue (and maybe even a patch) for that. If it's a problem.

aliciatheduff’s picture

I tried this patch out, am I supposed to see the new field appear under the users category in views?

chuckbar77’s picture

+1 subscribing

YK85’s picture

subscribing

Open Social’s picture

subscribing,

I can't find the item in the views field list. What should I do?

I used views custom php field to include it via the api

<?php print user_stats_get_stats('login_count', $data->users_uid);?>

But it looks like views chart doesn't like that

lukus’s picture

@goalgorilla;

The custom PHP fields aren't actually calculated until the view is rendered as far as I know, which might be why it's not working the way you hope.

hockey2112’s picture

Issue summary: View changes

How would I modify the php code from #11 so that it is compatible with Drupal 7?

cferthorney’s picture

@hockey2112 I'm going to work on this over the Easter break (This coming weekend) I think, as I need the feature for a work site. I'll apply a 7.x compatible patch (Haven't coded for D6 in years so won't be tackling that I'm afraid)

hockey2112’s picture

That sounds great, thanks!

Liam McDermott’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

cferthorney, that sounds great. Hope you're having some luck getting this done, the Views integration was quite badly done in the first place (by me) and has suffered bitrot too, so I have a bad feeling quite a lot may need to be rewritten in the Views integration.

Also bumping the version to 7.x, as I can understand why you wouldn't want to work with 6.x.