}
// Report deprecations.
$deprecated = _civicrm_api3_deprecation_check($entity, $result);
+ // Always report "setvalue" action as deprecated.
+ if (!is_string($deprecated) && ($action == 'getactions' || $action == 'setvalue')) {
+ $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.');
CRM_Core_DAO::$_nullObject,
$entity_id,
$groupID,
- $subType,
- $subName
+ NULL,
+ $subName,
+ TRUE,
+ NULL,
+ TRUE
);
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, CRM_Core_DAO::$_nullObject);
$customValues = array();
* @throws Exception
*/
function _civicrm_api3_validate_string(&$params, &$fieldName, &$fieldInfo, $entity) {
- list($fieldValue, $op) = _civicrm_api3_field_value_check($params, $fieldName);
+ 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)) {
return;
}
* Get the actual field value.
*
* In some case $params[$fieldName] holds Array value in this format Array([operator] => [value])
- * So this function returns the actual field value
+ * So this function returns the actual field value.
*
* @param array $params
* @param string $fieldName
+ * @param string $type
*
* @return mixed
*/
-function _civicrm_api3_field_value_check(&$params, $fieldName) {
+function _civicrm_api3_field_value_check(&$params, $fieldName, $type = NULL) {
$fieldValue = CRM_Utils_Array::value($fieldName, $params);
$op = NULL;
- if (!empty($fieldValue) && is_array($fieldValue) && array_search(key($fieldValue), CRM_Core_DAO::acceptedSQLOperators())) {
+ if (!empty($fieldValue) && is_array($fieldValue) &&
+ (array_search(key($fieldValue), CRM_Core_DAO::acceptedSQLOperators()) ||
+ $type == 'String' && strstr(key($fieldValue), 'EMPTY'))
+ ) {
$op = key($fieldValue);
$fieldValue = CRM_Utils_Array::value($op, $fieldValue);
}
return array($fieldValue, $op);
}
+
+/**
+ * A generic "get" API based on simple array data. This is comparable to
+ * _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 array $params
+ * API parameters.
+ * @param array $records
+ * List of all records.
+ * @param string $idCol
+ * The property which defines the ID of a record
+ * @param array $fields
+ * List of filterable fields.
+ * @return array
+ */
+function _civicrm_api3_basic_array_get($entity, $params, $records, $idCol, $fields) {
+ $options = _civicrm_api3_get_options_from_params($params, TRUE, $entity, 'get');
+ // TODO // $sort = CRM_Utils_Array::value('sort', $options, NULL);
+ $offset = CRM_Utils_Array::value('offset', $options);
+ $limit = CRM_Utils_Array::value('limit', $options);
+
+ $matches = array();
+
+ $currentOffset = 0;
+ foreach ($records as $record) {
+ if ($idCol != 'id') {
+ $record['id'] = $record[$idCol];
+ }
+ $match = TRUE;
+ foreach ($params as $k => $v) {
+ if ($k == 'id') {
+ $k = $idCol;
+ }
+ if (in_array($k, $fields) && $record[$k] != $v) {
+ $match = FALSE;
+ break;
+ }
+ }
+ if ($match) {
+ if ($currentOffset >= $offset) {
+ $matches[$record[$idCol]] = $record;
+ }
+ if ($limit && count($matches) >= $limit) {
+ break;
+ }
+ $currentOffset++;
+ }
+ }
+
+ $return = CRM_Utils_Array::value('return', $options, array());
+ if (!empty($return)) {
+ $return['id'] = 1;
+ $matches = CRM_Utils_Array::filterColumns($matches, array_keys($return));
+ }
+
+ return civicrm_api3_create_success($matches, $params);
+}