Filtering related records based no logged in user
Archived from the Xataface Users forum.
yokaiface — Mon Aug 03, 2009 12:35 pm
Hi Steve,
Yet another challenge! Is there a way to filter related records based on logged in user? I want the related records to display on those records owned by the one logged in.
Regards
shannah — Wed Aug 05, 2009 12:24 pm
OK.. haven’t tested this but it should work..
2 steps:
-
Create a calculated field in the delegate class for the source table that simply returns the logged in user.
-
Include this calculated field as part of the relationship definition.
E.g.
Your calculated field might look like:
- Code: Select all
function field__current_user(&$record){ $auth =& Dataface_AuthenticationTool::getInstance(); return $auth->getLoggedInUserName(); }
Then in your relationship you might have:
- Code: Select all
[books] books.category_id="$category_id" books.owner_id="$current_user"
This all assumes that your relationship is going from a “category” table to a “books” table and includes only books that match the current category’s category_id AND the book’s owner_id field matches the username of the currently logged in user.
-Steve