return $newCredit;
}
- /* Return a static array of available billing modes, in the format:
- * $array[numeric key] = 'descriptive text'.
- */
- static function getBillingModes() {
- return array(
- CRM_Core_Payment::BILLING_MODE_FORM => 'form',
- CRM_Core_Payment::BILLING_MODE_BUTTON => 'button',
- CRM_Core_Payment::BILLING_MODE_NOTIFY => 'notify',
- );
- }
}
if (isset($paymentProcessorType->billing_mode)) {
// ugh unidirectional manipulation
if (!is_numeric($paymentProcessorType->billing_mode)) {
- $billingModes = array_flip(CRM_Core_Payment::getBillingModes());
+ $billingModes = array_flip(self::buildOptions('billing_mode'));
if (array_key_exists($paymentProcessorType->billing_mode, $billingModes)) {
$paymentProcessorType->billing_mode = $billingModes[$paymentProcessorType->billing_mode];
}
}
- if (!array_key_exists($paymentProcessorType->billing_mode, CRM_Core_Payment::getBillingModes())) {
+ if (!array_key_exists($paymentProcessorType->billing_mode, self::buildOptions('billing_mode'))) {
throw new Exception("Unrecognized billing_mode");
}
}
}
return $ppt;
}
+
+ /**
+ * Get options for a given field.
+ * @see CRM_Core_DAO::buildOptions
+ *
+ * @param String $fieldName
+ * @param String $context: e.g. "search" "edit" "create" "view"
+ * @param Array $props: whatever is known about this dao object
+ */
+ public static function buildOptions($fieldName, $context = NULL, $props = array()) {
+ $params = array();
+ // Special logic for fields whose options depend on context or properties
+ switch ($fieldName) {
+ // These options are not in the db
+ case 'billing_mode':
+ return array(
+ CRM_Core_Payment::BILLING_MODE_FORM => 'form',
+ CRM_Core_Payment::BILLING_MODE_BUTTON => 'button',
+ CRM_Core_Payment::BILLING_MODE_NOTIFY => 'notify',
+ );
+ }
+ return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params);
+ }
}
return civicrm_api3_create_error("The field '{$apiRequest['params']['field']}' doesn't exist.");
}
- $daoName = _civicrm_api3_get_DAO($apiRequest['entity']);
+ $daoName = _civicrm_api3_get_BAO($apiRequest['entity']);
$options = $daoName::buildOptions($fieldName);
if ($options === FALSE) {
return civicrm_api3_create_error("The field '{$fieldName}' has no associated option list.");
$field['dataPattern'] = $this->value('dataPattern', $fieldXML);
$field['uniqueName'] = $this->value('uniqueName', $fieldXML);
$field['pseudoconstant'] = $this->value('pseudoconstant', $fieldXML);
- if(!empty($fieldXML->pseudoconstant)){
+ if(is_object($field['pseudoconstant'])){
//ok this is a bit long-winded but it gets there & is consistent with above approach
$field['pseudoconstant'] = array();
$validOptions = array(