}
if ($result['count'] == 1) {
- list($result['id']) = array_keys($values);
+ [$result['id']] = array_keys($values);
}
elseif (!empty($values['id']) && is_int($values['id'])) {
$result['id'] = $values['id'];
/**
* Load the DAO of the entity.
*
- * @param $entity
+ * @param string $entity
*
* @return bool
*/
if ($name === 'MailingRecipients') {
return 'CRM_Mailing_DAO_Recipients';
}
- if ($name === 'AclRole') {
+ if ($name === 'AclRole' || $name === 'ACLRole') {
return 'CRM_ACL_DAO_ACLEntityRole';
}
// FIXME: DAO should be renamed CRM_SMS_DAO_SmsProvider
/**
* Recursive function to explode value-separated strings into arrays.
*
- * @param $values
+ * @param array $values
*/
function _civicrm_api3_separate_values(&$values) {
$sp = CRM_Core_DAO::VALUE_SEPARATOR;
}
/**
- * Store values.
+ * Copy values (other than id) from params to values if they exist in fields.
*
* @param array $fields
* @param array $params
* @param array $values
*
- * @return Bool
+ * @return bool
*/
-function _civicrm_api3_store_values(&$fields, &$params, &$values) {
+function _civicrm_api3_store_values(array $fields, array $params, &$values): bool {
$valueFound = FALSE;
$keys = array_intersect_key($params, $fields);
* Ideally this would be merged with _civicrm_get_query_object but we need to resolve differences in what the
* 2 variants call
*
- * @param $entity
+ * @param string $entity
* @param array $params
* As passed into api get or getcount function.
* @param array $additional_options
$returnProperties = NULL;
}
- if (substr($sort, 0, 2) == 'id') {
+ if (substr(($sort ?? ''), 0, 2) == 'id') {
$sort = $lowercase_entity . "_" . $sort;
}
$skipPermissions = !empty($params['check_permissions']) ? 0 : 1;
- list($entities) = CRM_Contact_BAO_Query::apiQuery(
+ [$entities] = CRM_Contact_BAO_Query::apiQuery(
$newParams,
$returnProperties,
NULL,
empty($params['check_permissions']),
TRUE, TRUE, NULL, 'AND', 'NULL', TRUE
);
- list($select, $from, $where, $having) = $query->query();
+ [$select, $from, $where, $having] = $query->query();
$sql = "$select $from $where $having";
* Params array as passed into civicrm_api.
* @param object $dao
* DAO object.
- * @param $entity
+ * @param string $entity
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
/**
* Wrapper for _civicrm_object_to_array when api supports unique fields.
*
- * @param $dao
- * @param $values
+ * @param CRM_Core_DAO $dao
+ * @param array $values
*
* @return array
*/
}
foreach ($params as $key => $value) {
- list($customFieldID, $customValueID) = CRM_Core_BAO_CustomField::getKeyID($key, TRUE);
+ [$customFieldID, $customValueID] = CRM_Core_BAO_CustomField::getKeyID($key, TRUE);
if ($customFieldID && (!is_null($value))) {
if ($checkCheckBoxField && !empty($fields['custom_' . $customFieldID]) && $fields['custom_' . $customFieldID]['html_type'] == 'CheckBox') {
formatCheckBoxField($value, 'custom_' . $customFieldID, $entity);
* Format parameters for create action.
*
* @param array $params
- * @param $entity
+ * @param string $entity
*/
function _civicrm_api3_format_params_for_create(&$params, $entity) {
- $nonGenericEntities = ['Contact', 'Individual', 'Household', 'Organization'];
+ if (!$entity) {
+ return;
+ }
+ $entity = CRM_Core_DAO_AllCoreTables::convertEntityNameToCamel($entity);
+ $nonGenericEntities = array_merge(['Contact'], CRM_Contact_BAO_ContactType::basicTypes(TRUE));
$customFieldEntities = array_diff_key(CRM_Core_SelectValues::customGroupExtends(), array_fill_keys($nonGenericEntities, 1));
if (!array_key_exists($entity, $customFieldEntities)) {
*
* @param array $returnArray
* Array to append custom data too - generally $result[4] where 4 is the entity id.
- * @param $checkPermission
+ * @param bool $checkPermission
* @param string $entity
* E.g membership, event.
* @param int $entity_id
/**
* Used by the Validate API.
- * @param $fieldName
+ * @param string $fieldName
* @param array $fieldInfo
* @param string $entity
* @param array $params
break;
case CRM_Utils_Type::T_MONEY:
- list($fieldValue, $op) = _civicrm_api3_field_value_check($params, $fieldName);
+ [$fieldValue, $op] = _civicrm_api3_field_value_check($params, $fieldName);
foreach ((array) $fieldValue as $fieldvalue) {
if (!CRM_Utils_Rule::money($fieldvalue) && !empty($fieldvalue)) {
break;
case CRM_Utils_Type::T_MONEY:
- list($fieldValue, $op) = _civicrm_api3_field_value_check($params, $fieldName);
+ [$fieldValue, $op] = _civicrm_api3_field_value_check($params, $fieldName);
if (strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE) {
break;
}
* @throws Exception
*/
function _civicrm_api3_validate_date(&$params, &$fieldName, &$fieldInfo) {
- list($fieldValue, $op) = _civicrm_api3_field_value_check($params, $fieldName);
- if (strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE) {
+ [$fieldValue, $op] = _civicrm_api3_field_value_check($params, $fieldName);
+ if (strpos(($op ?? ''), 'NULL') !== FALSE || strpos(($op ?? ''), 'EMPTY') !== FALSE) {
return;
}
*
* @param string $dateValue
* @param string $fieldName
- * @param $fieldType
+ * @param int $fieldType
*
* @throws Exception
* @return mixed
* @throws Exception
*/
function _civicrm_api3_validate_unique_key(&$params, &$fieldName) {
- list($fieldValue, $op) = _civicrm_api3_field_value_check($params, $fieldName);
+ [$fieldValue, $op] = _civicrm_api3_field_value_check($params, $fieldName);
if (strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE) {
return;
}
/**
* Returns fields allowable by api.
*
- * @param $entity
+ * @param string $entity
* String Entity to query.
* @param bool $unique
* Index by unique fields?.
*
* This is the same as the BAO function but fields are prefixed with 'custom_' to represent api params.
*
- * @param $entity
+ * @param string $entity
* @param array $params
*
* @return array
*/
function _civicrm_api_get_custom_fields($entity, &$params) {
- $entity = _civicrm_api_get_camel_name($entity);
+ $entity = CRM_Core_DAO_AllCoreTables::convertEntityNameToCamel($entity);
if ($entity == 'Contact') {
// Use sub-type if available, otherwise "NULL" to fetch from all contact types
$entity = $params['contact_type'] ?? NULL;
*
* Function also swaps unique fields for non-unique fields & vice versa.
*
- * @param $apiRequest
- * @param $fields
+ * @param array $apiRequest
+ * @param array $fields
*/
function _civicrm_api3_swap_out_aliases(&$apiRequest, $fields) {
foreach ($fields as $field => $values) {
* @throws API_Exception
*/
function _civicrm_api3_validate_integer(&$params, $fieldName, &$fieldInfo, $entity) {
- list($fieldValue, $op) = _civicrm_api3_field_value_check($params, $fieldName);
+ [$fieldValue, $op] = _civicrm_api3_field_value_check($params, $fieldName);
if ($fieldName === 'auto_renew' && $fieldValue === TRUE) {
// https://lab.civicrm.org/dev/rc/-/issues/14
$fieldValue = 1;
}
- if (strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE) {
+ if (strpos(($op ?? ''), 'NULL') !== FALSE || strpos(($op ?? ''), 'EMPTY') !== FALSE) {
return;
}
}
}
if (
- (!empty($fieldInfo['pseudoconstant']) || !empty($fieldInfo['options']) || $fieldName === 'campaign_id')
- // if it is already numeric AND it is an FK field we don't need to validate because
- // sql will do that for us on insert (this also saves a big lookup)
- && (!is_numeric($fieldValue) || empty($fieldInfo['FKClassName']))
+ !empty($fieldInfo['pseudoconstant']) ||
+ !empty($fieldInfo['options']) ||
+ // Special case for campaign_id which is no longer a pseudoconstant
+ ($fieldName === 'campaign_id' && !CRM_Utils_Rule::positiveInteger($fieldValue))
) {
$additional_lookup_params = [];
if (strtolower($entity) === 'address' && $fieldName == 'state_province_id') {
/**
* Helper function to determine country_id given the myriad of values for country_id or country that are supported
- * @param $params
+ * @param array $params
*
* @return int|null
*/
* @throws API_Exception
*/
function _civicrm_api3_validate_html(&$params, &$fieldName, $fieldInfo) {
- list($fieldValue, $op) = _civicrm_api3_field_value_check($params, $fieldName);
+ [$fieldValue, $op] = _civicrm_api3_field_value_check($params, $fieldName);
if (strpos($op, 'NULL') || strpos($op, 'EMPTY')) {
return;
}
*/
function _civicrm_api3_validate_string(&$params, &$fieldName, &$fieldInfo, $entity, $action) {
$isGet = substr($action, 0, 3) === 'get';
- list($fieldValue, $op) = _civicrm_api3_field_value_check($params, $fieldName, 'String');
- if (strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE || CRM_Utils_System::isNull($fieldValue)) {
+ [$fieldValue, $op] = _civicrm_api3_field_value_check($params, $fieldName, 'String');
+ if (strpos(($op ?? ''), 'NULL') !== FALSE || strpos(($op ?? ''), 'EMPTY') !== FALSE || CRM_Utils_System::isNull($fieldValue)) {
return;
}
/**
* Returns the canonical name of a field.
*
- * @param $entity
+ * @param string $entity
* api entity name (string should already be standardized - no camelCase).
- * @param $fieldName
+ * @param string $fieldName
* any variation of a field's name (name, unique_name, api.alias).
*
* @param string $action
* _civicrm_api3_basic_get but does not use DAO/BAO. This is useful for
* small/mid-size data loaded from external JSON or XML documents.
*
- * @param $entity
+ * @param string $entity
* @param array $params
* API parameters.
* @param array $records