' and adjust it to your needs.
For a multi-element-filter, you may use the FilterScore-class to copy.
3. Change the constructor:
- provide optional default-config
- set the type
- check args and options if needed
- set syntax-description
- init internal vars if needed
4. Implement the filter-interface-functions (declared as abstract in
Filter-class):
- parse_value( $name, $val )
- build_query(), only for multi-element-filters
- get_input_element($prefix, $attr = array() )
5. adjust the class-documentation, scan all available FC_-configs,
if they can be used with your filter and document them accordingly.
6. add your new filter to "code_examples/filter_example2.php" with
all special new options you defined.
7. adjust this file to list your new filters in the sections:
- (2) Classes and Files
- (3) Users Guide
- (5) FAQ
- (7) Known Bugs (if any)
Changing one of the following classes is sensible work and shouldn't be done
without consultation; or you volunteer to write some unit-tests to assert
the correct functionality of existing parsers and framework after
your changes ;)
- SearchFilter, Filter
- BasicTokenizer, StringTokenizer
- BasicParser, TextParser, NumericParser, DateParser
- QuerySQL, RequestParameters
#-------- (5) FAQ -------------------------------------------------------------
This section contains some questions regarding the usage of filters for
developers of DGS. When refering to "see examples", the example-files
"code_examples/filter_example.php" and "code_examples/filter_example.php2"
are meant. More documentation you will also find in the sources,
see section (2) Classes and Files.
* Can I check if the filters have been freshly initialized without having
started a "Search" yet ?
Yes. See "include/filter.php" function "is_init()" and "is_reset()".
Example in "show_games.php", see game-restriction RESTRICT_SHOW_GAMES_ALL.
* Can I dynamically add columns/filters when using links, even when some
of the filtered columns are "removed" ?
Yes. See description above about REQF_URL-parameter.
* What filter can be used to search for negative numeric values ?
Not directly possible at the moment when you still want to use the
range-syntax. The Numeric-Filter does not allow this, because the
minus '-' is used as special range-char.
But you can still enter a negative-value by quoting the '-'-char
of course.
However, if you forbid range-syntax using filter-config FC_NO_RANGE,
then the '-' is treated as minus-sign. But that also allows to specify
exact values for that filter.
* Can I use numeric double-values ?
Yes. Use Numeric-Filter: a double 7.5 is also considered a numeric.
* Can I use SQL-queries using the OR-operator ?
Yes, but it depends on the resulting query. Take a look on the
example-files searching for FC_SQL_TEMPLATE and FC_GROUP_SQL_OR and
take a look in "include/filters.php" at the documentation for those
filter-configs (where the constants are defined).
If those filter-configs are not sufficient, you may use a complex
query using the QuerySQL-class. For that check out the examples too.
If all those possibilities doesn't fit your needs, you have to build
the query manually.
* How can the size or maximum length of the text-input-elements be changed ?
This is filter-specific, but normally can be changed with the
filter-config FC_SIZE and FC_MAXLEN. Read the according documentation
of the according Filter-class.
* Can I allow a text to start with a wildcard ?
Yes. See filter-config FC_START_WILD and see example-files for
the possible values for this config.
* Can I search for a substring without explicit use of a leading and
trailing wildcard ?
Yes. See filter-config FC_SUBSTRING.
Using this config implicitly forbids range-syntax.
Needs filter-config FC_START_WILD to be set.
Example on Text-Filter #6 in "code_examples/filter_example2.php".
* Can I forbid wildcards to be used ?
Yes. See filter-config FC_NO_WILD.
The wildcard-char '*' then is treated as normal character.
* Can I forbid the range-syntax to be used ?
Yes. See filter-config FC_NO_RANGE.
The range-char '-' then is treated as normal character.
* How can I build a complex query, but still using the filter-framework
to input values for a filter ?
Use filter-config FC_SQL_SKIP. See also example-files and check out
the possibilities you have with QuerySQL (see "include/std_classes.php"
and "code_examples/query_sql.php").
With FC_SQL_SKIP the particular filter-query isn't merged in the
SearchFilter-class and you must handle the merge manually:
$qsql = $searchfilter->get_query();
$f =& $searchfilter->get_filter(id);
if ( $f->has_query() ) {
$fq = $f->get_query();
$where = $fq->get_part( SQLP_WHERE ); ...
}
* Can I add an arbitrary SQL-part when a filter is set ?
Yes. See filter-config FC_QUERYSQL to merge additional QuerySQL when a filter
is set.
* Can I add a SQL-part using the HAVING-clause instead of the WHERE-clause ?
Yes. See filter-config FC_ADD_HAVING and/or use the QuerySQL-class.
See also example-files.
* Can I provide default-values to filters without specifying it in the URL ?
Yes. See filter-config FC_DEFAULT and see the big defaults-example in
the example-files. Be aware that this config is filter-specific, so take
also a close look on the filter-specific documentation. Escpecially for
the multi-element-filters this is important.
The "Reset search" will reset the filters to that defaults.
* How can I use numeric-values on the SQL-fields that differ from the
entered value by some factor ?
Use Numeric-Filter with filter-config FC_NUM_FACTOR. See example-files.
* Can I change the (default) used quoting-type used for text- and numeric-
based filters ?
Yes. See filter-config FC_QUOTETYPE and in example-files.
Though this is not recommended. The config was merely added to allow
for some tests of the quoting-mechanisms.
* Can I make the filters static when used with a Table, so that they
are always shown and can't be hidden ?
Yes. See filter-config FC_STATIC and in example-file
"code_examples/filter_example.php".
Actually it's the default now to show all filter-elements as static,
which can be controlled with the global const FILTER_CONF_FORCE_STATIC.
This can be overruled using the filter-config FC_HIDE,
see "code_examples/filter_example.php".
* Can I use multiple-select elements for filters ?
Yes. There are some predefined filters allowing to select more
than one element. See FilterSelection, FilterCheckboxArray.
Also see example-files. This must be activated filter-specific
using the filter-config FC_MULTIPLE. See the filter-class-documentation.
* How can I set filter-values via URL-vars ?
There are two ways how to accomplish this:
Beware that a "Reset Search" may clear those values, if not defined
with FC_DEFAULT-config.
1. Directly use the filters form-element-name to specify the value.
It's recommended to use the filter-config FC_FNAME for this.
That name is absolute and not changed even if several SearchFilter-
objects are used with prefixes. See also section (4) Developement Guide.
2. Do your own parsing of the URL-var, and after the filter-init() call,
parse the value into the filters:
$parsed_value = get_request_arg( 'myvar' );
$filter = new SearchFilter();
$f1 =& $filter->add_filter( 1, 'Numeric', 'P.ID', true);
$filter->init(); # parse URL-vars
$f1->parse_value( $fname, $parsed_value );
* Can I use filters that depend on the values in other filters ?
Yes. See filter-config FC_IF and see example-files.
* Can I use a filter for searching on table-columns with values 'Y|N' ?
Yes. Use BoolSelect-Filter and see example-files.
For the Rated-column in the Games-table there is also the special
RatedSelect-Filter also taking the 'Done'-value into account.
* Must I escape the '-40%' for a rank when using Rating-Filter ?
No. The minus-sign '-' is treated in a special way and need not to be
escaped while still allowing to use range-syntax.
However you may do escape it: "7k (-20%)" and "7k (\-20%)" are equivalent.
* Can I extend the default syntax-hover-text-description of a filter ?
Yes. See filter-config FC_SYNTAX_HINT.
Example on Numeric-Filter #2 in "code_examples/filter_example2.php".
* Can I overwrite a filters default help-id showed in the syntax-hover-text-description
of a filter ?
Yes. See filter-config FC_SYNTAX_HELP.
Example on Numeric-Filter #2 in "code_examples/filter_example2.php".
This can be used to use a filter needing different or special descriptions
in the FAQ or some other help pages.
* Can I use checkboxes to build a bitmask to search for ?
Yes. See filter-config FC_BITMASK.
Example on CheckboxArray-Filter #3 in "code_examples/filter_example2.php".
#-------- (6) Possible Future Enhancements ------------------------------------
# Priority (1=high, 5=low, ?=unknown) is added, e.g. Prio(1)
This section outlines some ideas that came to my (juga) mind regarding the
filters, but are not necessarily going to be implemented. Just wanted to
write them down somewhere.
* Prio(1): Save filter-specific settings for user:
- Prio(1): visibility-state (like column-visibility)
- Prio(?): quote-type, quote-chars, range-sep, wildcard-char, range-sep-str{2}, relrange-str{2}
- Prio(?): FCONF_ShowToggleFilter/FilterTableHead
* Prio(?): new basic filter-syntax allowing to search for list of values
(if implemented need to be supported by StringTokenizer-class to be used
for numeric- and text-based filters):
- possible syntax: "val1, val2" use ',' as separator of values;
or more general provide list-separating-char(s) with filter-config:
FC_LISTSEP = ' ,;' for example
- corresponding SQL: field IN (val1, val2, ...)
- list-syntax mutually exclusive to range-syntax or wildcard-syntax
* Prio(?): Perform global checks on Filters before building query to be able
to avoid costly queries. Possible global restrictions could be:
- minimum set of used filter-values in fields (to be able to optimize search)
* Prio(?): new filter-config for text-based filters:
- see also FC_SUBSTRING
- FC_IMPLICIT_WILDCARD: 0(default) | 1
- filter on 'abc' -> would implicitly search for 'abc*'
* Prio(?): including additional help-reference to Help or FAQ-page
- maybe using new filter-config FC_HELP => faq_label
- could show up as '?' near input-element
* Prio(?): LINK_VALUE-feature for Tables with Filters:
An additional submit-button 'Link Navigation' could switch the displayed
values in a table to be equipped with links (or an additional link)
that would restrict the corresponding table-column to exactly that value
(use the clicked value as new value for a designated filter).
For example, the Games Handicap-column shows value '3'. Clicking on the
additional link would restrict the filter on the handicap-column to use
the '3' as new value.
Cool feature to quickly restrict a search to what you want, but may need
some deep changes:
- could be a table-feature, adding the | by Table-class (but then
need way to specify attributes to | )
- could be configured only for selected filters -> FC_LINK_VALUE-config
#-------- (7) Known Bugs ------------------------------------------------------
# Priority (1=high, 3=low, E=enhancement/feature) is added, e.g. Prio(1)
The listed problems in this section doesn't disturb the basic functioning
of the filter-framework, but are identified as bugs, though some could also
be considered a feature ;)
* Prio(E): Using Table with Filters: if user selects a new max-rows or select
a new column to add to table, also the "Start/Reset Search" submit-button
executes the according action (change max-rows or add-column).
=> the submit-buttons should only carry out "their" action
* Prio(E): If used without external-form, the submit-buttons "Start Search"
and "Reset Search" may disappear, when no filter is active and is shown in
Table-head.
|