class BasicSearchContext extends SearchContext (View source)

A SearchContext that can be used with non-ORM data.

This class isn't guaranteed to respect the full searchable fields spec defined on DataObject classes.

Traits

Provides extensions to this object to integrate it with standard config API methods.

A class that can be instantiated or replaced via DI

Config options

general_search_field_name

Name of the field which, if included in search forms passed to this object, will be used to search across all searchable fields.

Properties

protected T> $modelClass

DataObject subclass to which search parameters relate to.

from  SearchContext
protected FieldList $fields

FormFields mapping to DataObject::$db properties which are supposed to be searchable.

from  SearchContext
protected SearchFilter[] $filters

Array of SearchFilter subclasses.

from  SearchContext
protected array $searchParams

Key/value pairs of search fields to search terms

from  SearchContext

Methods

public static 
create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

public static 
singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

public
__construct(T> $modelClass, FieldList $fields = null, array $filters = null)

A key value pair of values that should be searched for.

public
getSearchFields()

Returns scaffolded search fields for UI.

protected
applyBaseTableFields()

No description

public
T>
getQuery(array $searchParams, array|bool|string $sort = false, int|array|null $limit = false, DataList $existingQuery = null)

Returns a list which has been limited, sorted, and filtered by the given parameters.

public
T>
getResults(array $searchParams, array|bool|string $sort = false, array|null|string $limit = null)

Returns a result set from the given search parameters.

public
bool
clearEmptySearchFields(mixed $value)

Callback map function to filter fields with empty values from being included in the search expression.

public
getFilter(string $name)

Accessor for the filter attached to a named field.

public
getFilters()

Get the map of filters in the current search context.

public
setFilters(SearchFilter[] $filters)

Overwrite the current search context filter map.

public
addFilter(SearchFilter $filter)

Adds a instance of SearchFilter.

public
removeFilterByName(string $name)

Removes a filter by name.

public
getFields()

Get the list of searchable fields in the current search context.

public
setFields(FieldList $fields)

Apply a list of searchable fields to the current search context.

public
addField(FormField $field)

Adds a new FormField instance.

public
removeFieldByName(string $fieldName)

Removes an existing formfield instance by its name.

public
$this
setSearchParams(array|HTTPRequest $searchParams)

Set search param values

public
array
getSearchParams()

No description

public
ArrayData>
getSummary()

Gets a list of what fields were searched and the values provided for each field. Returns an ArrayList of ArrayData, suitable for rendering on a template.

public static 
config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

public
mixed
uninherited(string $name)

Gets the uninherited value for the given config option

Details

static Injectable create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

This method will defer class substitution to the Injector API, which can be customised via the Config API to declare substitution classes.

This can be called in one of two ways - either calling via the class directly, or calling on Object and passing the class name as the first parameter. The following are equivalent: $list = DataList::create(SiteTree::class); $list = SiteTree::get();

Parameters

mixed ...$args

Return Value

Injectable

static Injectable singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

It will always return the same instance for this class, which can be used for performance reasons and as a simple way to access instance methods which don't rely on instance data (e.g. the custom SilverStripe static handling).

Parameters

string $class

Optional classname to create, if the called class should not be used

Return Value

Injectable

The singleton instance

__construct(T> $modelClass, FieldList $fields = null, array $filters = null)

A key value pair of values that should be searched for.

The keys should match the field names specified in SearchContext::$fields. Usually these values come from a submitted searchform in the form of a $_REQUEST object. CAUTION: All values should be treated as insecure client input.

Parameters

T> $modelClass

The base DataObject class that search properties related to. Also used to generate a set of result objects based on this class.

FieldList $fields

Optional. FormFields mapping to DataObject::$db properties which are to be searched. Derived from modelclass using DataObject::scaffoldSearchFields() if left blank.

array $filters

Optional. Derived from modelclass if left blank

FieldList getSearchFields()

Returns scaffolded search fields for UI.

Return Value

FieldList

protected applyBaseTableFields()

No description

T> getQuery(array $searchParams, array|bool|string $sort = false, int|array|null $limit = false, DataList $existingQuery = null)

Returns a list which has been limited, sorted, and filtered by the given parameters.

Parameters

array $searchParams

Map of search criteria, mostly taken from $_REQUEST. If a filter is applied to a relationship in dot notation, the parameter name should have the dots replaced with double underscores, for example "Comments__Name" instead of the filter name "Comments.Name".

array|bool|string $sort

Database column to sort on. Falls back to DataObject::$default_sort if not provided.

int|array|null $limit
DataList $existingQuery

Return Value

T>

T> getResults(array $searchParams, array|bool|string $sort = false, array|null|string $limit = null)

Returns a result set from the given search parameters.

Parameters

array $searchParams
array|bool|string $sort
array|null|string $limit

Return Value

T>

Exceptions

Exception

bool clearEmptySearchFields(mixed $value)

Callback map function to filter fields with empty values from being included in the search expression.

Parameters

mixed $value

Return Value

bool

SearchFilter|null getFilter(string $name)

Accessor for the filter attached to a named field.

Parameters

string $name

Return Value

SearchFilter|null

SearchFilter[] getFilters()

Get the map of filters in the current search context.

Return Value

SearchFilter[]

setFilters(SearchFilter[] $filters)

Overwrite the current search context filter map.

Parameters

SearchFilter[] $filters

addFilter(SearchFilter $filter)

Adds a instance of SearchFilter.

Parameters

SearchFilter $filter

removeFilterByName(string $name)

Removes a filter by name.

Parameters

string $name

FieldList getFields()

Get the list of searchable fields in the current search context.

Return Value

FieldList

setFields(FieldList $fields)

Apply a list of searchable fields to the current search context.

Parameters

FieldList $fields

addField(FormField $field)

Adds a new FormField instance.

Parameters

FormField $field

removeFieldByName(string $fieldName)

Removes an existing formfield instance by its name.

Parameters

string $fieldName

$this setSearchParams(array|HTTPRequest $searchParams)

Set search param values

Parameters

array|HTTPRequest $searchParams

Return Value

$this

array getSearchParams()

No description

Return Value

array

ArrayData> getSummary()

Gets a list of what fields were searched and the values provided for each field. Returns an ArrayList of ArrayData, suitable for rendering on a template.

Return Value

ArrayData>

static Config_ForClass config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

Return Value

Config_ForClass

mixed uninherited(string $name)

Gets the uninherited value for the given config option

Parameters

string $name

Return Value

mixed