{$their->} placeholder keeps returning {$my->} in element

abel408

Member
Hello all,

I'm trying to display the last login date for each user in my fabrik user list. I am getting this information from the joomla users table in the "lastvisitDate" element.

I have created a Date element (I also tried a field element type) and have the following in my Default value:

$db =& JFactory::getDBO();
$query = "SELECT `userID` FROM `users` WHERE `ID` = '{rowid}'";
$db->setQuery($query);
$userid = $db->loadResult();
$cname = '{$their->$userid->lastvisitDate}';
return $cname;


For what ever reason, it keeps returning the current user's information instead of the user who I am editing.


Also, is there a better way to do this? This is a new element for an existing list. I would like to have each existing record display the last login date in the list view without having to edit each user.

Thanks for your help!
 
I decided to abandon the their placeholder and use the following:

$db =& JFactory::getDBO();
$query = "SELECT `userID` FROM `users` WHERE `ID` = '{rowid}'";
$db->setQuery($query);
$userid = $db->loadResult();
$query = "SELECT `lastvisitDate` FROM `_users` WHERE `ID` = '$userid'";
$db->setQuery($query);
$lastlogin = $db->loadResult();
return $lastlogin;

This works well, but it's not going to do what I want it to do. It's only going to evaluate this as the default value of the element. I need it to show the value of lastvisitDate every time so that when lastvisitDate updates, this element will also update.

Is there anything that does this?
 
Yeah, that's not how the {$their...} placeholder works. It takes {$their->var->attribute}, where 'var' is a query string arg (or form input), and 'attribute' is the user table field. So if you had &owner=123 in the URL (or a form input), {$their->owner->email} would yield the email of userid 123.

Also, remember that placeholders replacement is done BEFORE your code is run, and your code is then run with placeholders replaced with values. So you can't use a $variable you compute in your code as part of a placeholder.

To do your update on all rows, you'll need to run a query by hand. Assuming 'users' is your Fabrik table, 'last_visit' is the field on that you want to set, and abc_users is your J! users table ...

UPDATE users LEFT JOIN abc_users ON abc_users.id = users.userID SET users.last_visit = abc_users.lastvisitDate

-- hugh
 
Thanks hugh. All makes sense now. Running the query by hand is just going to update the records once correct? So if someone logs in again, the value of abc_users.lastvisitDate will get updated, but users.last_login will not... How can I keep these 2 records in sync?
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top