Fix billing_mode field handling CRM-12464
authorColeman Watts <coleman@civicrm.org>
Mon, 10 Jun 2013 22:04:00 +0000 (15:04 -0700)
committerColeman Watts <coleman@civicrm.org>
Mon, 10 Jun 2013 22:04:00 +0000 (15:04 -0700)
----------------------------------------
* CRM-12464: Add PseudoConstants to Schema Metadata
  http://issues.civicrm.org/jira/browse/CRM-12464

CRM/Core/Payment.php
CRM/Financial/BAO/PaymentProcessorType.php
api/v3/Generic.php
xml/GenCode.php
xml/schema/Financial/PaymentProcessorType.xml

index 968cffefca103d4ccba467be875fa28218b7fefa..64ef5c59f1521a8d15ebffda051eac1f87e9b60b 100644 (file)
@@ -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',
-    );
-  }
 }
 
index dd37d1f06fd3acea3c3b94d976d52abdb03417b7..d645b0969954273b244883e5cf5bed03722dd5a8 100644 (file)
@@ -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);
+  }
 }
 
index b624621030415b681ef0ff5a357818eceba92d10..233a8e776583392daf392bbb3549447897a84cc2 100644 (file)
@@ -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.");
index 582a0fffe7c85f5df06871457be76d32a826090c..549c50533e07de346ef871cca0cb72200e0ad2b1 100644 (file)
@@ -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(
index f882d376d30a5827a573105cad6c5a218812cde4..19dc06d42f534ec6658f18f5f00b6fb055755734 100644 (file)
       <type>int unsigned</type>
       <required>true</required>
       <comment>Billing Mode</comment>
+      <pseudoconstant>true</pseudoconstant>
       <add>1.8</add>
   </field>
   <field>