User Tools

Site Tools


filter_class

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 ConditionMatch('lastname', 'sahl'));

And at last the filter is executed which will return a Collection with the results.

$datacollection = $filter->execute();

Conditions

The following conditions are available:

new ConditionAND($condition1, $condition2);
// Return objects for which both conditions are true.
 
new ConditionGreater($field, $value);
// Return objects where the content of $field are greater than $value.
 
new ConditionGreaterEqual($field, $value);
// Return objects where the content of $field are greater or equal than $value.
 
new ConditionInFilter($field, $filter);
// Return objects where the content of $field are present in the filter $filter.
 
new ConditionLesser($field, $value);
// Return objects where the content of $field are lesser than $value.
 
new ConditionLesserEqual($field, $value);
// Return objects where the content of $field are lesser or equal than $value.
 
new ConditionLike($field, $value);
// Return objects where the content of $field contains part of $value.
 
new ConditionMatch($field, $value);
// Return objects where the content of $field is exactly $value.
 
new ConditionNOT($condition);
// Return all objects which isn't matched by $condition.
 
new ConditionOR($condition1, $condition2);
// Return objects where one of the conditions is true.
 
new ConditionOneOf($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.txt · Last modified: 2020/08/07 11:35 by sahl

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki