Use metadata for getOptions abbreviation & include currency symbol
authorColeman Watts <coleman@civicrm.org>
Mon, 5 Aug 2019 14:56:00 +0000 (10:56 -0400)
committerColeman Watts <coleman@civicrm.org>
Tue, 6 Aug 2019 13:16:47 +0000 (09:16 -0400)
32 files changed:
CRM/Contribute/DAO/Contribution.php
CRM/Contribute/DAO/ContributionPage.php
CRM/Contribute/DAO/ContributionRecur.php
CRM/Contribute/DAO/ContributionSoft.php
CRM/Contribute/DAO/Product.php
CRM/Core/CodeGen/Specification.php
CRM/Core/DAO/Address.php
CRM/Core/PseudoConstant.php
CRM/Event/DAO/Event.php
CRM/Event/DAO/Participant.php
CRM/Financial/DAO/FinancialItem.php
CRM/Financial/DAO/FinancialTrxn.php
CRM/Grant/DAO/Grant.php
CRM/PCP/DAO/PCP.php
CRM/Pledge/DAO/Pledge.php
CRM/Pledge/DAO/PledgePayment.php
tests/phpunit/api/v3/AddressTest.php
tests/phpunit/api/v3/ContributionTest.php
xml/schema/Contribute/Contribution.xml
xml/schema/Contribute/ContributionPage.xml
xml/schema/Contribute/ContributionRecur.xml
xml/schema/Contribute/ContributionSoft.xml
xml/schema/Contribute/Product.xml
xml/schema/Core/Address.xml
xml/schema/Event/Event.xml
xml/schema/Event/Participant.xml
xml/schema/Financial/FinancialItem.xml
xml/schema/Financial/FinancialTrxn.xml
xml/schema/Grant/Grant.xml
xml/schema/PCP/PCP.xml
xml/schema/Pledge/Pledge.xml
xml/schema/Pledge/PledgePayment.xml

