// get payment instrument id
if (!empty($query->_returnProperties['payment_instrument_id'])) {
+ $query->_select['instrument_id'] = "contribution_payment_instrument.value as instrument_id";
$query->_select['payment_instrument_id'] = "contribution_payment_instrument.value as payment_instrument_id";
- $query->_element['payment_instrument_id'] = 1;
+ $query->_element['instrument_id'] = $query->_element['payment_instrument_id'] = 1;
$query->_tables['civicrm_contribution'] = 1;
$query->_tables['contribution_payment_instrument'] = 1;
}
$query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
return;
+ case 'contribution_payment_instrument':
+ case 'contribution_payment_instrument_id':
+ $name = str_replace('contribution_', '', $name);
case 'payment_instrument':
case 'payment_instrument_id':
if ($name == 'payment_instrument') {
if (strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE) {
break;
}
- if (is_array($fieldValue)) {
- foreach($fieldValue as $fieldvalue) {
- if (!CRM_Utils_Rule::money($fieldvalue) && !empty($fieldvalue)) {
- throw new Exception($fieldName . " is not a valid amount: " . $params[$fieldName]);
- }
- }
- }
- else {
- if (!CRM_Utils_Rule::money($fieldValue) && !empty($fieldValue)) {
+ foreach((array)$fieldValue as $fieldvalue) {
+ if (!CRM_Utils_Rule::money($fieldvalue) && !empty($fieldvalue)) {
throw new Exception($fieldName . " is not a valid amount: " . $params[$fieldName]);
}
}
}
if ($fieldName == 'currency') {
//When using IN operator $fieldValue is a array of currency codes
- if (is_array($fieldValue)) {
- foreach ($fieldValue as $currency) {
- if (!CRM_Utils_Rule::currencyCode($currency)) {
- throw new Exception("Currency not a valid code: $currency");
- }
+ foreach ((array)$fieldValue as $currency) {
+ if (!CRM_Utils_Rule::currencyCode($currency)) {
+ throw new Exception("Currency not a valid code: $currency");
}
}
- else {
- if (!CRM_Utils_Rule::currencyCode($fieldValue)) {
- throw new Exception("Currency not a valid code: $fieldValue");
- }
- }
- }
- if (!empty($fieldInfo['pseudoconstant']) || !empty($fieldInfo['options'])) {
- _civicrm_api3_api_match_pseudoconstant($fieldValue, $entity, $fieldName, $fieldInfo);
- }
- // Check our field length
- elseif (is_string($fieldValue) && !empty($fieldInfo['maxlength']) && strlen(utf8_decode($fieldValue)) > $fieldInfo['maxlength']) {
- throw new API_Exception("Value for $fieldName is " . strlen(utf8_decode($value)) . " characters - This field has a maxlength of {$fieldInfo['maxlength']} characters.",
- 2100, array('field' => $fieldName)
- );
}
}
+ if (!empty($fieldInfo['pseudoconstant']) || !empty($fieldInfo['options'])) {
+ _civicrm_api3_api_match_pseudoconstant($fieldValue, $entity, $fieldName, $fieldInfo);
+ }
+ // Check our field length
+ elseif (is_string($fieldValue) && !empty($fieldInfo['maxlength']) && strlen(utf8_decode($fieldValue)) > $fieldInfo['maxlength']) {
+ throw new API_Exception("Value for $fieldName is " . strlen(utf8_decode($value)) . " characters - This field has a maxlength of {$fieldInfo['maxlength']} characters.",
+ 2100, array('field' => $fieldName)
+ );
+ }
if (!empty($op)) {
$params[$fieldName][$op] = $fieldValue;
}
$options = civicrm_api($entity, 'getoptions', array('version' => 3, 'field' => $fieldInfo['name'], 'context' => 'validate'));
$options = CRM_Utils_Array::value('values', $options, array());
-
- if (count($options) == 0 && isset($pseudoconstant['table'])) {
- $pseudoParams = $pseudoconstant;
- unset($pseudoParams['table']);
- $options = CRM_Core_PseudoConstant::get(CRM_Core_DAO_AllCoreTables::getClassForTable($pseudoconstant['table']), $fieldName, $pseudoParams);
- }
}
// If passed a value-separated string, explode to an array, then re-implode after matching values
$this->callAPISuccess('contribution', 'create', $params2);
$contribution = $this->callAPISuccess('contribution', 'get', array(
'sequential' => 1,
- 'contribution_payment_instrument_id' => 'Cash',
+ 'contribution_payment_instrument' => 'Cash',
));
$this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
$this->assertEquals('Cash',$contribution['values'][0]['payment_instrument']);
//This should not be required on update:
$old_contact_id = $original['values'][$contributionID]['contact_id'];
- $old_payment_instrument = $original['values'][$contributionID]['payment_instrument_id'];
+ $old_payment_instrument = $original['values'][$contributionID]['instrument_id'];
$old_fee_amount = $original['values'][$contributionID]['fee_amount'];
$old_source = $original['values'][$contributionID]['contribution_source'];
$this->assertEquals($contribution['values'][$contributionID]['contact_id'], $this->_individualId);
$this->assertEquals($contribution['values'][$contributionID]['total_amount'], 110.00);
$this->assertEquals($contribution['values'][$contributionID]['financial_type_id'],$this->_financialTypeId );
- $this->assertEquals($contribution['values'][$contributionID]['payment_instrument_id'], $old_payment_instrument);
+ $this->assertEquals($contribution['values'][$contributionID]['instrument_id'], $old_payment_instrument);
$this->assertEquals($contribution['values'][$contributionID]['non_deductible_amount'], 10.00);
$this->assertEquals($contribution['values'][$contributionID]['fee_amount'], $old_fee_amount);
$this->assertEquals($contribution['values'][$contributionID]['net_amount'], 100.00);
'entity_id',
),
),
+ 'ContributionSoft' => array(
+ 'cant_update' => array(
+ // can't be changed through api
+ 'pcp_id',
+ ),
+ ),
'Pledge' => array(
'cant_update' => array(
'pledge_original_installment_amount',
));
$options['values'][] = $optionValue['id'];
}
- if (isset($specs['pseudoconstant']['table'])) {
- //some psedoconstant property is based on other entity attributes
- //as the there may or maynot be records for such entity, so we are considering empty records for now
- //e.g. pcp_id property will be table=civicrm_pcp, keyColumn=id and labelColumn=title
- continue;
- }
}
$entity[$field] = array_rand($options['values']);
}