DataFilter
Generating an ORM filter (or GetList-filter for the legacy api core). It is used in a configured filter for data retrieval and in the data uploader (iblock).
Method | Description | Available from version |
---|---|---|
construct | Class constructor | |
initFieldTypeHandlers | Service method completes the list of supported field types | |
addCheckboxValue | Converts checkbox value into the format bitrix:main.ui.filter. | |
addCustomDateValue | Converts date range into the format bitrix:main.ui.filter. | |
addDateValue | Converts date or date/time type value into the format bitrix:main.ui.filter. | |
addDestSelectorValue | Converts entity binding type value into the format bitrix:main.ui.filter. | |
addListValue | Converts list/multiple list type value into the format bitrix:main.ui.filter. | |
addNumberValue | Converts integer type into the format bitrix:main.ui.filter. | |
addStringValue | Converts string type into the format bitrix:main.ui.filter. |
Example
Converting block filter to ORM filter (also see example for user-defined source). Please be advised that the key 'operators' is indicated for the fields: nothing will work without it.
$fields = []; // NAME string field $fields['NAME'] = [ 'id' => 'NAME', // identifier (matches with array key) 'type' => 'string', // String field type (main.ui.filter) 'operators' => [ // prefixes for conditions 'default' => '%' // default prefix ] ]; // integer ID field $fields['ID'] = [ 'id' => 'ID', // identifier (matches with array key) 'type' => 'number', // Integer type field (main.ui.filter) 'operators' => [ // prefixes for conditions 'default' => '=', // default prefix 'exact' => '=', // precise match (equal) (X === value) 'range' => '><', // range filter (min <= X <= max) 'more' => '>', // higher (X > value) 'less' => '<' // lower (X < value) ] ]; // SECTION_ID list field $fields['SECTION_ID'] = [ 'id' => 'SECTION_ID', // identifier (matches with array key) 'type' => 'list', // List field (main.ui.filter) 'operators' => [ // prefixes for conditions 'default' => '=' // default prefix ] ]; // INCLUDE_SUBSECTIONS checkbox field $fields['INCLUDE_SUBSECTIONS'] = [ 'id' => 'INCLUDE_SUBSECTIONS', // identifier (matches with array key) 'type' => 'checkbox', Checkbox field type (main.ui.filter) 'operators' => [ // prefixes for conditions 'default' => '=' // default prefix ] ]; $sourceFilter = ... // gets block filter, see class description \Bitrix\Landing\Source\DataLoader and its descendants $filter = \Bitrix\Landing\Source\DataFilter(); $filter->setFields($filter); $ormFilter = $filter->create($sourceFilter); // filter for orm
© «Bitrix24», 2001-2024