FormattingUtil
in package
Table of Contents
Properties
- $pseudoConstantContexts : array<string|int, string>
Methods
- contactFieldsToRemove() : array<string|int, mixed>
- Lists all field names (including suffixed variants) that should be removed for a given contact type.
- convertDataType() : mixed
- filterByPath() : array<string|int, mixed>
- Given a field belonging to either the main entity or a joined entity, and a values array of [path => value], this returns all values which share the same root path.
- formatDateValue() : array<string|int, mixed>|string
- Parse date expressions.
- formatInputValue() : mixed
- Transform raw api input to appropriate format for use in a SQL query.
- formatOutputValues() : mixed
- Unserialize raw DAO values and convert to correct type
- formatWriteParams() : mixed
- Massage values into the format the BAO expects for a write operation
- getFieldOptions() : void
- Get options associated with an entity field
- getPseudoconstantList() : array<string|int, mixed>
- Retrieves pseudoconstant option list for a field.
- replacePseudoconstant() : array<string|int, mixed>|mixed|null
- Replaces value (or an array of values) with options from a pseudoconstant list.
- resolveContactID() : int|null
- A contact ID field passed in to the API may contain values such as "user_contact_id" which need to be resolved to the actual contact ID.
- applyFormatter() : void
- applyFormatters() : void
- Apply a field's output_formatters callback functions
Properties
$pseudoConstantContexts
public
static array<string|int, string>
$pseudoConstantContexts
= ['name' => 'validate', 'abbr' => 'abbreviate', 'label' => 'get']
Methods
contactFieldsToRemove()
Lists all field names (including suffixed variants) that should be removed for a given contact type.
public
static contactFieldsToRemove(string $contactType, string $prefix) : array<string|int, mixed>
Parameters
- $contactType : string
-
Individual|Organization|Household
- $prefix : string
-
Path at which these fields are found, e.g. "address.contact."
Return values
array<string|int, mixed>convertDataType()
public
static convertDataType(mixed $value, string $dataType) : mixed
Parameters
- $value : mixed
- $dataType : string
filterByPath()
Given a field belonging to either the main entity or a joined entity, and a values array of [path => value], this returns all values which share the same root path.
public
static filterByPath(array<string|int, mixed> $values, string $fieldPath, string $fieldName) : array<string|int, mixed>
Note: Unlike CRM_Utils_Array::filterByPrefix this does not mutate the original array.
Ex:
$values = [
'first_name' => 'a',
'middle_name' => 'b',
'related_contact.first_name' => 'c',
'related_contact.last_name' => 'd',
'activity.subject' => 'e',
]
$fieldPath = 'related_contact.id'
$fieldName = 'id'
filterByPrefix($values, $fieldPath, $fieldName)
returns [
'first_name' => 'c',
'last_name' => 'd',
]
Parameters
- $values : array<string|int, mixed>
- $fieldPath : string
- $fieldName : string
Return values
array<string|int, mixed>formatDateValue()
Parse date expressions.
public
static formatDateValue(mixed $format, mixed $value[, mixed &$operator = NULL ][, mixed $index = NULL ]) : array<string|int, mixed>|string
Expands relative date range expressions, modifying the sql operator if necessary
Parameters
- $format : mixed
- $value : mixed
- $operator : mixed = NULL
- $index : mixed = NULL
Return values
array<string|int, mixed>|stringformatInputValue()
Transform raw api input to appropriate format for use in a SQL query.
public
static formatInputValue(mixed &$value, string|null $fieldPath, array<string|int, mixed> $fieldSpec[, array<string|int, mixed> $params = [] ][, string|null &$operator = NULL ][, null $index = NULL ]) : mixed
This is used by read AND write actions (Get, Create, Update, Replace)
Parameters
- $value : mixed
- $fieldPath : string|null
- $fieldSpec : array<string|int, mixed>
- $params : array<string|int, mixed> = []
- $operator : string|null = NULL
-
(only for 'get' actions)
- $index : null = NULL
-
(for recursive loops)
Tags
formatOutputValues()
Unserialize raw DAO values and convert to correct type
public
static formatOutputValues(array<string|int, mixed> &$result, array<string|int, mixed> $fields[, string $action = 'get' ][, array<string|int, mixed> $selectAliases = [] ]) : mixed
Parameters
- $result : array<string|int, mixed>
- $fields : array<string|int, mixed>
- $action : string = 'get'
- $selectAliases : array<string|int, mixed> = []
Tags
formatWriteParams()
Massage values into the format the BAO expects for a write operation
public
static formatWriteParams(array<string|int, mixed> &$params, array<string|int, mixed> $fields) : mixed
Parameters
- $params : array<string|int, mixed>
- $fields : array<string|int, mixed>
Tags
getFieldOptions()
Get options associated with an entity field
public
static getFieldOptions(array<string|int, mixed> $field[, array<string|int, mixed> $values = [] ][, bool $includeDisabled = FALSE ][, bool $checkPermissions = FALSE ][, int|null $userId = NULL ]) : void
Parameters
- $field : array<string|int, mixed>
- $values : array<string|int, mixed> = []
- $includeDisabled : bool = FALSE
- $checkPermissions : bool = FALSE
- $userId : int|null = NULL
Tags
getPseudoconstantList()
Retrieves pseudoconstant option list for a field.
public
static getPseudoconstantList(array<string|int, mixed> $field, string $fieldAlias[, array<string|int, mixed> $values = [] ][, string $action = 'get' ]) : array<string|int, mixed>
Parameters
- $field : array<string|int, mixed>
- $fieldAlias : string
-
Field path plus pseudoconstant suffix, e.g. 'contact.employer_id.contact_sub_type:label'
- $values : array<string|int, mixed> = []
-
Other values for this object
- $action : string = 'get'
Tags
Return values
array<string|int, mixed>replacePseudoconstant()
Replaces value (or an array of values) with options from a pseudoconstant list.
public
static replacePseudoconstant(array<string|int, mixed> $options, string|array<string|int, string> $value[, bool $reverse = FALSE ]) : array<string|int, mixed>|mixed|null
The direction of lookup defaults to transforming ids to option values for api output; for api input, set $reverse = TRUE to transform option values to ids.
Parameters
- $options : array<string|int, mixed>
- $value : string|array<string|int, string>
- $reverse : bool = FALSE
-
Is this a reverse lookup (for transforming input instead of output)
Return values
array<string|int, mixed>|mixed|nullresolveContactID()
A contact ID field passed in to the API may contain values such as "user_contact_id" which need to be resolved to the actual contact ID.
public
static resolveContactID(string $fieldName, string|int|null $fieldValue) : int|null
This function resolves those strings to the actual contact ID or throws an exception on "unknown user"
Parameters
- $fieldName : string
- $fieldValue : string|int|null
Tags
Return values
int|nullapplyFormatter()
private
static applyFormatter(array<string|int, mixed> $fieldDefn, array<string|int, mixed> $row, mixed &$value) : void
Parameters
- $fieldDefn : array<string|int, mixed>
- $row : array<string|int, mixed>
- $value : mixed
applyFormatters()
Apply a field's output_formatters callback functions
private
static applyFormatters(array<string|int, mixed> $result, SqlExpression $fieldExpr, array<string|int, mixed> $fieldDefn, mixed &$value) : void
Parameters
- $result : array<string|int, mixed>
- $fieldExpr : SqlExpression
- $fieldDefn : array<string|int, mixed>
- $value : mixed