if ((CRM_Utils_Array::value('cache_clear', $apiRequest['params']))) {
$results = array();
// we will also clear pseudoconstants here - should potentially be moved to relevant BAO classes
+ CRM_Core_PseudoConstant::flush();
if(!empty($apiRequest['params']['fieldname'])){
CRM_Utils_PseudoConstant::flushConstant($apiRequest['params']['fieldname']);
}
$lcase_entity = _civicrm_api_get_entity_name_from_camel($entity);
$subentity = CRM_Utils_Array::value('contact_type', $apiRequest['params']);
$action = strtolower(CRM_Utils_Array::value('action', $apiRequest['params']));
+ $sequential = empty($apiRequest['params']) ? 0 : 1;
$apiOptions = CRM_Utils_Array::value('options', $apiRequest['params'], array());
if ($action == 'getvalue' || $action == 'getvalue' || $action == 'getcount') {
$action = 'get';
}
// determines whether to use unique field names - seem comment block above
$unique = TRUE;
- if (isset($results[$entity . $subentity]) && CRM_Utils_Array::value($action, $results[$entity])
- && empty($apiOptions)) {
- return $results[$entity . $subentity][$action];
+ if (empty($apiOptions) && isset($results[$entity . $subentity]) && isset($action, $results[$entity . $subentity])
+ && isset($action, $results[$entity . $subentity][$sequential])) {
+ return $results[$entity . $subentity][$action][$sequential];
}
// defaults based on data model and API policy
switch ($action) {
'id' => array('title' => 'Unique Identifier',
'api.required' => 1,
'api.aliases' => array($lcase_entity . '_id'),
+ 'type' => CRM_Utils_Type::T_INT,
));
break;
case 'getoptions':
$metadata = array(
- 'field' => array('title' => 'Field to retrieve options for',
- 'api.required' => 1,
- ));
+ 'field' => array(
+ 'title' => 'Field to retrieve options for',
+ 'api.required' => 1,
+ ),
+ 'context' => array(
+ 'title' => 'Context string',
+ ),
+ );
break;
default:
// oddballs are on their own
$helper = '_' . $hypApiRequest['function'] . '_spec';
if (function_exists($helper)) {
// alter
- $helper($metadata);
+ $helper($metadata, $apiRequest);
}
$fieldsToResolve = (array) CRM_Utils_Array::value('get_options', $apiOptions, array());
_civicrm_api3_generic_get_metadata_options($metadata, $apiRequest['entity'], $fieldname, $fieldSpec, $fieldsToResolve);
}
- $results[$entity][$action] = civicrm_api3_create_success($metadata, $apiRequest['params'], NULL, 'getfields');
- return $results[$entity][$action];
+ $results[$entity][$action][$sequential] = civicrm_api3_create_success($metadata, $apiRequest['params'], NULL, 'getfields');
+ return $results[$entity][$action][$sequential];
}
/**
* @return integer count of results
*/
function civicrm_api3_generic_getcount($apiRequest) {
+ $apiRequest['params']['options']['is_count'] = TRUE;
$result = civicrm_api($apiRequest['entity'], 'get', $apiRequest['params']);
+ if(is_numeric (CRM_Utils_Array::value('values', $result))) {
+ return (int) $result['values'];
+ }
+ if(!isset($result['count'])) {
+ throw new API_Exception(ts('Unexpected result from getcount') . print_r($result, TRUE));
+ }
return $result['count'];
}
if (!$fieldName) {
return civicrm_api3_create_error("The field '{$apiRequest['params']['field']}' doesn't exist.");
}
+ // Validate 'context' from params
+ $context = CRM_Utils_Array::value('context', $apiRequest['params']);
+ CRM_Core_DAO::buildOptionsContext($context);
+ unset($apiRequest['params']['context'], $apiRequest['params']['field']);
- $daoName = _civicrm_api3_get_BAO($apiRequest['entity']);
- $options = $daoName::buildOptions($fieldName);
+ $baoName = _civicrm_api3_get_BAO($apiRequest['entity']);
+ $options = $output = $baoName::buildOptions($fieldName, $context, $apiRequest['params']);
if ($options === FALSE) {
return civicrm_api3_create_error("The field '{$fieldName}' has no associated option list.");
}
- return civicrm_api3_create_success($options);
+ // Support 'sequential' output as a non-associative array
+ if (!empty($apiRequest['params']['sequential'])) {
+ $output = array();
+ foreach ($options as $key => $val) {
+ $output[] = array('key' => $key, 'value' => $val);
+ }
+ }
+ return civicrm_api3_create_success($output);
}
/**
return;
}
- if(substr($fieldname, -3) == '_id'){
- $metadata[$fieldname]['api.aliases'][] = substr($fieldname, 0, -3);
- }
-
- if (!empty($metadata[$fieldname]['options']) || !in_array($fieldname, $fieldsToResolve)) {
+ if (!empty($metadata[$fieldname]['options']) || (!in_array($fieldname, $fieldsToResolve) && !in_array('all', $fieldsToResolve))) {
return;
}