Quick search:


How to create and use filters

The filters that are available for a type of peanuts are retrieved by the classDescriptor from the static method 'getFilters' on their class. You may retrieve filters from there to use as you please, or change the list by overriding this method (See how to override the default search options list of a SearchPage).

The simplest way to create a filter is to call the static method PntSqlFilter::getInstance, passing the type and the navigational path. A navigational path is string that consists of a series of property names, separated by dots. In example 4 the path is 'employee.country.name', the filter will be used for selecting peanuts by the name of the country of the employee of each peanut. See example 4.

The path of a filter can be as long as you want. The last property must be a persistent field property. The others must be derived properties that implement navigation over a relationship. Currently multi value properties are not supported. Paths over recursive relationships should work fine. 

Since version 1.2 the user can combine multiple filters in a SearchPage. When he selects AND or OR in the filterCombinator of the filter, a new filter is shown. The maximum number of filters can be overridden by specializing the page, overriding the getFilterFormPart method and set the $nAdvancedFilters field on the part.

You can combine multiple filters programatically to a new one using an instance of PntSqlCombiFilter. The filters to be combined are added to the combiFilter by the addPart method. All combined filters must have the same itemType. The filters will by default be combined using 'AND". You can change 'combinator' property to 'OR'. You may set 'comparator' and values on each of the combined filters or, if they all have the same valueType, set them at once on the combiFilter. See example 7.

You may set the (topmost) filter to the 'filter' property of a  sort. This combines the sorting with the filters. Most domain model classes define a method getLabelSort that returns a default sort (example).

To use the filters, call the addSqlFromSpec method on a queryHandler on which the select and from clause are already added. Use the sortObject as the argument, or if you do not need sorting, the topmost filter. See how to retrieve instances of a class from the database for how to get and use the queryHandler.

Multiple filters created this way with arbitrary paths as well as sortObjects with arbitrary paths should work seamlessly together if combined in a single query. CombiFilters can be nested.

It is possible to create a custom filter with arbitrary SQL by instantiating PntSqlFilter and setting the 'sqlTemplate' property, see getSqlTemplate method comment. However, such a filter may not properly combine its join conditions with other filters and a sortObject. That may be corrected by creating and using a subclass of PntSqlFilter and overriding the addJoinConditionAsKeysByTableAlias method. For an example of this method see PntSqlJoinFilter::addJoinConditionAsKeysByTableAlias