setSecurityFilter - two conditions

A place to discuss development of the Xataface core.

setSecurityFilter - two conditions

Postby 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!
sheriff_deadeye
 
Posts: 11
Joined: Mon Feb 22, 2010 10:46 am

Re: setSecurityFilter - two conditions

Postby 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:

1. 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
2. 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').'|'));
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Developers

Who is online

Users browsing this forum: No registered users and 15 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved