Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow for types filter multiple values #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand All @@ -51,7 +51,7 @@ TODO: `defaults`: Default attributes or settings, as opposed to those submitted

# Example configuration

```
```yml
---
Name: search
Before:
Expand All @@ -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'
Expand Down
4 changes: 4 additions & 0 deletions src/SearchPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.')';
}
}
Expand Down