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.

View Replies:
pvernaglia replied on at Permalink Reply
pvernaglia
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.
commisariat replied on at Permalink Reply
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:

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.
firepixel replied on at Permalink Reply
firepixel
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() {
c5mix replied on at Permalink Reply
c5mix
Do you know how to do this in 5.6 and above, since overriding/extending core classes has changed
firepixel replied on at Permalink Reply
firepixel
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?
c5mix replied on at Permalink Reply
c5mix
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...
firepixel replied on at Permalink Reply
firepixel
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();
   }
}
c5mix replied on at Permalink Reply
c5mix
Thanks. I'll try that.
jcrooke replied on at Permalink Reply
jcrooke
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.
c5mix replied on at Permalink Reply
c5mix
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.
jcrooke replied on at Permalink Reply
jcrooke
So how do I do that? Do I need to download concrete 5.5 instead?
c5mix replied on at Permalink Reply
c5mix
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/...
firepixel replied on at Permalink Reply
firepixel
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.
nikkor replied on at Permalink Reply
nikkor
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.