Get
extends DAOGetAction
in package
uses
CustomValueActionTrait
Get fields for a custom group.
Table of Contents
Properties
- $_debugOutput : mixed
- $_actionName : string
- $_entityName : string
- $chain : array<string|int, mixed>
- Additional api requests - will be called once per result.
- $checkPermissions : bool
- Whether to enforce acl permissions based on the current user.
- $debug : bool
- Add debugging info to the api result.
- $groupBy : array<string|int, mixed>
- Field(s) by which to group the results.
- $having : array<string|int, mixed>
- Clause for filtering results after grouping and filters are applied.
- $join : array<string|int, mixed>
- Joins to other entities.
- $language : string
- Preferred language (optional)
- $limit : int
- Maximum number of $ENTITIES to return.
- $offset : int
- Zero-based index of first $ENTITY to return.
- $orderBy : array<string|int, mixed>
- Array of field(s) to use in ordering the results.
- $select : array<string|int, mixed>
- Fields to return. Defaults to all standard (non-custom, non-extra) fields `['*']`.
- $translationMode : string|null
- Should we automatically overload the result with translated data? How do we pick the suitable translation?
- $version : int
- Api version number; cannot be changed.
- $where : array<string|int, mixed>
- Criteria for selecting $ENTITIES.
- $_arrayStorage : array<string|int, mixed>
- $_entityFields : array<string|int, mixed>
- $_id : int
- $_maxWeights : array<string|int, mixed>
- $_paramInfo : array<string|int, mixed>
- $_reflection : ReflectionClass
- $customGroup : string
- Custom Group name if this is a CustomValue pseudo-entity.
Methods
- __call() : static|mixed
- Magic function to provide automatic getter/setter for params.
- __construct() : mixed
- __set() : mixed
- Strictly enforce api parameters
- _run() : mixed
- addChain() : $this
- addClause() : $this
- Adds one or more AND/OR/NOT clause groups
- addGroupBy() : $this
- addHaving() : $this
- addJoin() : DAOGetAction
- addOrderBy() : $this
- Adds to the orderBy clause
- addSelect() : $this
- Add one or more fields to be selected (wildcard * allowed)
- addWhere() : $this
- baoToArray() : array<string|int, mixed>
- Convert saved object to array
- entityFields() : array<string|int, mixed>
- Returns schema fields for this entity & action.
- evaluateCondition() : bool
- This function is used internally for evaluating field annotations.
- execute() : Result
- Invoke api call.
- expandSelectClauseWildcards() : mixed
- Adds all standard fields matched by the * wildcard
- getActionName() : string
- getChain() : array<string|int, mixed>
- getCheckPermissions() : bool
- getCustomGroup() : string
- getDebug() : bool
- getEntityName() : mixed
- getJoin() : array<string|int, mixed>
- getLanguage() : string|null
- getLimit() : int
- getOffset() : int
- getOrderBy() : array<string|int, mixed>
- getParamInfo() : array<string|int, mixed>
- Get documentation for one or all params
- getParams() : array<string|int, mixed>
- Serialize this object's params into an array
- getPermissions() : array<string|int, mixed>
- getTranslationMode() : string|null
- getWhere() : array<string|int, mixed>
- isAuthorized() : bool
- Is this api call permitted?
- offsetExists() : bool
- offsetGet() : mixed
- offsetSet() : void
- offsetUnset() : void
- paramExists() : bool
- reflect() : ReflectionClass
- selectRowCount() : $this
- Only return the number of found items.
- setChain() : $this
- setCheckPermissions() : $this
- setDebug() : $this
- setDefaultWhereClause() : mixed
- Adds field defaults to the where clause.
- setJoin() : DAOGetAction
- setLanguage() : $this
- setLimit() : $this
- setOffset() : $this
- setOrderBy() : $this
- setTranslationMode() : $this
- setVersion() : $this
- setWhere() : $this
- _isFieldSelected() : bool
- Helper to see if field(s) should be selected by the getRecords function.
- _itemsToGet() : array<string|int, mixed>|null
- Helper to parse the WHERE param for getRecords to perform simple pre-filtering.
- _whereContains() : bool
- Walk through the where clause and check if field(s) are in use.
- addCallbackToDebugOutput() : mixed
- When in debug mode, this logs the callback function being used by a Basic*Action class.
- checkRequiredFields() : array<string|int, mixed>
- Validates required fields for actions which create a new object.
- deleteObjects() : mixed
- fillDefaults() : mixed
- formatCustomParams() : mixed
- Converts params from flat array e.g. ['GroupName.Fieldname' => value] to the hierarchy expected by the BAO, nested within $params['custom'].
- formatWriteValues() : mixed
- getBaoName() : CRM_Core_DAO|string
- getCustomFieldInfo() : array{id: int, name: string, entity: string, suffix: string, html_type: string, data_type: string, extends: string, table_name: string}|null
- Gets field info needed to save custom data
- getLanguageOptions() : array<string|int, mixed>
- Get available preferred languages.
- getMagicProperties() : array<string|int, mixed>
- Get a list of class properties for which magic methods are supported.
- getObjects() : mixed
- getParamDefaults() : array<string|int, mixed>
- resolveFKValues() : void
- Looks up an id based on some other property of an fk entity
- updateWeight() : mixed
- Update weights when inserting or updating a sortable entity
- whereClauseToString() : string
- Produces a human-readable where clause, for the reading enjoyment of you humans.
- write() : array<string|int, CRM_Core_DAO>
- Overrideable function to save items using the appropriate BAO function
- writeObjects() : mixed
- getMaxWeight() : int|mixed
- Looks up max weight for a set of sortable entities
Properties
$_debugOutput
public
mixed
$_debugOutput
= []
$_actionName
protected
string
$_actionName
$_entityName
protected
string
$_entityName
$chain
Additional api requests - will be called once per result.
protected
array<string|int, mixed>
$chain
= []
Keys can be any string - this will be the name given to the output.
You can reference other values in the api results in this call by prefixing them with $
.
For example, you could create a contact and place them in a group by chaining the
GroupContact
api to the Contact
api:
Contact::create()
->setValue('first_name', 'Hello')
->addChain('add_a_group', GroupContact::create()
->setValue('contact_id', '$id')
->setValue('group_id', 123)
)
This will substitute the id of the newly created contact with $id
.
$checkPermissions
Whether to enforce acl permissions based on the current user.
protected
bool
$checkPermissions
= TRUE
Setting to FALSE will disable permission checks and override ACLs. In REST/javascript this cannot be disabled.
$debug
Add debugging info to the api result.
protected
bool
$debug
= FALSE
When enabled, $result->debug
will be populated with information about the api call,
including sql queries executed.
Note: with checkPermissions enabled, debug info will only be returned if the user has "view debug output" permission.
$groupBy
Field(s) by which to group the results.
protected
array<string|int, mixed>
$groupBy
= []
$having
Clause for filtering results after grouping and filters are applied.
protected
array<string|int, mixed>
$having
= []
Each expression should correspond to an item from the SELECT array.
$join
Joins to other entities.
protected
array<string|int, mixed>
$join
= []
Each join is an array of properties:
[Entity, Required, Bridge, [field, op, value]...]
-
Entity
: the name of the api entity to join onto. -
Required
:TRUE
for anINNER JOIN
,FALSE
for aLEFT JOIN
. -
Bridge
(optional): Name of a Bridge to incorporate into the join. -
[field, op, value]...
: zero or more conditions for the ON clause, using the same nested format as WHERE and HAVING but with the difference that "value" is interpreted as an expression (e.g. can be the name of a field). Enclose literal values with quotes.
Tags
$language
Preferred language (optional)
protected
string
$language
This option will notify major localization subsystems (ts()
, multilingual, etc)
about which locale should be used for composing/formatting messaging.
This indicates the preferred language. The effective language is determined
by Civi\Core\Locale::negotiate($preferredLanguage)
.
Tags
$limit
Maximum number of $ENTITIES to return.
protected
int
$limit
= 0
Defaults to 0
- unlimited.
Note: the Api Explorer sets this to 25
by default to avoid timeouts.
Change or remove this default for your application code.
$offset
Zero-based index of first $ENTITY to return.
protected
int
$offset
= 0
Defaults to 0
- first $ENTITY found.
$orderBy
Array of field(s) to use in ordering the results.
protected
array<string|int, mixed>
$orderBy
= []
Defaults to id ASC
$example->addOrderBy('sort_name', 'ASC')
$select
Fields to return. Defaults to all standard (non-custom, non-extra) fields `['*']`.
protected
array<string|int, mixed>
$select
= []
The keyword "custom.*"
selects all custom fields (except those belonging to multi-record custom field sets). So to select all standard + custom fields, select ['*', 'custom.*']
.
Multi-record custom field sets are represented as their own entity, so join to that entity to get those custom fields.
Use the dot notation to perform joins in the select clause, e.g. selecting ['*', 'contact.*']
from Email::get()
will select all fields for the email + all fields for the related contact.
Tags
$translationMode
Should we automatically overload the result with translated data? How do we pick the suitable translation?
protected
string|null
$translationMode
Tags
$version
Api version number; cannot be changed.
protected
int
$version
= 4
$where
Criteria for selecting $ENTITIES.
protected
array<string|int, mixed>
$where
= []
$example->addWhere('contact_type', 'IN', ['Individual', 'Household'])
$_arrayStorage
private
array<string|int, mixed>
$_arrayStorage
= []
$_entityFields
private
array<string|int, mixed>
$_entityFields
$_id
private
int
$_id
Used to identify api calls for transactions
Tags
$_maxWeights
private
array<string|int, mixed>
$_maxWeights
= []
$_paramInfo
private
array<string|int, mixed>
$_paramInfo
$_reflection
private
ReflectionClass
$_reflection
$customGroup
Custom Group name if this is a CustomValue pseudo-entity.
private
string
$customGroup
Methods
__call()
Magic function to provide automatic getter/setter for params.
public
__call(mixed $name, mixed $arguments) : static|mixed
Parameters
- $name : mixed
- $arguments : mixed
Tags
Return values
static|mixed__construct()
public
__construct(mixed $customGroup, mixed $actionName) : mixed
Parameters
- $customGroup : mixed
- $actionName : mixed
__set()
Strictly enforce api parameters
public
__set(mixed $name, mixed $value) : mixed
Parameters
- $name : mixed
- $value : mixed
Tags
_run()
public
_run(Result $result) : mixed
Parameters
- $result : Result
Tags
addChain()
public
addChain(string $name, AbstractAction $apiRequest[, string|int|array<string|int, mixed> $index = NULL ]) : $this
Parameters
- $name : string
-
Unique name for this chained request
- $apiRequest : AbstractAction
- $index : string|int|array<string|int, mixed> = NULL
-
See
civicrm_api4()
for documentation of$index
param
Return values
$thisaddClause()
Adds one or more AND/OR/NOT clause groups
public
addClause(string $operator, mixed $condition1) : $this
Parameters
- $operator : string
- $condition1 : mixed
-
... $conditionN Either a nested array of arguments, or a variable number of arguments passed to this function.
Tags
Return values
$thisaddGroupBy()
public
addGroupBy(string $field) : $this
Parameters
- $field : string
Return values
$thisaddHaving()
public
addHaving(string $expr, string $op[, mixed $value = NULL ][, bool $isExpression = FALSE ]) : $this
Parameters
- $expr : string
- $op : string
- $value : mixed = NULL
- $isExpression : bool = FALSE
Tags
Return values
$thisaddJoin()
public
addJoin(string $entity[, string|bool $type = 'LEFT' ][, string $bridge = NULL ], array<string|int, mixed> ...$conditions) : DAOGetAction
Parameters
- $entity : string
-
Name of api entity to join with
- $type : string|bool = 'LEFT'
-
Should be 'LEFT' or 'INNER' (bool preserved for legacy support)
- $bridge : string = NULL
-
Optional name of bridge entity. This can be omitted, as a 3rd argument to the function would be interpreted as the first condition.
- $conditions : array<string|int, mixed>
-
One or more conditions, each condition is an array like ['field', '=', 'expr']
Return values
DAOGetActionaddOrderBy()
Adds to the orderBy clause
public
addOrderBy(string $fieldName[, string $direction = 'ASC' ]) : $this
Parameters
- $fieldName : string
- $direction : string = 'ASC'
Return values
$thisaddSelect()
Add one or more fields to be selected (wildcard * allowed)
public
addSelect(string ...$fieldNames) : $this
Parameters
- $fieldNames : string
Return values
$thisaddWhere()
public
addWhere(string $fieldName, string $op[, mixed $value = NULL ][, bool $isExpression = FALSE ]) : $this
Parameters
- $fieldName : string
- $op : string
- $value : mixed = NULL
- $isExpression : bool = FALSE
Tags
Return values
$thisbaoToArray()
Convert saved object to array
public
baoToArray(CRM_Core_DAO $bao, array<string|int, mixed> $input) : array<string|int, mixed>
Used by create, update & save actions
Parameters
- $bao : CRM_Core_DAO
- $input : array<string|int, mixed>
Return values
array<string|int, mixed>entityFields()
Returns schema fields for this entity & action.
public
entityFields() : array<string|int, mixed>
Here we bypass the api wrapper and run the getFields action directly. This is because we DON'T want the wrapper to check permissions as this is an internal op.
Tags
Return values
array<string|int, mixed>evaluateCondition()
This function is used internally for evaluating field annotations.
public
static evaluateCondition(string $expr, array<string|int, mixed> $vars) : bool
It should never be passed raw user input.
Parameters
- $expr : string
-
Conditional in php format e.g. $foo > $bar
- $vars : array<string|int, mixed>
-
Variable name => value
Tags
Return values
boolexecute()
Invoke api call.
public
execute() : Result
At this point all the params have been sent in and we initiate the api call & return the result. This is basically the outer wrapper for api v4.
Tags
Return values
ResultexpandSelectClauseWildcards()
Adds all standard fields matched by the * wildcard
public
expandSelectClauseWildcards() : mixed
Note: this function only deals with simple wildcard expressions. It ignores those containing special characters like dots or parentheses, they are handled separately in Api4SelectQuery.
Tags
getActionName()
public
getActionName() : string
Return values
stringgetChain()
public
getChain() : array<string|int, mixed>
Return values
array<string|int, mixed>getCheckPermissions()
public
getCheckPermissions() : bool
Return values
boolgetCustomGroup()
public
getCustomGroup() : string
Return values
stringgetDebug()
public
getDebug() : bool
Return values
boolgetEntityName()
public
getEntityName() : mixed
Tags
getJoin()
public
getJoin() : array<string|int, mixed>
Return values
array<string|int, mixed>getLanguage()
public
getLanguage() : string|null
Return values
string|nullgetLimit()
public
getLimit() : int
Return values
intgetOffset()
public
getOffset() : int
Return values
intgetOrderBy()
public
getOrderBy() : array<string|int, mixed>
Return values
array<string|int, mixed>getParamInfo()
Get documentation for one or all params
public
getParamInfo([string $param = NULL ]) : array<string|int, mixed>
Parameters
- $param : string = NULL
Return values
array<string|int, mixed> —of arrays [description, type, default, (comment)]
getParams()
Serialize this object's params into an array
public
getParams() : array<string|int, mixed>
Return values
array<string|int, mixed>getPermissions()
public
getPermissions() : array<string|int, mixed>
Return values
array<string|int, mixed>getTranslationMode()
public
getTranslationMode() : string|null
Return values
string|nullgetWhere()
public
getWhere() : array<string|int, mixed>
Return values
array<string|int, mixed>isAuthorized()
Is this api call permitted?
public
isAuthorized() : bool
This function is called if checkPermissions is set to true.
Return values
booloffsetExists()
public
offsetExists(mixed $offset) : bool
Parameters
- $offset : mixed
Tags
Return values
booloffsetGet()
public
& offsetGet(mixed $offset) : mixed
Parameters
- $offset : mixed
Tags
Attributes
- #[ReturnTypeWillChange]
offsetSet()
public
offsetSet(mixed $offset, mixed $value) : void
Parameters
- $offset : mixed
- $value : mixed
Tags
offsetUnset()
public
offsetUnset(mixed $offset) : void
Parameters
- $offset : mixed
Tags
paramExists()
public
paramExists(string $param) : bool
Parameters
- $param : string
Return values
boolreflect()
public
reflect() : ReflectionClass
Return values
ReflectionClassselectRowCount()
Only return the number of found items.
public
selectRowCount() : $this
Return values
$thissetChain()
public
setChain([array<string|int, mixed> $chain = ]) : $this
Parameters
- $chain : array<string|int, mixed> =
Return values
$thissetCheckPermissions()
public
setCheckPermissions(bool $checkPermissions) : $this
Parameters
- $checkPermissions : bool
Return values
$thissetDebug()
public
setDebug([bool $debug = ]) : $this
Enable/disable debug output
Parameters
- $debug : bool =
Return values
$thissetDefaultWhereClause()
Adds field defaults to the where clause.
public
setDefaultWhereClause() : mixed
Note: it will skip adding field defaults when fetching records by id, or if that field has already been added to the where clause.
Tags
setJoin()
public
setJoin(array<string|int, mixed> $join) : DAOGetAction
Parameters
- $join : array<string|int, mixed>
Return values
DAOGetActionsetLanguage()
public
setLanguage([string|null $language = ]) : $this
Parameters
- $language : string|null =
Return values
$thissetLimit()
public
setLimit([int $limit = ]) : $this
Parameters
- $limit : int =
Return values
$thissetOffset()
public
setOffset([int $offset = ]) : $this
Parameters
- $offset : int =
Return values
$thissetOrderBy()
public
setOrderBy([array<string|int, mixed> $order = ]) : $this
Parameters
- $order : array<string|int, mixed> =
Return values
$thissetTranslationMode()
public
setTranslationMode([string|null $mode = ]) : $this
Parameters
- $mode : string|null =
Return values
$thissetVersion()
public
setVersion(int $val) : $this
Parameters
- $val : int
Tags
Return values
$thissetWhere()
public
setWhere([array<string|int, mixed> $wheres = ]) : $this
Parameters
- $wheres : array<string|int, mixed> =
Return values
$this_isFieldSelected()
Helper to see if field(s) should be selected by the getRecords function.
protected
_isFieldSelected(string ...$fieldNames) : bool
Checks the SELECT, WHERE and ORDER BY params to see what fields are needed.
Note that if no SELECT clause has been set then all fields should be selected and this function will return TRUE for field expressions that don't contain a :pseudoconstant suffix.
Parameters
- $fieldNames : string
-
One or more field names to check (uses OR if multiple)
Return values
bool —Returns true if any given fields are in use.
_itemsToGet()
Helper to parse the WHERE param for getRecords to perform simple pre-filtering.
protected
_itemsToGet(string $field) : array<string|int, mixed>|null
This is intended to optimize some common use-cases e.g. calling the api to get one or more records by name or id.
Ex: If getRecords fetches a long list of items each with a unique name,
but the user has specified a single record to retrieve, you can optimize the call
by checking $this->_itemsToGet('name')
and only fetching the item(s) with that name.
Parameters
- $field : string
Return values
array<string|int, mixed>|null_whereContains()
Walk through the where clause and check if field(s) are in use.
protected
_whereContains(string|array<string|int, mixed> $fieldName[, array<string|int, mixed> $clauses = NULL ]) : bool
Parameters
- $fieldName : string|array<string|int, mixed>
-
A single fieldName or an array of names (uses OR if multiple)
- $clauses : array<string|int, mixed> = NULL
Return values
bool —Returns true if any given fields are found in the where clause.
addCallbackToDebugOutput()
When in debug mode, this logs the callback function being used by a Basic*Action class.
protected
addCallbackToDebugOutput(callable $callable) : mixed
Parameters
- $callable : callable
checkRequiredFields()
Validates required fields for actions which create a new object.
protected
checkRequiredFields(mixed $values) : array<string|int, mixed>
Parameters
- $values : mixed
Tags
Return values
array<string|int, mixed>deleteObjects()
protected
deleteObjects(mixed $items) : mixed
Parameters
- $items : mixed
Tags
fillDefaults()
protected
fillDefaults(mixed &$params) : mixed
Parameters
- $params : mixed
Tags
formatCustomParams()
Converts params from flat array e.g. ['GroupName.Fieldname' => value] to the hierarchy expected by the BAO, nested within $params['custom'].
protected
formatCustomParams(array<string|int, mixed> &$params, int $entityId) : mixed
Parameters
- $params : array<string|int, mixed>
- $entityId : int
Tags
formatWriteValues()
protected
formatWriteValues(mixed &$record) : mixed
Parameters
- $record : mixed
Tags
getBaoName()
protected
getBaoName() : CRM_Core_DAO|string
Return values
CRM_Core_DAO|stringgetCustomFieldInfo()
Gets field info needed to save custom data
protected
getCustomFieldInfo(string $fieldExpr) : array{id: int, name: string, entity: string, suffix: string, html_type: string, data_type: string, extends: string, table_name: string}|null
Parameters
- $fieldExpr : string
-
Field identifier with possible suffix, e.g. MyCustomGroup.MyField1:label
Return values
array{id: int, name: string, entity: string, suffix: string, html_type: string, data_type: string, extends: string, table_name: string}|nullgetLanguageOptions()
Get available preferred languages.
protected
getLanguageOptions() : array<string|int, mixed>
Return values
array<string|int, mixed>getMagicProperties()
Get a list of class properties for which magic methods are supported.
protected
static getMagicProperties() : array<string|int, mixed>
Return values
array<string|int, mixed> —List of supported properties, keyed by property name. Array(string $propertyName => bool $true).
getObjects()
protected
getObjects(Result $result) : mixed
Parameters
- $result : Result
getParamDefaults()
protected
getParamDefaults() : array<string|int, mixed>
Return values
array<string|int, mixed>resolveFKValues()
Looks up an id based on some other property of an fk entity
protected
resolveFKValues(array<string|int, mixed> &$record) : void
Parameters
- $record : array<string|int, mixed>
updateWeight()
Update weights when inserting or updating a sortable entity
protected
updateWeight(array<string|int, mixed> &$record) : mixed
Parameters
- $record : array<string|int, mixed>
Tags
whereClauseToString()
Produces a human-readable where clause, for the reading enjoyment of you humans.
protected
whereClauseToString([array<string|int, mixed> $whereClause = NULL ][, string $op = 'AND' ]) : string
Parameters
- $whereClause : array<string|int, mixed> = NULL
- $op : string = 'AND'
Return values
stringwrite()
Overrideable function to save items using the appropriate BAO function
protected
write(array<string|int, array<string|int, mixed>> $items) : array<string|int, CRM_Core_DAO>
Parameters
- $items : array<string|int, array<string|int, mixed>>
-
Items already formatted by self::writeObjects
Return values
array<string|int, CRM_Core_DAO> —Array of saved DAO records
writeObjects()
protected
writeObjects(mixed $items) : mixed
Parameters
- $items : mixed
Tags
getMaxWeight()
Looks up max weight for a set of sortable entities
private
getMaxWeight(mixed $daoName, mixed $filters, mixed $weightField) : int|mixed
Keeps it in memory in case this operation is writing more than one record
Parameters
- $daoName : mixed
- $filters : mixed
- $weightField : mixed