[eluser]tazoony[/eluser]
Hi there !
I'm glad to contribute today
I'm working on a CRM-based application. Then I needed to make users able to create customers segments. But you all know security problems in this case.
So, I made a Datamapper extension which makes me able to import a (very simple) script (from a string var) that applies some filters by methods calling.
You just need to call query_script() method of you DM object :
Code:
$member = new Member();
$member->query_script("
// Your query script here
");
The general query script syntax is pretty simple :
[CLAUSE] :: [FIELD] :: [VALUE(S)]
Value can be a single value or a multiple value. In this case you need to use { }
Example :
Code:
where_in :: zipcode :: {75002,95890,92300}
or_where :: zipcode > :: 93000
or_where_between :: zipcode :: {50000,69999}
where :: birthdate < :: 1988-12-01
In facts, each line simply calls the right DM method with the right parameters.
And we can use Datamapper group instructions, comments, etc. :
Code:
group_start
where_in :: zipcode :: {75002,95890,92300}
or_where :: zipcode > :: 93000
or_where_between :: zipcode :: {50000,69999}
group_end
// Specific age
where_between :: birthdate :: {1988-12-01 , 2000-05-18}
You can specify allowed methods calls in $_dm_allowed_methods property.
By the way you can now store your DM queries in your database !
Please find the code attached. Just add this file in your Datamapper extensions directory (should be
application/datamapper), and activate it in the Datamapper config.
Feel free to improve this extension, and to share these improvements
Joffrey