/** * Get list of deprecated entities. * * This is called by the api wrapper when returning the result of api.Entity.get. * * @param array $entities * * @return array * Array of deprecated api entities */ function _civicrm_api3_entity_deprecation($entities) { $deprecated = array(); if (!empty($entities['values'])) { foreach ($entities['values'] as $entity) { if (is_string(_civicrm_api3_deprecation_check($entity))) { $deprecated[] = $entity; } } } return $deprecated; }
/** * Format array in result output style. * * @param array|int $values values generated by API operation (the result) * @param array $params * Parameters passed into API call. * @param string $entity * The entity being acted on. * @param string $action * The action passed to the API. * @param object $dao * DAO object to be freed here. * @param array $extraReturnValues * Additional values to be added to top level of result array(. * - this param is currently used for legacy behaviour support * * @return array */ function civicrm_api3_create_success($values = 1, $params = array(), $entity = NULL, $action = NULL, &$dao = NULL, $extraReturnValues = array()) { $result = array(); $lowercase_entity = _civicrm_api_get_entity_name_from_camel($entity); // TODO: This shouldn't be necessary but this fn sometimes gets called with lowercase entity $entity = _civicrm_api_get_camel_name($entity); $result['is_error'] = 0; //lets set the ['id'] field if it's not set & we know what the entity is if (is_array($values) && $entity && $action != 'getfields') { foreach ($values as $key => $item) { if (empty($item['id']) && !empty($item[$lowercase_entity . "_id"])) { $values[$key]['id'] = $item[$lowercase_entity . "_id"]; } if (!empty($item['financial_type_id'])) { //4.3 legacy handling $values[$key]['contribution_type_id'] = $item['financial_type_id']; } if (!empty($item['next_sched_contribution_date'])) { // 4.4 legacy handling $values[$key]['next_sched_contribution'] = $item['next_sched_contribution_date']; } } } if (is_array($params) && !empty($params['debug'])) { if (is_string($action) && $action != 'getfields') { $apiFields = civicrm_api($entity, 'getfields', array('version' => 3, 'action' => $action) + $params); } elseif ($action != 'getfields') { $apiFields = civicrm_api($entity, 'getfields', array('version' => 3) + $params); } else { $apiFields = FALSE; } $allFields = array(); if ($action != 'getfields' && is_array($apiFields) && is_array(CRM_Utils_Array::value('values', $apiFields))) { $allFields = array_keys($apiFields['values']); } $paramFields = array_keys($params); $undefined = array_diff($paramFields, $allFields, array_keys($_COOKIE), array('action', 'entity', 'debug', 'version', 'check_permissions', 'IDS_request_uri', 'IDS_user_agent', 'return', 'sequential', 'rowCount', 'option_offset', 'option_limit', 'custom', 'option_sort', 'options', 'prettyprint')); if ($undefined) { $result['undefined_fields'] = array_merge($undefined); } } if (is_object($dao)) { $dao->free(); } $result['version'] = 3; if (is_array($values)) { $result['count'] = (int) count($values); // Convert value-separated strings to array _civicrm_api3_separate_values($values); if ($result['count'] == 1) { list($result['id']) = array_keys($values); } elseif (!empty($values['id']) && is_int($values['id'])) { $result['id'] = $values['id']; } } else { $result['count'] = !empty($values) ? 1 : 0; } if (is_array($values) && isset($params['sequential']) && $params['sequential'] == 1) { $result['values'] = array_values($values); } else { $result['values'] = $values; } if (!empty($params['options']['metadata'])) { // We've made metadata an array but only supporting 'fields' atm. if (in_array('fields', (array) $params['options']['metadata']) && $action !== 'getfields') { $fields = civicrm_api3($entity, 'getfields', array('action' => substr($action, 0, 3) == 'get' ? 'get' : 'create')); $result['metadata']['fields'] = $fields['values']; } } // Report deprecations. $deprecated = _civicrm_api3_deprecation_check($entity, $result); // The "setvalue" action is deprecated but still in use, so report it only on "getactions". if (!is_string($deprecated) && $action == 'getactions') { $deprecated = (array) $deprecated + array('setvalue' => 'The "setvalue" action is deprecated. Use "create" with an id instead.'); } // Always report "update" action as deprecated. if (!is_string($deprecated) && ($action == 'getactions' || $action == 'update')) { $deprecated = (array) $deprecated + array('update' => 'The "update" action is deprecated. Use "create" with an id instead.'); } if ($deprecated) { // Metadata-level deprecations or wholesale entity deprecations. if ($entity == 'Entity' || $action == 'getactions' || is_string($deprecated)) { $result['deprecated'] = $deprecated; } elseif (!empty($deprecated[$action])) { $result['deprecated'] = $deprecated[$action]; } } return array_merge($result, $extraReturnValues); }