qgisExpressionUtils
in package
Tags
Table of Contents
Methods
- evaluateExpressions() : null|object
- Request QGIS Server and the lizmap plugin to evaluate QGIS expressions.
- evaluateGroupVisibilities() : array<string|int, mixed>
- Return form group visibilities.
- expressionErrorMessage() : string
- Build the message shown to the user for an expression error.
- getCriteriaFromExpression() : array<string|int, mixed>
- Returns criteria dependencies (fields) for a QGIS expression.
- getCriteriaFromExpressions() : array<string|int, mixed>
- Returns criteria dependencies (fields) for QGIS expressions.
- getCurrentValueCriteriaFromExpression() : array<string|int, mixed>
- Returns criteria dependencies (fields) in current_value() for QGIS expression.
- getExpressionByUser() : string
- Returns the expression used to filter by login the layer.
- getFeatureWithFormScope() : array<string|int, mixed>
- Request QGIS Server to provide features with a form scope used for drilling down select.
- hasCurrentGeometry() : bool
- Returns true if @current_geometry is in the QGIS expression.
- logReplaceExpressionTextErrors() : array<string, string>
- Log the expressions in error of a replace expression text response, and remove them.
- replaceAtlasVariables() : string
- Replace the atlas variables of a QGIS expression for a single atlas feature.
- replaceExpressionText() : null|object
- Request QGIS Server and the lizmap plugin to replace QGIS expressions text.
- updateExpressionByUser() : string
- Returns the expression updated if filter by login is applied for the layer.
- virtualFields() : null|array<string|int, mixed>
- Request QGIS Server and the lizmap plugin calculate virtual fields for the features of a given vector layer.
- request() : null|object
- Performing the request to QGIS Server.
Methods
evaluateExpressions()
Request QGIS Server and the lizmap plugin to evaluate QGIS expressions.
public
static evaluateExpressions(qgisVectorLayer $layer, array<string|int, mixed> $expressions[, array<string|int, mixed> $form_feature = null ]) : null|object
Parameters
- $layer : qgisVectorLayer
-
A QGIS vector layer
- $expressions : array<string|int, mixed>
-
The expressions' list to evaluate
- $form_feature : array<string|int, mixed> = null
-
A feature to add to the evaluation context
Return values
null|object —the results of expressions' evaluation
evaluateGroupVisibilities()
Return form group visibilities.
public
static evaluateGroupVisibilities(qgisAttributeEditorElement $attributeEditorForm, jFormsBase $form) : array<string|int, mixed>
Parameters
- $attributeEditorForm : qgisAttributeEditorElement
- $form : jFormsBase
Return values
array<string|int, mixed> —visibilities, an associated array with group html id as key and boolean as value
expressionErrorMessage()
Build the message shown to the user for an expression error.
public
static expressionErrorMessage(AppContextInterface $appContext, string $localeKey, string $label, string $error) : string
The administrators and the publishers (rights to update the repositories or to view the projects list in the administration) get the error message. The other users get a generic message, asking them to contact the administrator.
Parameters
- $appContext : AppContextInterface
-
The application context, to check the rights
- $localeKey : string
-
The locale key of the generic message, with the label as variable. The detailed message key adds the ".details" suffix and the error
- $label : string
-
The label of what could not be computed, e.g. a form widget
- $error : string
-
The error message
Return values
string —the message for the current user
getCriteriaFromExpression()
Returns criteria dependencies (fields) for a QGIS expression.
public
static getCriteriaFromExpression(string $exp) : array<string|int, mixed>
Parameters
- $exp : string
-
A QGIS expression string
Return values
array<string|int, mixed> —The list of criteria dependencies
getCriteriaFromExpressions()
Returns criteria dependencies (fields) for QGIS expressions.
public
static getCriteriaFromExpressions(array<string|int, mixed> $expressions) : array<string|int, mixed>
Parameters
- $expressions : array<string|int, mixed>
-
list of QGIS expressions
Return values
array<string|int, mixed> —The list of criteria dependencies
getCurrentValueCriteriaFromExpression()
Returns criteria dependencies (fields) in current_value() for QGIS expression.
public
static getCurrentValueCriteriaFromExpression(string $exp) : array<string|int, mixed>
Parameters
- $exp : string
-
A QGIS expression string
Return values
array<string|int, mixed> —The list of criteria dependencies
getExpressionByUser()
Returns the expression used to filter by login the layer.
public
static getExpressionByUser(qgisVectorLayer $layer[, bool $edition = false ]) : string
This method combines the attribute and the spatial filter expressions.
Parameters
- $layer : qgisVectorLayer
-
A QGIS vector layer
- $edition : bool = false
-
It's for editing
Return values
string —the expression to filter by login the layer
getFeatureWithFormScope()
Request QGIS Server to provide features with a form scope used for drilling down select.
public
static getFeatureWithFormScope(qgisVectorLayer $layer, mixed $expression, array<string|int, mixed> $form_feature, array<string|int, mixed> $fields[, bool $edition = false ]) : array<string|int, mixed>
Parameters
- $layer : qgisVectorLayer
-
A QGIS vector layer
- $expression : mixed
- $form_feature : array<string|int, mixed>
-
The feature in the form
- $fields : array<string|int, mixed>
-
List of requested fields
- $edition : bool = false
-
It's for edition
Return values
array<string|int, mixed> —the features filtered with a form scope
hasCurrentGeometry()
Returns true if @current_geometry is in the QGIS expression.
public
static hasCurrentGeometry(string $exp) : bool
Parameters
- $exp : string
-
A QGIS expression string
Return values
bool —@current_geometry is in the QGIS expression
logReplaceExpressionTextErrors()
Log the expressions in error of a replace expression text response, and remove them.
public
static logReplaceExpressionTextErrors(object $json, string $layerInfo, AppContextInterface $appContext) : array<string, string>
Since lizmap_server 2.16, the response has a status, "success" or "partial", and the list of the expressions in error, whose strings are null in the results. The status and the errors are removed from the response, so that it is the same, whatever the version of the plugin.
Parameters
- $json : object
-
The GeoJSON response of the replace expression text request
- $layerInfo : string
-
The layer and the project, for the log message
- $appContext : AppContextInterface
-
The application context, to log the errors
Return values
array<string, string> —the first error message of each string in error, by key
replaceAtlasVariables()
Replace the atlas variables of a QGIS expression for a single atlas feature.
public
static replaceAtlasVariables(string $expression, string $pageNameExpression, string $layerId, string $layerName) : string
The lizmap plugin evaluates expressions with the feature in the context but without the atlas scope, so the atlas variables are replaced by their equivalents for an atlas of one feature. Text in string literals and quoted field names is kept as is.
Parameters
- $expression : string
-
A QGIS expression using atlas variables
- $pageNameExpression : string
-
The atlas page name expression
- $layerId : string
-
The atlas coverage layer id
- $layerName : string
-
The atlas coverage layer name
Return values
string —The expression without atlas variables
replaceExpressionText()
Request QGIS Server and the lizmap plugin to replace QGIS expressions text.
public
static replaceExpressionText(qgisVectorLayer $layer, array<string|int, mixed> $expressions[, array<string|int, mixed> $form_feature = null ][, null|array<string, string> &$errors = null ]) : null|object
The strings with an expression in error are null, and the errors are listed in the response: they are logged for the administrator, returned in $errors and removed from the returned GeoJSON, as an older plugin does not send them.
Parameters
- $layer : qgisVectorLayer
-
A QGIS vector layer
- $expressions : array<string|int, mixed>
-
The expressions text to replace
- $form_feature : array<string|int, mixed> = null
-
A feature to add to the evaluation context
- $errors : null|array<string, string> = null
-
Filled with the error message of each string in error
Return values
null|object —the results of expressions text replacement, null on error
updateExpressionByUser()
Returns the expression updated if filter by login is applied for the layer.
public
static updateExpressionByUser(qgisVectorLayer $layer, string $expression[, bool $edition = false ]) : string
Parameters
- $layer : qgisVectorLayer
-
A QGIS vector layer
- $expression : string
-
The expression to update
- $edition : bool = false
-
It's for edition
Return values
string —the expression updated or not
virtualFields()
Request QGIS Server and the lizmap plugin calculate virtual fields for the features of a given vector layer.
public
static virtualFields(qgisVectorLayer $layer, array<string|int, mixed> $virtualFields[, string $filter = null ][, string $withGeometry = 'true' ][, string $fields = '' ][, int $limit = 1000 ][, null|string $sortingField = null ][, null|string $sortingOrder = 'asc' ][, null|array<string|int, mixed> $safeVirtualFields = null ]) : null|array<string|int, mixed>
A filter can be used to retrieve the virtual fields values only for a subset of features.
Parameters
- $layer : qgisVectorLayer
-
A QGIS vector layer
- $virtualFields : array<string|int, mixed>
-
The expressions' list to evaluate as key
- $filter : string = null
-
A filter to restrict virtual fields creation
- $withGeometry : string = 'true'
-
'true' to get geometries of features
- $fields : string = ''
-
A list of field names separated by comma. E.g. 'name,code'
- $limit : int = 1000
-
The maximum number of features to return
- $sortingField : null|string = null
-
The field to sort by E.g. 'desc'
- $sortingOrder : null|string = 'asc'
-
The order to sort by E.g. 'name'
- $safeVirtualFields : null|array<string|int, mixed> = null
-
List of expressions to be evaluated carefully
Return values
null|array<string|int, mixed> —the features with virtual fields
request()
Performing the request to QGIS Server.
protected
static request(array<string|int, mixed> $params, Project $project) : null|object
Parameters
- $params : array<string|int, mixed>
- $project : Project
Return values
null|object —The response content or null