From: Coleman Watts Date: Mon, 10 Jun 2013 22:04:00 +0000 (-0700) Subject: Fix billing_mode field handling CRM-12464 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=5973d43cba9f1242840a1bd654a7def5eaa4d190;p=civicrm-core.git Fix billing_mode field handling CRM-12464 ---------------------------------------- * CRM-12464: Add PseudoConstants to Schema Metadata http://issues.civicrm.org/jira/browse/CRM-12464 --- diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 968cffefca..64ef5c59f1 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -379,15 +379,5 @@ INNER JOIN civicrm_contribution con ON ( con.contribution_recur_id = rec.id ) 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', - ); - } } diff --git a/CRM/Financial/BAO/PaymentProcessorType.php b/CRM/Financial/BAO/PaymentProcessorType.php index dd37d1f06f..d645b09699 100644 --- a/CRM/Financial/BAO/PaymentProcessorType.php +++ b/CRM/Financial/BAO/PaymentProcessorType.php @@ -151,12 +151,12 @@ class CRM_Financial_BAO_PaymentProcessorType extends CRM_Financial_DAO_PaymentPr 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"); } } @@ -213,5 +213,28 @@ WHERE pp.payment_processor_type_id = ppt.id AND ppt.id = %1"; } 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); + } } diff --git a/api/v3/Generic.php b/api/v3/Generic.php index b624621030..233a8e7765 100644 --- a/api/v3/Generic.php +++ b/api/v3/Generic.php @@ -208,7 +208,7 @@ function civicrm_api3_generic_getoptions($apiRequest) { 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."); diff --git a/xml/GenCode.php b/xml/GenCode.php index 582a0fffe7..549c50533e 100644 --- a/xml/GenCode.php +++ b/xml/GenCode.php @@ -706,7 +706,7 @@ Alternatively you can get a version of CiviCRM that matches your PHP version $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( diff --git a/xml/schema/Financial/PaymentProcessorType.xml b/xml/schema/Financial/PaymentProcessorType.xml index f882d376d3..19dc06d42f 100644 --- a/xml/schema/Financial/PaymentProcessorType.xml +++ b/xml/schema/Financial/PaymentProcessorType.xml @@ -153,6 +153,7 @@ int unsigned true Billing Mode + true 1.8