* Initialize CiviCRM - should be run at the start of each API function
*/
function _civicrm_api3_initialize() {
- require_once 'CRM/Core/Config.php';
- $config = CRM_Core_Config::singleton();
- }
+ require_once 'CRM/Core/ClassLoader.php';
+ CRM_Core_ClassLoader::singleton()->register();
+ CRM_Core_Config::singleton();
+}
/**
* Wrapper Function for civicrm_verify_mandatory to make it simple to pass either / or fields for checking
if (empty($item['id']) && !empty($item[$entity . "_id"])) {
$values[$key]['id'] = $item[$entity . "_id"];
}
+ if(!empty($item['financial_type_id'])){
+ $values[$key]['contribution_type_id'] = $item['financial_type_id'];
+ }
}
}
//if ( array_key_exists ('debug',$params) && is_object ($dao)) {
if (is_array($params) && array_key_exists('debug', $params)) {
- if (!is_object($dao)) {
- $d = _civicrm_api3_get_DAO(CRM_Utils_Array::value('entity', $params));
- if (!empty($d)) {
- $file = str_replace('_', '/', $d) . ".php";
- require_once ($file);
- $dao = new $d();
- }
- }
if (is_string($action) && $action != 'getfields') {
$apiFields = civicrm_api($entity, 'getfields', array('version' => 3, 'action' => $action) + $params);
}
if (empty($dao)) {
return FALSE;
}
- $file = str_replace('_', '/', $dao) . ".php";
- require_once ($file);
$d = new $dao();
return $d;
}
}
//hack to deal with incorrectly named BAO/DAO - see CRM-10859 - remove after rename
- if($name == 'price_set'){
+ if($name == 'price_set' || $name == 'PriceSet'){
return 'CRM_Price_DAO_Set';
}
- if($name == 'price_field'){
+ if($name == 'price_field' || $name == 'PriceField'){
return 'CRM_Price_DAO_Field';
}
- if($name == 'price_field_value'){
+ if($name == 'price_field_value' || $name == 'PriceFieldValue'){
return 'CRM_Price_DAO_FieldValue';
}
// these aren't listed on ticket CRM-10859 - but same problem - lack of standardisation
if(strtolower($name) == 'im'){
return 'CRM_Core_BAO_IM';
}
-
-
- return CRM_Core_AllCoreTables::getFullName(_civicrm_api_get_camel_name($name, 3));
+ return CRM_Core_DAO_AllCoreTables::getFullName(_civicrm_api_get_camel_name($name, 3));
}
/**
//if entity_id is set then treat it as ID (will be overridden by id if set)
$dao->id = $params[$entity . "_id"];
}
+
+ $options = _civicrm_api3_get_options_from_params($params);
//apply options like sort
_civicrm_api3_apply_options_to_dao($params, $dao, $entity);
}
else {
if ($unique) {
- $dao->$allfields[$field]['name'] = $params[$field];
+ $daoFieldName = $allfields[$field]['name'];
+ if (empty($daoFieldName)) {
+ throw new API_Exception("Failed to determine field name for \"$field\"");
+ }
+ $dao->{$daoFieldName} = $params[$field];
}
else {
$dao->$field = $params[$field];
}
}
}
- if (!empty($params['return']) && is_array($params['return'])) {
+ if (!empty($options['return']) && is_array($options['return'])) {
$dao->selectAdd();
+ $options['return']['id'] = TRUE;// ensure 'id' is included
$allfields = _civicrm_api3_get_unique_name_array($dao);
- $returnMatched = array_intersect($params['return'], $allfields);
+ $returnMatched = array_intersect(array_keys($options['return']), $allfields);
$returnUniqueMatched = array_intersect(
array_diff(// not already matched on the field names
- $params['return'],
+ $options['return'],
$returnMatched),
array_flip($allfields)// but a match for the field keys
);
$dao->selectAdd($allfields[$uniqueVal]);
}
- $dao->selectAdd('id');
}
}
return TRUE;
}
- require_once 'CRM/Core/Permission.php';
-
require_once 'CRM/Core/DAO/permissions.php';
$permissions = _civicrm_api3_permissions($entity, $action, $params);
*
*/
function _civicrm_api3_custom_data_get(&$returnArray, $entity, $entity_id, $groupID = NULL, $subType = NULL, $subName = NULL) {
- require_once 'CRM/Core/BAO/CustomGroup.php';
- require_once 'CRM/Core/BAO/CustomField.php';
$groupTree = &CRM_Core_BAO_CustomGroup::getTree($entity,
CRM_Core_DAO::$_nullObject,
$entity_id,
//field is of type date or datetime
_civicrm_api3_validate_date($params, $fieldname, $fieldInfo);
break;
- case 32://blob
+
+ case 32://blob
_civicrm_api3_validate_html($params, $fieldname, $fieldInfo);
break;
- case CRM_Utils_Type::T_STRING:
+ case CRM_Utils_Type::T_STRING:
_civicrm_api3_validate_string($params, $fieldname, $fieldInfo);
break;
* @param array $fieldinfo array of fields from getfields function
*/
function _civicrm_api3_validate_constraint(&$params, &$fieldname, &$fieldInfo) {
- $file = str_replace('_', '/', $fieldInfo['FKClassName']) . ".php";
- require_once ($file);
$dao = new $fieldInfo['FKClassName'];
$dao->id = $params[$fieldname];
$dao->selectAdd();
*/
function _civicrm_api3_generic_replace($entity, $params) {
- require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
try {
if (!is_array($params['values'])) {
if (empty($dao)) {
return array();
}
- $file = str_replace('_', '/', $dao) . ".php";
- require_once ($file);
$d = new $dao();
$fields = $d->fields();
// replace uniqueNames by the normal names as the key
* fields are prefixed with 'custom_' to represent api params
*/
function _civicrm_api_get_custom_fields($entity, &$params) {
- require_once 'CRM/Core/BAO/CustomField.php';
$customfields = array();
$entity = _civicrm_api_get_camel_name($entity);
if (strtolower($entity) == 'contact') {
$session = &CRM_Core_Session::singleton();
$params[$fieldname] = $session->get('userID');
}
- if (CRM_Utils_Array::value('pseudoconstant', $fieldInfo) ) {
+ if (!empty($fieldInfo['options'])) {
$constant = CRM_Utils_Array::value('options', $fieldInfo);
if (is_numeric($params[$fieldname]) && !CRM_Utils_Array::value('FKClassName',$fieldInfo) && !array_key_exists($params[$fieldname], $fieldInfo['options'])) {
throw new API_Exception("$fieldname is not valid", 2001, array('error_field' => $fieldname,"type"=>"integer"));
*/
function _civicrm_api3_validate_string(&$params, &$fieldname, &$fieldInfo) {
// If fieldname exists in params
- $value = (string) CRM_Utils_Array::value($fieldname, $params,'');
+ $value = CRM_Utils_Array::value($fieldname, $params, '');
+ if(!is_array($value)){
+ $value = (string) $value;
+ }
+ else{
+ //@todo what do we do about passed in arrays. For many of these fields
+ // the missing piece of functionality is separating them to a separated string
+ // & many save incorrectly. But can we change them wholesale?
+ }
if ($value ) {
if (!CRM_Utils_Rule::xssString($value)) {
throw new Exception('Illegal characters in input (potential scripting attack)');
$lowerCaseOptions = array_map("strtolower", $options);
// If value passed is not a key, it may be a label
// Try to lookup key from label - if it can't be found throw error
- if (!isset($options[strtolower($value)]) && !isset($options[$value]) ) {
+ if (!is_array($value) && !isset($options[strtolower($value)]) && !isset($options[$value]) ) {
if (!in_array(strtolower($value), $lowerCaseOptions)) {
throw new Exception("$fieldname `$value` is not valid.");
}