PHP Class Search\Model\Behavior\SearchBehavior

Inheritance: extends Cake\ORM\Behavior
Show file Open project: friendsofcake/search

Public Properties

Property Type Description
$_manager Search\Manager Search Manager instance.

Protected Properties

Property Type Description
$_defaultConfig array ### Options - searchConfigMethod Method name of the method that returns the filters.
$_isSearch boolean Internal flag to check whether the behavior modified the query.

Public Methods

Method Description
filterParams ( array $params ) : array Returns search params nested in array with key _search for passing as options to find method.
findSearch ( Query $query, array $options ) : Query Callback fired from the controller.
isSearch ( ) : boolean Returns true if the findSearch call modified the query in a way that at least one search filter has been applied.
searchManager ( ) : Manager Returns the search filter manager.

Protected Methods

Method Description
_extractParams ( array $params, Base[] $filters ) : array Extracts all parameters for wich a filter with a matching field name exists.
_flattenParams ( array $params ) : array Flattens a parameters array, so that possible aliased parameter keys that are provided in a nested fashion, are being grouped using flat keys.
_getAllFilters ( string | null $collection = 'default' ) : Base[] Gets all filters by the default or given collection from the search manager
_processFilters ( Base[] $filters, array $params, Query $query ) : Query Processes the given filters.

Method Details

_extractParams() protected method

Extracts all parameters for wich a filter with a matching field name exists.
protected _extractParams ( array $params, Base[] $filters ) : array
$params array The parameters array to extract from.
$filters Search\Model\Filter\Base[] The filters to match against.
return array The extracted parameters.

_flattenParams() protected method

### Example: The following parameters array: [ 'Alias' => [ 'field' => 'value' 'otherField' => [ 'value', 'otherValue' ] ], 'field' => 'value' ] would return as [ 'Alias.field' => 'value', 'Alias.otherField' => [ 'value', 'otherValue' ], 'field' => 'value' ]
protected _flattenParams ( array $params ) : array
$params array The parameters array to flatten.
return array The flattened parameters array.

_getAllFilters() protected method

Gets all filters by the default or given collection from the search manager
protected _getAllFilters ( string | null $collection = 'default' ) : Base[]
$collection string | null name of collection
return Search\Model\Filter\Base[] An array of filters for the defined fields.

_processFilters() protected method

Processes the given filters.
protected _processFilters ( Base[] $filters, array $params, Query $query ) : Query
$filters Search\Model\Filter\Base[] The filters to process.
$params array The parameters to pass to the filters.
$query Cake\ORM\Query The query to pass to the filters.
return Cake\ORM\Query The query processed by the filters.

filterParams() public method

Returns search params nested in array with key _search for passing as options to find method.
Deprecation: 2.0.0 You can directly call find like `find('search', ['search' => $this->request->query])`
public filterParams ( array $params ) : array
$params array A key value list of search parameters to use for a search.
return array

findSearch() public method

Callback fired from the controller.
public findSearch ( Query $query, array $options ) : Query
$query Cake\ORM\Query Query.
$options array The options for the find. - `search`: Array of search arguments. - `collection`: Filter collection name.
return Cake\ORM\Query The Query object used in pagination.

isSearch() public method

Returns true if the findSearch call modified the query in a way that at least one search filter has been applied.
public isSearch ( ) : boolean
return boolean

searchManager() public method

Returns the search filter manager.
public searchManager ( ) : Manager
return Search\Manager

Property Details

$_defaultConfig protected property

### Options - searchConfigMethod Method name of the method that returns the filters.
protected array $_defaultConfig
return array

$_isSearch protected property

Internal flag to check whether the behavior modified the query.
protected bool $_isSearch
return boolean

$_manager public property

Search Manager instance.
public Manager,Search $_manager
return Search\Manager