How To Show User Last Login Date In Dashboard
Permalink
I would like to have each user's actual date/time of last login show up in the Dashboard just like the "Date Added" does now in the Find Users tab.
It is easy enough to create a custom user attribute and get it to show up on the Dashboard's "Find Users" tab, user profile, etc. But what about core attributes? I've been trying to use handles such as uLastLogin without success.
It is easy enough to create a custom user attribute and get it to show up on the Dashboard's "Find Users" tab, user profile, etc. But what about core attributes? I've been trying to use handles such as uLastLogin without success.
I haven't tried, but take a look at concrete/elements/dashboard/users/search_results.php, you could copy that out to elements/dashboard/users and make a few changes or add a column to the table maybe use getLastOnline() similar to how getUserAdded() is in there now. I'd agree it would be nice to see that info there.
I see. Thanks for the lead on which file to override.
So I've done that and after a little experimenting I've gotten it to display the lastOnline dates and times, but with two subsequent problems.
First, the getLastOnline method, when invoked with the 'user' argument, is crashing the php date() function. When the 'system' argument is used instead, no such error occurs. The error being reported is:
Second, I do not understand how to make the Last Online column sortable in the Find Users display. When I click on the column header I do not see the little triangle icon appear, nor do the records seem to change their ordering.
So I've done that and after a little experimenting I've gotten it to display the lastOnline dates and times, but with two subsequent problems.
First, the getLastOnline method, when invoked with the 'user' argument, is crashing the php date() function. When the 'system' argument is used instead, no such error occurs. The error being reported is:
DateTime::__construct() [datetime.--construct]: Failed to parse time string (1309310000) at position 7 (0): Unexpected character
Second, I do not understand how to make the Last Online column sortable in the Find Users display. When I click on the column header I do not see the little triangle icon appear, nor do the records seem to change their ordering.
Got this to work in 5.5.2.1 - copy the /concrete/models/user_list.php file to the /models folder and change the class UserSearchDefaultColumnSet as follows...
class UserSearchDefaultColumnSet extends DatabaseItemListColumnSet { protected $attributeClass = 'UserAttributeKey'; public function getUserName($ui) { return '<a href="' . View::url('/dashboard/users/search') . '?uID=' . $ui->getUserID() . '">' . $ui->getUserName() . '</a>'; } public function getUserEmail($ui) { return '<a href="mailto:' . $ui->getUserEmail() . '">' . $ui->getUserEmail() . '</a>'; } public static function getUserDateAdded($ui) { return date(DATE_APP_DASHBOARD_SEARCH_RESULTS_USERS, strtotime($ui->getUserDateAdded())); } public static function getUserLastOnline($ui) { return date(DATE_APP_DASHBOARD_SEARCH_RESULTS_USERS, $ui->getLastOnline()); } public function __construct() {
Viewing 15 lines of 24 lines. View entire code block.
Do you know how to do this in 5.6 and above, since overriding/extending core classes has changed
Don't think it has changed that much, all my overrides are still working and upgraded many websites to 5.6. Have you tried it?
Yeah it works modifying the pre 5.6 file like you mentioned, but with 5.6 there's the new core classes that can be extended and I was just wondering the best way to go about it using that new method.
See this:
http://www.concrete5.org/documentation/how-tos/developers/overridin...
See this:
http://www.concrete5.org/documentation/how-tos/developers/overridin...
Oh I see, so you could do something like this if you didn,t care about the column order too much...
class UserSearchDefaultColumnSet extends Concrete5_Model_UserSearchDefaultColumnSet { public function __construct() { $this->addColumn(new DatabaseItemListColumn('uLastOnline', t('Last Online'), array('UserSearchDefaultColumnSet', 'getUserLastOnline'))); parent::__constructor(); } }
Thanks. I'll try that.
c5mix, did you get this to work? I am having trouble overiding the class UserSearchDefaultColumnSet in Concrete 5.6+ I'm starting to think it is a bug.
No I wasn't able to extend it like firepixel mentioned, so i just modified a pre 5.6 version like originally mentioned and that worked.
So how do I do that? Do I need to download concrete 5.5 instead?
Yeah, you'll have to download an older version (5.5.2.1) if you don't have one. You can get that here:
http://www.concrete5.org/developers/downloads/...
http://www.concrete5.org/developers/downloads/...
I have it working on 5.6, you just have to override rather than extending.
It turned out that since it is a secondary class within another file you cannot extend it and have to overwrite the whole file.
It turned out that since it is a secondary class within another file you cannot extend it and have to overwrite the whole file.
Can you please explain how the override vs extend works. I have tried adding my updated class UserSearchDefaultColumnSet to the pub_html/models/user_list.php but when I do I am getting an error of: Cannot redeclare class UserSearchDefaultColumnSet
Thanks for your help.
Thanks for your help.
Here's a working solution for 5.6.3.1, which should be upgrade-proof:
Copy this file: concrete/models/user_list.php
To this path: models/user_list.php
Then adjust the content to following:
Then copy this file: concrete/tools/users/customize_search_columns.php
To this path: tools/users/customize_search_columns.php
And do the following changes:
Replace these lines:
with following:
And this line:
To following:
Now save the changes, flush cache and go to Users > Search, then Advanced search > Customize results > Choose the new column.
Good luck.
Copy this file: concrete/models/user_list.php
To this path: models/user_list.php
Then adjust the content to following:
<?php defined('C5_EXECUTE') or die("Access Denied."); class UserList extends Concrete5_Model_UserList { } class CustomUserSearchDefaultColumnSet extends UserSearchDefaultColumnSet { protected $attributeClass = 'UserAttributeKey'; public static function getUserLastOnline($ui) { if( $ui->getLastOnline() > 0 ){ return date(DATE_APP_DASHBOARD_SEARCH_RESULTS_USERS, $ui->getLastOnline()); } else { return t('Never'); } } public function __construct() { $this->addColumn(new DatabaseItemListColumn('uName', t('Username'), array('CustomUserSearchDefaultColumnSet', 'getUserName')));
Viewing 15 lines of 58 lines. View entire code block.
Then copy this file: concrete/tools/users/customize_search_columns.php
To this path: tools/users/customize_search_columns.php
And do the following changes:
Replace these lines:
$fldc = UserSearchColumnSet::getCurrent(); $fldca = new UserSearchAvailableColumnSet();
with following:
$fldc = CustomUserSearchColumnSet::getCurrent(); $fldca = new CustomUserSearchAvailableColumnSet();
And this line:
$fdc = new UserSearchColumnSet();
To following:
$fdc = new CustomSearchColumnSet();
Now save the changes, flush cache and go to Users > Search, then Advanced search > Customize results > Choose the new column.
Good luck.
@jgangso your solution almost works in 5.6, one small change is needed...
This
Needs to be this
This
$fdc = new CustomSearchColumnSet();
Needs to be this
$fdc = new CustomUserSearchColumnSet();