DAOActionTrait
Common properties and helper-methods used for DB-oriented actions.
Table of Contents
Properties
- $_maxWeights : array<string|int, mixed>
Methods
- baoToArray() : array<string|int, mixed>
- Convert saved object to array
- fillDefaults() : mixed
- Fill field defaults which were declared by the api.
- 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
- 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
- write() : array<string|int, CRM_Core_DAO>
- Overrideable function to save items using the appropriate BAO function
- writeObjects() : array<string|int, mixed>
- Write bao objects as part of a create/update/save action.
- getMaxWeight() : int|mixed
- Looks up max weight for a set of sortable entities
Properties
$_maxWeights
private
array<string|int, mixed>
$_maxWeights
= []
Methods
baoToArray()
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>fillDefaults()
Fill field defaults which were declared by the api.
protected
fillDefaults(array<string|int, mixed> &$params) : mixed
Note: default values from core are ignored because the BAO or database layer will supply them.
Parameters
- $params : array<string|int, mixed>
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}|nullresolveFKValues()
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
write()
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()
Write bao objects as part of a create/update/save action.
protected
writeObjects(array<string|int, mixed> $items) : array<string|int, mixed>
Parameters
- $items : array<string|int, mixed>
-
The records to write to the DB.
Tags
Return values
array<string|int, mixed> —The records after being written to the DB (e.g. including newly assigned "id").
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