SavedSearchInspectorTrait
Trait for requiring a savedSearch as a param plus util functions for inspecting it.
Table of Contents
Properties
- $_apiParams : array{select: array, where: array, having: array, orderBy: array, limit: int, offset: int, checkPermissions: bool, debug: bool}
- $savedSearch : string|array<string|int, mixed>
- Either the name of the savedSearch or an array containing the savedSearch definition (for preview mode)
- $_joinMap : array<string|int, mixed>
- $_searchEntityFields : array<string|int, mixed>
- $_selectClause : array<string|int, mixed>
- $_selectQuery : Api4SelectQuery
Methods
- getSavedSearch() : array<string|int, mixed>|string
- getSelectClause() : array<string|int, SqlExpression, dataType: string}>
- Returns the select clause enhanced with metadata
- setSavedSearch() : $this
- applyFilter() : mixed
- checkPermissionToLoadSearch() : mixed
- Only SearchKit admins can use unsecured "preview mode" and pass an array for savedSearch or display
- getColumnLabel() : string
- getField() : array<string|int, mixed>|null
- Returns field definition for a given field or NULL if not found
- getJoin() : array{entity: string, alias: string, table: string, bridge: string|null}|null
- getJoinLabel() : string
- getJoins() : array<string|int, array{entity: string, alias: string, table: string, bridge: string|null}>
- getSelectExpression() : SqlExpression, dataType: string}|null
- getTokens() : array<string|int, mixed>
- Search a string for all square bracket tokens and return their contents (without the brackets)
- hasValue() : bool
- Checks if a filter contains a non-empty value
- loadSavedSearch() : mixed
- If SavedSearch is supplied as a string, this will load it as an array
- loadSearchDisplay() : void
- Loads display if not already an array
- canAggregate() : bool
- Determines if a column belongs to an aggregate grouping
- getEntityFields() : array<string|int, mixed>
- Used as a fallback for non-DAO entities which don't use the Query object
- getQuery() : Api4SelectQuery|bool
- Returns a Query object for the search entity, or FALSE if it doesn't have a DAO
- renameIfAggregate() : string
Properties
$_apiParams
protected
array{select: array, where: array, having: array, orderBy: array, limit: int, offset: int, checkPermissions: bool, debug: bool}
$_apiParams
$savedSearch
Either the name of the savedSearch or an array containing the savedSearch definition (for preview mode)
protected
string|array<string|int, mixed>
$savedSearch
Tags
$_joinMap
private
array<string|int, mixed>
$_joinMap
$_searchEntityFields
private
array<string|int, mixed>
$_searchEntityFields
$_selectClause
private
array<string|int, mixed>
$_selectClause
$_selectQuery
private
Api4SelectQuery
$_selectQuery
Methods
getSavedSearch()
public
getSavedSearch() : array<string|int, mixed>|string
Return values
array<string|int, mixed>|stringgetSelectClause()
Returns the select clause enhanced with metadata
public
getSelectClause() : array<string|int, SqlExpression, dataType: string}>
Return values
array<string|int, SqlExpression, dataType: string}>setSavedSearch()
public
setSavedSearch([array<string|int, mixed>|string $savedSearch = ]) : $this
Parameters
- $savedSearch : array<string|int, mixed>|string =
Return values
$thisapplyFilter()
protected
applyFilter(string|array<string|int, mixed> $fieldName, mixed $value) : mixed
Parameters
- $fieldName : string|array<string|int, mixed>
-
If multiple field names are given they will be combined in an OR clause
- $value : mixed
checkPermissionToLoadSearch()
Only SearchKit admins can use unsecured "preview mode" and pass an array for savedSearch or display
protected
checkPermissionToLoadSearch() : mixed
Tags
getColumnLabel()
protected
getColumnLabel(SqlExpression $expr) : string
Parameters
- $expr : SqlExpression
Return values
stringgetField()
Returns field definition for a given field or NULL if not found
protected
getField(mixed $fieldName) : array<string|int, mixed>|null
Parameters
- $fieldName : mixed
Return values
array<string|int, mixed>|nullgetJoin()
protected
getJoin(string $joinAlias) : array{entity: string, alias: string, table: string, bridge: string|null}|null
Parameters
- $joinAlias : string
-
Alias of the join, with or without the trailing dot
Return values
array{entity: string, alias: string, table: string, bridge: string|null}|nullgetJoinLabel()
protected
getJoinLabel(string $joinAlias) : string
Parameters
- $joinAlias : string
Return values
stringgetJoins()
protected
getJoins() : array<string|int, array{entity: string, alias: string, table: string, bridge: string|null}>
Return values
array<string|int, array{entity: string, alias: string, table: string, bridge: string|null}>getSelectExpression()
protected
getSelectExpression(string $key) : SqlExpression, dataType: string}|null
Parameters
- $key : string
Return values
SqlExpression, dataType: string}|nullgetTokens()
Search a string for all square bracket tokens and return their contents (without the brackets)
protected
getTokens(string $str) : array<string|int, mixed>
Parameters
- $str : string
Return values
array<string|int, mixed>hasValue()
Checks if a filter contains a non-empty value
protected
hasValue(mixed $value) : bool
"Empty" search values are [], '', and NULL. Also recursively checks arrays to ensure they contain at least one non-empty value.
Parameters
- $value : mixed
Return values
boolloadSavedSearch()
If SavedSearch is supplied as a string, this will load it as an array
protected
loadSavedSearch([int|null $id = NULL ]) : mixed
Parameters
- $id : int|null = NULL
Tags
loadSearchDisplay()
Loads display if not already an array
protected
loadSearchDisplay() : void
canAggregate()
Determines if a column belongs to an aggregate grouping
private
canAggregate(string $fieldPath) : bool
Parameters
- $fieldPath : string
Return values
boolgetEntityFields()
Used as a fallback for non-DAO entities which don't use the Query object
private
getEntityFields() : array<string|int, mixed>
Return values
array<string|int, mixed>getQuery()
Returns a Query object for the search entity, or FALSE if it doesn't have a DAO
private
getQuery() : Api4SelectQuery|bool
Return values
Api4SelectQuery|boolrenameIfAggregate()
private
renameIfAggregate(string $fieldPath[, bool $asSelect = FALSE ]) : string
Parameters
- $fieldPath : string
- $asSelect : bool = FALSE