filter_class
This is an old revision of the document!
Table of Contents
Filter class
The filter class is used as an easy and high performance way of retrieving Datarecords.
A filter is constructed by naming which class we want to filter
$filter = new Filter('User');
Then one or more conditions can be added:
$filter->addCondition(new FilterConditionMatch('lastname', 'sahl'));
And at last the filter is executed which will return a DataRecordCollection with the results.
$datacollection = $filter->execute();
Conditions
The following conditions are available:
new FilterConditionAND($condition1, $condition2); // Return objects for which both conditions are true. new FilterConditionGreater($field, $value); // Return objects where the content of $field are greater than $value. new FilterConditionGreaterEqual($field, $value); // Return objects where the content of $field are greater or equal than $value. new FilterConditionLesser($field, $value); // Return objects where the content of $field are lesser than $value. new FilterConditionLesserEqual($field, $value); // Return objects where the content of $field are lesser or equal than $value. new FilterConditionLike($field, $value); // Return objects where the content of $field contains part of $value. new FilterConditionMatch($field, $value); // Return objects where the content of $field is exactly $value. new FilterConditionNOT($condition); // Return all objects which isn't matched by $condition. new FilterConditionOR($condition1, $condition2); // Return objects where one of the conditions is true. new FilterConditionOneOf($field, $values); // Return objects where the content of $field is one of the supplied $values.
Not all conditions work on all field types.
Serializing filters
Filters can be serialized as a JSON string, so they can be stored in databases or passed through forms.
$json = $filter->toJSON();
And they can be reconstructed just as easy.
$filter = Filter::getFilterFromJSON($json);
filter_class.1572463411.txt.gz · Last modified: 2019/10/30 19:23 by sahl