From 9d9608335303120bddea8dc1a95ed0a192ae6329 Mon Sep 17 00:00:00 2001 From: CSoellinger Date: Wed, 22 Mar 2023 14:48:52 +0100 Subject: [PATCH] feat: allow for types filter multiple values --- README.md | 6 ++++-- src/SearchPageController.php | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 53ef71a..c2b52e0 100755 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ The built-in SilverStripe search form is a very simple search engine. This plugi * `Table`: the object's primary table (note `_Live` suffix for versioned objects) * `ClassName`: full ClassName * `ClassNameShort`: namespaced ClassName - * `Filters`: a list of filters to apply pre-search (maps to `DataList->Filter(key => value)`) + * `Filters`: a list of filters to apply pre-search (maps to `DataList->Filter(key => value|value[])`) * `Columns`: columns to search for query string matches (format `Table.Column`) * `filters`: associative list of filter options * `Structure`: defines the filter's relational structure (must be one of `db`, `has_one` or `many_many`) @@ -51,7 +51,7 @@ TODO: `defaults`: Default attributes or settings, as opposed to those submitted # Example configuration -``` +```yml --- Name: search Before: @@ -67,6 +67,8 @@ PlasticStudio\Search\SearchPageController: Filters: File_Live.ShowInSearch: '1' File_Live.ClassName: '''Silverstripe\\Assets\\File''' # You need to TRIPLE-ESCAPE in order to pass this as a string to the query + # For images too.. + # File_Live.ClassName: ['''Silverstripe\\Assets\\File''', '''Silverstripe\\Assets\\Image'''] Columns: ['File_Live.Title','File_Live.Description','File_Live.Name'] pages: Label: 'Pages' diff --git a/src/SearchPageController.php b/src/SearchPageController.php index 688e6e7..1452f62 100755 --- a/src/SearchPageController.php +++ b/src/SearchPageController.php @@ -324,6 +324,10 @@ public function PerformSearch(){ **/ if (isset($type['Filters'])){ foreach ($type['Filters'] as $key => $value){ + if (is_array($value) === true) { + $where.= ' AND ('.$key.' IN ('.implode(',', $value).'))'; + continue; + } $where.= ' AND ('.$key.' = '.$value.')'; } }