index 26ca0b9b93c47679de856984b92b0f5da57ae3dc..a30e2042ea9741a8e48e74c956cc600df3682ec6 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Generated from xml/schema/CRM/Contribute/Contribution.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:0972c177daa2ee48c98658f62c0f8ade)
+ * (GenCodeChecksum:b4e84298d9ba23d3b2fae0768fc5cb58)
  */
 
 /**
@@ -550,6 +550,7 @@ class CRM_Contribute_DAO_Contribution extends CRM_Core_DAO {
             'keyColumn' => 'name',
             'labelColumn' => 'full_name',
             'nameColumn' => 'name',
+            'abbrColumn' => 'symbol',
           ],
         ],
         'contribution_cancel_date' => [
index c4b5382c4a59d6236d1986fcf0b239afc886a5ca..4ba652bdae28b59368ba985f0bbf12f8215a2ff1 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Generated from xml/schema/CRM/Contribute/ContributionPage.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:a0dc506faaceaf3a644d020cd5b0676b)
+ * (GenCodeChecksum:70763e4804af1e4e3ddbac7b60cbd242)
  */
 
 /**
@@ -949,6 +949,7 @@ class CRM_Contribute_DAO_ContributionPage extends CRM_Core_DAO {
             'keyColumn' => 'name',
             'labelColumn' => 'full_name',
             'nameColumn' => 'name',
+            'abbrColumn' => 'symbol',
           ],
         ],
         'campaign_id' => [
index 0bb99f3a9f36367d00f1d45f1ddb941a48fd44b2..a560211bdb59d635be89e5c0657f42f69736dd55 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Generated from xml/schema/CRM/Contribute/ContributionRecur.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:95610d5dfc95017698041a9e814a7cda)
+ * (GenCodeChecksum:f88b64f09ed0362f6d630038f0a47686)
  */
 
 /**
@@ -330,6 +330,7 @@ class CRM_Contribute_DAO_ContributionRecur extends CRM_Core_DAO {
             'keyColumn' => 'name',
             'labelColumn' => 'full_name',
             'nameColumn' => 'name',
+            'abbrColumn' => 'symbol',
           ],
         ],
         'frequency_unit' => [
index 2ae9dd65b5a3356058eab5135a9f1ee42805bed2..651db6a883873eb6d6a7bd340cc57d1948c9809d 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Generated from xml/schema/CRM/Contribute/ContributionSoft.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:2872ea7ea6a2581d868e805574b9ae9f)
+ * (GenCodeChecksum:4b5e273fabfbab2591c227fed3d0214a)
  */
 
 /**
@@ -210,6 +210,7 @@ class CRM_Contribute_DAO_ContributionSoft extends CRM_Core_DAO {
             'keyColumn' => 'name',
             'labelColumn' => 'full_name',
             'nameColumn' => 'name',
+            'abbrColumn' => 'symbol',
           ],
         ],
         'pcp_id' => [
index 1e59b596ba4f11ecb5839f0afaa390f258f94f87..398b0ba375bbd86b40f87ab24fee85b8ee4a88e8 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Generated from xml/schema/CRM/Contribute/Product.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:6db129966023efff6007413d264f7e37)
+ * (GenCodeChecksum:8036ec1084e88e8fcd65e69072592388)
  */
 
 /**
@@ -313,6 +313,7 @@ class CRM_Contribute_DAO_Product extends CRM_Core_DAO {
             'keyColumn' => 'name',
             'labelColumn' => 'full_name',
             'nameColumn' => 'name',
+            'abbrColumn' => 'symbol',
           ],
         ],
         'financial_type_id' => [
index e0bfedca500e3e5283cdfbd44b2be3d0bd187857..17bfc45a5571a95fd14dacc9e83c4ce0b46bdb22 100644 (file)
@@ -430,6 +430,8 @@ class CRM_Core_CodeGen_Specification {
         'labelColumn',
         // Non-translated machine name for programmatic lookup. Defaults to 'name' if that column exists
         'nameColumn',
+        // Column to fetch in "abbreviate" context
+        'abbrColumn',
         // Where clause snippet (will be joined to the rest of the query with AND operator)
         'condition',
         // callback function incase of static arrays
index b1e00a83dc990f2f2ca9999fc90fa379bd93f214..4e896f5572ba6fe688d8e0c76431fa52d11756aa 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Generated from xml/schema/CRM/Core/Address.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:e9acc7bc70fb2860407a7d4afe12c725)
+ * (GenCodeChecksum:9cc91d1b8831b712698603b619aa1906)
  */
 
 /**
@@ -669,6 +669,7 @@ class CRM_Core_DAO_Address extends CRM_Core_DAO {
             'keyColumn' => 'id',
             'labelColumn' => 'name',
             'nameColumn' => 'iso_code',
+            'abbrColumn' => 'iso_code',
           ],
         ],
         'geo_code_1' => [
index 96a6a864206a61999e990ee0764bf0d2f69cef15..c53c451d2d3785b9a9739fae6605ccbbed2b1972 100644 (file)
@@ -253,20 +253,6 @@ class CRM_Core_PseudoConstant {
         'labelColumn' => CRM_Utils_Array::value('labelColumn', $pseudoconstant),
       ];
 
-      if ($context == 'abbreviate') {
-        switch ($fieldName) {
-          case 'state_province_id':
-            $params['labelColumn'] = 'abbreviation';
-            break;
-
-          case 'country_id':
-            $params['labelColumn'] = 'iso_code';
-            break;
-
-          default:
-        }
-      }
-
       // Fetch option group from option_value table
       if (!empty($pseudoconstant['optionGroupName'])) {
         if ($context == 'validate') {
@@ -327,6 +313,12 @@ class CRM_Core_PseudoConstant {
               $params[$nameField] = 'name';
             }
           }
+
+          // Use abbrColum if context is abbreviate
+          if ($context == 'abbreviate' && (in_array('abbreviation', $availableFields) || !empty($pseudoconstant['abbrColumn']))) {
+            $params['labelColumn'] = $pseudoconstant['abbrColumn'] ?? 'abbreviation';
+          }
+
           // Condition param can be passed as an sql clause string or an array of clauses
           if (!empty($params['condition'])) {
             $wheres[] = implode(' AND ', (array) $params['condition']);
index c6facb40120547a31c7a33be925df6e8029b82ab..a9abd91d8b1554a038bdedaf256b011c17b31854 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Generated from xml/schema/CRM/Event/Event.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:5a41f356ab1d50b2203cbef7ca3fc90a)
+ * (GenCodeChecksum:839408d0d122c558757ad2855021733d)
  */
 
 /**
@@ -1520,6 +1520,7 @@ class CRM_Event_DAO_Event extends CRM_Core_DAO {
             'keyColumn' => 'name',
             'labelColumn' => 'full_name',
             'nameColumn' => 'name',
+            'abbrColumn' => 'symbol',
           ],
         ],
         'campaign_id' => [
index 68fa6bcc9814efac886c207195d62c89076a44a7..02f804617033300083e1328d948aedf4fe901abd 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Generated from xml/schema/CRM/Event/Participant.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:919ea3218803ca5851b09181115c1c58)
+ * (GenCodeChecksum:eb8c441daf90abc9313b39ef6033320b)
  */
 
 /**
@@ -445,6 +445,7 @@ class CRM_Event_DAO_Participant extends CRM_Core_DAO {
             'keyColumn' => 'name',
             'labelColumn' => 'full_name',
             'nameColumn' => 'name',
+            'abbrColumn' => 'symbol',
           ],
         ],
         'participant_campaign_id' => [
index 2fe78840e288f7371216a448f0d9bd96d32f8642..2a106ef9237f34126b2984124ebf9d093992d69e 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Generated from xml/schema/CRM/Financial/FinancialItem.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:0746b9db4a912a1ec5242e15622e4ba8)
+ * (GenCodeChecksum:02ec1490ebc665316bc38da19b07cb60)
  */
 
 /**
@@ -239,6 +239,7 @@ class CRM_Financial_DAO_FinancialItem extends CRM_Core_DAO {
             'keyColumn' => 'name',
             'labelColumn' => 'full_name',
             'nameColumn' => 'name',
+            'abbrColumn' => 'symbol',
           ],
         ],
         'financial_account_id' => [
index 1c18b197278d63b30efedf6964edad98f3994e0d..c740bff55fbf4ed12f72db083eefd0cd573d7c9d 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Generated from xml/schema/CRM/Financial/FinancialTrxn.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:d8b27a1e5bea7078179addfc775e1ca1)
+ * (GenCodeChecksum:ea6e4e27680634c1c2e4def15d91e02c)
  */
 
 /**
@@ -316,6 +316,7 @@ class CRM_Financial_DAO_FinancialTrxn extends CRM_Core_DAO {
             'keyColumn' => 'name',
             'labelColumn' => 'full_name',
             'nameColumn' => 'name',
+            'abbrColumn' => 'symbol',
           ],
         ],
         'is_payment' => [
index bc447c32a91f17982d24ca19dbfff88255875dd9..af216a4e693f979cd473c4e74cecc6ccd1ca6e30 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Generated from xml/schema/CRM/Grant/Grant.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:55398307473a631415b01f5e9b40f7dc)
+ * (GenCodeChecksum:03885f41aa2d1f7299c66134ddd19ec2)
  */
 
 /**
@@ -383,6 +383,7 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO {
             'keyColumn' => 'name',
             'labelColumn' => 'full_name',
             'nameColumn' => 'name',
+            'abbrColumn' => 'symbol',
           ],
         ],
         'rationale' => [
index 554965ad5e47cf43316ceca2b5b2138b9dd10c9a..1a01fb5ddd893825fa8b65d09dd7ed93ecaf842c 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Generated from xml/schema/CRM/PCP/PCP.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:6dab4bfdec110d18dc9457ca3e83a0d6)
+ * (GenCodeChecksum:381499ae9c76477eb8aa0693c45456c6)
  */
 
 /**
@@ -371,6 +371,7 @@ class CRM_PCP_DAO_PCP extends CRM_Core_DAO {
             'keyColumn' => 'name',
             'labelColumn' => 'full_name',
             'nameColumn' => 'name',
+            'abbrColumn' => 'symbol',
           ],
         ],
         'is_active' => [
index d38eb70577a221c028a78a3af8101deee5f9b02c..fe6abc9014b7a22588b9981699c21be87d56fc3f 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Generated from xml/schema/CRM/Pledge/Pledge.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:117f63c183c68fcf5bd882f3fc40173e)
+ * (GenCodeChecksum:5e5bb725caa46ae10f0c5d039a03c675)
  */
 
 /**
@@ -347,6 +347,7 @@ class CRM_Pledge_DAO_Pledge extends CRM_Core_DAO {
             'keyColumn' => 'name',
             'labelColumn' => 'full_name',
             'nameColumn' => 'name',
+            'abbrColumn' => 'symbol',
           ],
         ],
         'pledge_frequency_unit' => [
index a2c000037e543e9a758cc6bc3583c93ad4e464dd..5e1da56ae5f8280d2f433f6ee5e54658b55d5978 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Generated from xml/schema/CRM/Pledge/PledgePayment.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:9f610b55354cf1a7c509cf685a03187b)
+ * (GenCodeChecksum:7dfb4f8000b79fa8b1abab1de3712fc1)
  */
 
 /**
@@ -220,6 +220,7 @@ class CRM_Pledge_DAO_PledgePayment extends CRM_Core_DAO {
             'keyColumn' => 'name',
             'labelColumn' => 'full_name',
             'nameColumn' => 'name',
+            'abbrColumn' => 'symbol',
           ],
         ],
         'pledge_payment_scheduled_date' => [
index f2724993644a92ce08f92c4af24fdf78144aaa27..7f61b3ce5dd923cbfea36128007a74681148a9bd 100644 (file)
@@ -604,4 +604,19 @@ class api_v3_AddressTest extends CiviUnitTestCase {
     $this->assertEquals('San Francisco', $goodResult['values'][4]);
   }
 
+  public function testGetOptionsAbbr() {
+    $result = $this->callAPISuccess('Address', 'getoptions', [
+      'field' => 'country_id',
+      'context' => "abbreviate",
+    ]);
+    $this->assertContains('US', $result['values']);
+    $this->assertNotContains('United States', $result['values']);
+    $result = $this->callAPISuccess('Address', 'getoptions', [
+      'field' => 'state_province_id',
+      'context' => "abbreviate",
+    ]);
+    $this->assertContains('AL', $result['values']);
+    $this->assertNotContains('Alabama', $result['values']);
+  }
+
 }
index 37d375f71b71a3d2437d823d798f96c402960aa8..5245b7498e8da7e6a9b072d531b222b7a6f7b2de 100644 (file)
@@ -4297,4 +4297,18 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
     $this->callAPISuccessGetCount('Contribution', [], 2);
   }
 
+  public function testGetCurrencyOptions() {
+    $result = $this->callAPISuccess('Contribution', 'getoptions', [
+      'field' => 'currency',
+    ]);
+    $this->assertEquals('US Dollar', $result['values']['USD']);
+    $this->assertNotContains('$', $result['values']);
+    $result = $this->callAPISuccess('Contribution', 'getoptions', [
+      'field' => 'currency',
+      'context' => "abbreviate",
+    ]);
+    $this->assertEquals('$', $result['values']['USD']);
+    $this->assertNotContains('US Dollar', $result['values']);
+  }
+
 }
index 376f5675be623a2fe4ec4ec6bf77cdca2404a26c..8c47a84fa8ed03d0141fad6f425ab90f5e397695 100644 (file)
       <keyColumn>name</keyColumn>
       <labelColumn>full_name</labelColumn>
       <nameColumn>name</nameColumn>
+      <abbrColumn>symbol</abbrColumn>
     </pseudoconstant>
     <html>
       <type>Select</type>
index ace8c0f500bb5685ed5a1d29d6d9a69d769f8681..351eef9129f2837329f58afaabe2b6254cedea46 100644 (file)
       <keyColumn>name</keyColumn>
       <labelColumn>full_name</labelColumn>
       <nameColumn>name</nameColumn>
+      <abbrColumn>symbol</abbrColumn>
     </pseudoconstant>
     <html>
       <type>Select</type>
index 9ac04a4f689c6158b8b35a73b6d46f56693ec88d..3ac72066cab1c11be657a7fc700b30b7909585e7 100644 (file)
@@ -60,6 +60,7 @@
       <keyColumn>name</keyColumn>
       <labelColumn>full_name</labelColumn>
       <nameColumn>name</nameColumn>
+      <abbrColumn>symbol</abbrColumn>
     </pseudoconstant>
     <html>
       <type>Select</type>
index f1ddfc413ad212e20542844f32edf3fb86648768..85da611d778c01cf867cdc756167923703697959 100644 (file)
@@ -79,6 +79,7 @@
       <keyColumn>name</keyColumn>
       <labelColumn>full_name</labelColumn>
       <nameColumn>name</nameColumn>
+      <abbrColumn>symbol</abbrColumn>
     </pseudoconstant>
     <html>
       <type>Select</type>
index e0095082ab1eed5128c2b18fa9ebe4bbd5edd7e3..8c18004c2cd1082e9ec91c9872a1f9e2d8b4ee61 100644 (file)
@@ -90,6 +90,7 @@
       <keyColumn>name</keyColumn>
       <labelColumn>full_name</labelColumn>
       <nameColumn>name</nameColumn>
+      <abbrColumn>symbol</abbrColumn>
     </pseudoconstant>
     <html>
       <type>Select</type>
index ba522711e2d1a48768fc9283231160168a0f5849..5b792fd4a69766e973a3d2ac7978ee4fed57ee59 100644 (file)
       <keyColumn>id</keyColumn>
       <labelColumn>name</labelColumn>
       <nameColumn>iso_code</nameColumn>
+      <abbrColumn>iso_code</abbrColumn>
     </pseudoconstant>
     <localize_context>country</localize_context>
     <html>
index 09343769a4f8a50735b42d7d3df250a95c76807d..4dd1e206b67a16140693d65ef0851b185e3930b9 100644 (file)
       <keyColumn>name</keyColumn>
       <labelColumn>full_name</labelColumn>
       <nameColumn>name</nameColumn>
+      <abbrColumn>symbol</abbrColumn>
     </pseudoconstant>
     <html>
       <type>Select</type>
index 8b267c84ebfce2b435c7a3553d81e20b65cecffb..96db3000eb9a2c9b4b64ff6e6ff6d78fe6288531 100644 (file)
       <keyColumn>name</keyColumn>
       <labelColumn>full_name</labelColumn>
       <nameColumn>name</nameColumn>
+      <abbrColumn>symbol</abbrColumn>
     </pseudoconstant>
     <html>
       <type>Select</type>
index c9c241f9a337a211fea28eaf5d716e67e392fa4e..4c6b4c0b207234e68867f7c3e3d805572a090d40 100644 (file)
@@ -85,6 +85,7 @@
       <keyColumn>name</keyColumn>
       <labelColumn>full_name</labelColumn>
       <nameColumn>name</nameColumn>
+      <abbrColumn>symbol</abbrColumn>
     </pseudoconstant>
     <html>
       <type>Select</type>
index d0d9ce8572b53a672bf19604af1a2d9535233b32..55290a872ed0679caa009df562695193126c03c5 100644 (file)
       <keyColumn>name</keyColumn>
       <labelColumn>full_name</labelColumn>
       <nameColumn>name</nameColumn>
+      <abbrColumn>symbol</abbrColumn>
     </pseudoconstant>
     <html>
       <type>Select</type>
index d19965dde64e1b145255d351483fe1ae7fb01fd9..d76e52bd5668e405390bc2b077dc0c604e5e6d71 100644 (file)
     <required>true</required>
     <comment>3 character string, value from config setting or input via user.</comment>
     <add>3.2</add>
-      <pseudoconstant>
-        <table>civicrm_currency</table>
-        <keyColumn>name</keyColumn>
-        <labelColumn>full_name</labelColumn>
-        <nameColumn>name</nameColumn>
-      </pseudoconstant>
-      <html>
-        <type>Select</type>
-      </html>
+    <pseudoconstant>
+      <table>civicrm_currency</table>
+      <keyColumn>name</keyColumn>
+      <labelColumn>full_name</labelColumn>
+      <nameColumn>name</nameColumn>
+      <abbrColumn>symbol</abbrColumn>
+    </pseudoconstant>
+    <html>
+      <type>Select</type>
+    </html>
   </field>
   <field>
     <name>currency</name>
index 9ccd2b3c4087502a9cf599476af7b952d5565997..dfb8a13f8c7429d032f737b0a8c8fc8277b48fbc 100644 (file)
       <keyColumn>name</keyColumn>
       <labelColumn>full_name</labelColumn>
       <nameColumn>name</nameColumn>
+      <abbrColumn>symbol</abbrColumn>
     </pseudoconstant>
     <html>
       <type>Select</type>
index 22f672ea9258611aa76aa227bdcca9e1fd3e7d84..50ecd9c2261b391c4ae8f46a650cb85368b180d2 100644 (file)
       <keyColumn>name</keyColumn>
       <labelColumn>full_name</labelColumn>
       <nameColumn>name</nameColumn>
+      <abbrColumn>symbol</abbrColumn>
     </pseudoconstant>
     <html>
       <type>Select</type>
index 5b70a94917ce06fd0ec3df91635f5569a7cb406e..e13eb9e16b7d5466ce3a1c61ad1c2124494d2d31 100644 (file)
@@ -87,6 +87,7 @@
       <keyColumn>name</keyColumn>
       <labelColumn>full_name</labelColumn>
       <nameColumn>name</nameColumn>
+      <abbrColumn>symbol</abbrColumn>
     </pseudoconstant>
     <html>
       <type>Select</type>