setSecurityFilter - two conditions
Archived from the Xataface Developers forum.
sheriff_deadeye — Tue Apr 13, 2010 2:31 pm
Another quick question
I have successfully implemented a security filter so that records are limited to the their ‘owner’. For one of the user roles, however, i need what is basically an ‘or’ clause when setting the security filter.
here is my current statement (contained in the getPreferences function of the applicationdelegate.php file)
- Code: Select all
$mytable->setSecurityFilter(array('manager_id'=>$user->val('employee_id')));
I need to filter the results on this condition:
manager_id = employee_id
or
project_manager_id = employee_id
How do i accomplish this ?
as always..thanks for the help!
shannah — Wed Apr 14, 2010 10:30 am
Hmm… this is a bit tricky. Xataface doesn’t do “or” over different fields. There are 2 hacks that I can think of to achieve this behavior:
- Add a grafted field in your __sql__ directive of the fields.ini file that concatenates the two fields you’re interested in, then do a search on this field.
or - Implement the __sql__ method in your delegate class to include the filter directly there in SQL.
The first option might look like:
fields.ini file:
- Code: Select all
__sql__ = "select m.*, concat('|',m.manager_id,'|',m.project_manager_id,'|') as manager_ids from mytable m"
Then your security filter would be:
- Code: Select all
$mytable->setSecurityFilter(array('manager_ids'=>'|'.$user->val('employee_id').'|'));