UrlQueryHelper
in package
Class to help build URLs and forms in the view based on search settings.
Tags
Table of Contents
- $config : array<string|int, mixed>
- Configuration for this helper.
- $queryObject : AbstractQuery
- Current query object
- $urlParams : array<string|int, mixed>
- URL query parameters
- __construct() : mixed
- Constructor
- __toString() : string
- Magic method: behavior when this object is treated as a string.
- addFacet() : UrlQueryHelper
- Add a facet to the parameters.
- addFilter() : UrlQueryHelper
- Add a filter to the parameters.
- asHiddenFields() : string
- Turn the current GET parameters into a set of hidden form fields.
- buildQueryString() : string
- Turn an array into a properly URL-encoded query string. This is equivalent to the built-in PHP http_build_query function, but it handles arrays in a more compact way and ensures that ampersands don't get messed up based on server-specific settings.
- getParamArray() : array<string|int, mixed>
- Get an array of URL parameters.
- getParams() : string
- Get the current search parameters as a GET query.
- getParamsWithConfiguredDefaults() : array<string|int, mixed>
- Get an array of field names with configured defaults; this is a useful way to identify custom query parameters added through setDefaultParameter().
- isQuerySuppressed() : bool
- Is query suppressed?
- removeAllFilters() : UrlQueryHelper
- Remove all filters.
- removeFacet() : UrlQueryHelper
- Remove a facet from the parameters.
- removeFilter() : UrlQueryHelper
- Remove a filter from the parameters.
- replaceTerm() : UrlQueryHelper
- Replace a term in the search query (used for spelling replacement)
- resetDefaultFilters() : UrlQueryHelper
- Reset default filter state.
- setDefaultParameter() : UrlQueryHelper
- Set the default value of a parameter, and add that parameter to the object if it is not already defined.
- setHandler() : UrlQueryHelper
- Return HTTP parameters to render the current page with a different search handler.
- setJumpto() : UrlQueryHelper
- Return HTTP parameters to render the current page with a different jumpto parameter.
- setLimit() : UrlQueryHelper
- Return HTTP parameters to render the current page with a different limit parameter.
- setPage() : UrlQueryHelper
- Return HTTP parameters to render a different page of results.
- setSearchTerms() : UrlQueryHelper
- Return HTTP parameters to render the current page with a different set of search terms.
- setSort() : UrlQueryHelper
- Return HTTP parameters to render the current page with a different sort parameter.
- setSuppressQuery() : UrlQueryHelper
- Control query suppression
- setViewParam() : UrlQueryHelper
- Return HTTP parameters to render the current page with a different view parameter.
- clearSearchQueryParams() : void
- Reset search-related parameters in the internal array.
- filtered() : bool
- Support method for asHiddenFields -- are the provided field and value excluded by the provided filter?
- getAliasesForFacetField() : array<string|int, mixed>
- Given a facet field, return an array containing all aliases of that field.
- getBasicSearchParam() : string
- Get the name of the basic search param.
- getDefault() : mixed
- Look up a default value in the internal configuration array.
- parseFilter() : array<string|int, mixed>
- Parse apart the field and value from a URL filter string.
- regenerateSearchQueryParams() : void
- Adjust the internal query array based on the query object.
- updateQueryString() : UrlQueryHelper
- Generic case of parameter rebuilding.
Properties
$config
Configuration for this helper.
protected
array<string|int, mixed>
$config
$queryObject
Current query object
protected
AbstractQuery
$queryObject
$urlParams
URL query parameters
protected
array<string|int, mixed>
$urlParams
= []
Methods
__construct()
Constructor
public
final __construct(array<string|int, mixed> $urlParams, AbstractQuery $query[, array<string|int, mixed> $options = [] ][, bool $regenerateQueryParams = true ]) : mixed
Note that the constructor is final here, because this class relies on "new static()" to build instances, and we must ensure that child classes have consistent constructor signatures.
Parameters
- $urlParams : array<string|int, mixed>
-
Array of URL query parameters.
- $query : AbstractQuery
-
Query object to use to update URL query.
- $options : array<string|int, mixed> = []
-
Configuration options for the object.
- $regenerateQueryParams : bool = true
-
Should we add parameters based on the contents of $query to $urlParams (true) or are they already there (false)?
Return values
mixed —__toString()
Magic method: behavior when this object is treated as a string.
public
__toString() : string
Return values
string —addFacet()
Add a facet to the parameters.
public
addFacet(string $field, string $value[, string $operator = 'AND' ]) : UrlQueryHelper
Parameters
- $field : string
-
Facet field
- $value : string
-
Facet value
- $operator : string = 'AND'
-
Facet type to add (AND, OR, NOT)
Return values
UrlQueryHelper —addFilter()
Add a filter to the parameters.
public
addFilter(string $filter) : UrlQueryHelper
Parameters
- $filter : string
-
Filter to add
Return values
UrlQueryHelper —asHiddenFields()
Turn the current GET parameters into a set of hidden form fields.
public
asHiddenFields([array<string|int, mixed> $filter = [] ]) : string
Parameters
- $filter : array<string|int, mixed> = []
-
Array of parameters to exclude -- key = field name, value = regular expression to exclude.
Return values
string —buildQueryString()
Turn an array into a properly URL-encoded query string. This is equivalent to the built-in PHP http_build_query function, but it handles arrays in a more compact way and ensures that ampersands don't get messed up based on server-specific settings.
public
static buildQueryString(array<string|int, mixed> $a[, bool $escape = true ]) : string
Parameters
- $a : array<string|int, mixed>
-
Array of parameters to turn into a GET string
- $escape : bool = true
-
Should we escape the string for use in the view?
Return values
string —getParamArray()
Get an array of URL parameters.
public
getParamArray() : array<string|int, mixed>
Return values
array<string|int, mixed> —getParams()
Get the current search parameters as a GET query.
public
getParams([bool $escape = true ]) : string
Parameters
- $escape : bool = true
-
Should we escape the string for use in the view?
Return values
string —getParamsWithConfiguredDefaults()
Get an array of field names with configured defaults; this is a useful way to identify custom query parameters added through setDefaultParameter().
public
getParamsWithConfiguredDefaults() : array<string|int, mixed>
Return values
array<string|int, mixed> —isQuerySuppressed()
Is query suppressed?
public
isQuerySuppressed() : bool
Return values
bool —removeAllFilters()
Remove all filters.
public
removeAllFilters() : UrlQueryHelper
Return values
UrlQueryHelper —removeFacet()
Remove a facet from the parameters.
public
removeFacet(string $field, string $value[, string $operator = 'AND' ]) : UrlQueryHelper
Parameters
- $field : string
-
Facet field
- $value : string
-
Facet value
- $operator : string = 'AND'
-
Facet type to add (AND, OR, NOT)
Return values
UrlQueryHelper —removeFilter()
Remove a filter from the parameters.
public
removeFilter(string $filter) : UrlQueryHelper
Parameters
- $filter : string
-
Filter to add
Return values
UrlQueryHelper —replaceTerm()
Replace a term in the search query (used for spelling replacement)
public
replaceTerm(string $from, string $to[, callable $normalizer = null ]) : UrlQueryHelper
Parameters
- $from : string
-
Search term to find
- $to : string
-
Search term to insert
- $normalizer : callable = null
-
Function to normalize text strings (null for no normalization)
Return values
UrlQueryHelper —resetDefaultFilters()
Reset default filter state.
public
resetDefaultFilters() : UrlQueryHelper
Return values
UrlQueryHelper —setDefaultParameter()
Set the default value of a parameter, and add that parameter to the object if it is not already defined.
public
setDefaultParameter(string $name, string $value[, bool $forceOverride = false ]) : UrlQueryHelper
Parameters
- $name : string
-
Name of parameter
- $value : string
-
Value of parameter
- $forceOverride : bool = false
-
Force an override of the existing value, even if it was set in the incoming $urlParams in the constructor (defaults to false)
Return values
UrlQueryHelper —setHandler()
Return HTTP parameters to render the current page with a different search handler.
public
setHandler(string $handler) : UrlQueryHelper
Parameters
- $handler : string
-
new Handler.
Return values
UrlQueryHelper —setJumpto()
Return HTTP parameters to render the current page with a different jumpto parameter.
public
setJumpto(null|false|int $jumpto) : UrlQueryHelper
Parameters
- $jumpto : null|false|int
-
If results page is skipped when a search has only one hit
Return values
UrlQueryHelper —setLimit()
Return HTTP parameters to render the current page with a different limit parameter.
public
setLimit(string $l) : UrlQueryHelper
Parameters
- $l : string
-
New limit parameter (null for NO limit parameter)
Return values
UrlQueryHelper —setPage()
Return HTTP parameters to render a different page of results.
public
setPage(string $p) : UrlQueryHelper
Parameters
- $p : string
-
New page parameter (null for NO page parameter)
Return values
UrlQueryHelper —setSearchTerms()
Return HTTP parameters to render the current page with a different set of search terms.
public
setSearchTerms(string $lookfor) : UrlQueryHelper
Parameters
- $lookfor : string
-
New search terms
Return values
UrlQueryHelper —setSort()
Return HTTP parameters to render the current page with a different sort parameter.
public
setSort(string $s) : UrlQueryHelper
Parameters
- $s : string
-
New sort parameter (null for NO sort parameter)
Return values
UrlQueryHelper —setSuppressQuery()
Control query suppression
public
setSuppressQuery(bool $suppress) : UrlQueryHelper
Parameters
- $suppress : bool
-
Should we suppress queries?
Return values
UrlQueryHelper —setViewParam()
Return HTTP parameters to render the current page with a different view parameter.
public
setViewParam(string $v) : UrlQueryHelper
Note: This is called setViewParam rather than setView to avoid confusion with the \Laminas\View\Helper\AbstractHelper interface.
Parameters
- $v : string
-
New sort parameter (null for NO view parameter)
Return values
UrlQueryHelper —clearSearchQueryParams()
Reset search-related parameters in the internal array.
protected
clearSearchQueryParams() : void
Return values
void —filtered()
Support method for asHiddenFields -- are the provided field and value excluded by the provided filter?
protected
filtered(string $field, string $value, array<string|int, mixed> $filter) : bool
Parameters
- $field : string
-
Field to check
- $value : string
-
Regular expression to check
- $filter : array<string|int, mixed>
-
Filter provided to asHiddenFields() above
Return values
bool —getAliasesForFacetField()
Given a facet field, return an array containing all aliases of that field.
protected
getAliasesForFacetField(string $field) : array<string|int, mixed>
Parameters
- $field : string
-
Field to look up
Return values
array<string|int, mixed> —getBasicSearchParam()
Get the name of the basic search param.
protected
getBasicSearchParam() : string
Return values
string —getDefault()
Look up a default value in the internal configuration array.
protected
getDefault(string $key) : mixed
Parameters
- $key : string
-
Name of default to load
Return values
mixed —parseFilter()
Parse apart the field and value from a URL filter string.
protected
parseFilter(string $filter) : array<string|int, mixed>
Parameters
- $filter : string
-
A filter string from url : "field:value"
Return values
array<string|int, mixed> —Array with elements 0 = field, 1 = value.
regenerateSearchQueryParams()
Adjust the internal query array based on the query object.
protected
regenerateSearchQueryParams() : void
Return values
void —updateQueryString()
Generic case of parameter rebuilding.
protected
updateQueryString(string $field, string $value[, string $default = null ][, bool $clearPage = false ]) : UrlQueryHelper
Parameters
- $field : string
-
Field to update
- $value : string
-
Value to use (null to skip field entirely)
- $default : string = null
-
Default value (skip field if $value matches; null for no default).
- $clearPage : bool = false
-
Should we clear the page number, if any?