<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.3 |
+ | CiviCRM version 4.4 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2013 |
+--------------------------------------------------------------------+
}
$newParams = CRM_Contact_BAO_Query::convertFormValues($inputParams);
+ foreach ($newParams as &$newParam) {
+ if($newParam[1] == '=' && is_array($newParam[2])) {
+ // we may be looking at an attempt to use the 'IN' style syntax
+ // @todo at time of writing only 'IN' & 'NOT IN' are supported for the array style syntax
+ $sqlFilter = CRM_Core_DAO::createSqlFilter($newParam[0], $params[$newParam[0]], 'String', NULL, TRUE);
+ if($sqlFilter) {
+ $newParam[1] = key($newParam[2]);
+ $newParam[2] = $sqlFilter;
+ }
+ }
+
+ }
$skipPermissions = CRM_Utils_Array::value('check_permissions', $params)? 0 :1;
+
list($entities, $options) = CRM_Contact_BAO_Query::apiQuery(
$newParams,
$returnProperties,
}
// Extract the keys -- somewhat scary, don't think too hard about it
- $baseParams = $params;
- unset($baseParams['values']);
- unset($baseParams['sequential']);
+ $baseParams = _civicrm_api3_generic_replace_base_params($params);
// Lookup pre-existing records
$preexisting = civicrm_api($entity, 'get', $baseParams, $params);
}
}
+function _civicrm_api3_generic_replace_base_params($params) {
+ $baseParams = $params;
+ unset($baseParams['values']);
+ unset($baseParams['sequential']);
+ unset($baseParams['options']);
+ return $baseParams;
+}
+
/**
* returns fields allowable by api
* @param $entity string Entity to query
$customfields = array();
$entity = _civicrm_api_get_camel_name($entity);
if (strtolower($entity) == 'contact') {
- $entity = CRM_Utils_Array::value('contact_type', $params);
+ // Use sub-type if available, otherwise stick with 'Contact'
+ $entity = CRM_Utils_Array::value('contact_type', $params, $entity);
}
$retrieveOnlyParent = FALSE;
// we could / should probably test for other subtypes here - e.g. activity_type_id
foreach ($customfields as $key => $value) {
// Regular fields have a 'name' property
$value['name'] = 'custom_' . $key;
+ $value['type'] = _getStandardTypeFromCustomDataType($value['data_type']);
$customfields['custom_' . $key] = $value;
if (in_array('custom_' . $key, $getoptions)) {
$customfields['custom_' . $key]['options'] = CRM_Core_BAO_CustomOption::valuesByID($key);
}
return $customfields;
}
-
+/**
+ * Translate the custom field data_type attribute into a std 'type'
+ */
+function _getStandardTypeFromCustomDataType($dataType) {
+ $mapping = array(
+ 'String' => CRM_Utils_Type::T_STRING,
+ 'Int' => CRM_Utils_Type::T_INT,
+ 'Money' => CRM_Utils_Type::T_MONEY,
+ 'Memo' => CRM_Utils_Type::T_LONGTEXT,
+ 'Float' => CRM_Utils_Type::T_FLOAT,
+ 'Date' => CRM_Utils_Type::T_DATE,
+ 'Boolean' => CRM_Utils_Type::T_BOOLEAN,
+ 'StateProvince' => CRM_Utils_Type::T_INT,
+ 'File' => CRM_Utils_Type::T_STRING,
+ 'Link' => CRM_Utils_Type::T_STRING,
+ 'ContactReference' => CRM_Utils_Type::T_INT,
+ 'Country' => CRM_Utils_Type::T_INT,
+ );
+ return $mapping[$dataType];
+}
/**
* Return array of defaults for the given API (function is a wrapper on getfields)
*/
function _civicrm_api3_getdefaults($apiRequest) {
$defaults = array();
- $result = civicrm_api($apiRequest['entity'],
+ $result = civicrm_api3($apiRequest['entity'],
'getfields',
array(
- 'version' => 3,
'action' => $apiRequest['action'],
)
);
}
return;
}
- $result = civicrm_api($apiRequest['entity'],
+ $result = civicrm_api3($apiRequest['entity'],
'getfields',
array(
- 'version' => 3,
'action' => $apiRequest['action'],
)
);