From a8fdb24e93f8cdcf62c8448412ddd4d6a8e0e5dc Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 5 Aug 2019 10:56:00 -0400 Subject: [PATCH] Use metadata for getOptions abbreviation & include currency symbol --- CRM/Contribute/DAO/Contribution.php | 3 ++- CRM/Contribute/DAO/ContributionPage.php | 3 ++- CRM/Contribute/DAO/ContributionRecur.php | 3 ++- CRM/Contribute/DAO/ContributionSoft.php | 3 ++- CRM/Contribute/DAO/Product.php | 3 ++- CRM/Core/CodeGen/Specification.php | 2 ++ CRM/Core/DAO/Address.php | 3 ++- CRM/Core/PseudoConstant.php | 20 ++++++-------------- CRM/Event/DAO/Event.php | 3 ++- CRM/Event/DAO/Participant.php | 3 ++- CRM/Financial/DAO/FinancialItem.php | 3 ++- CRM/Financial/DAO/FinancialTrxn.php | 3 ++- CRM/Grant/DAO/Grant.php | 3 ++- CRM/PCP/DAO/PCP.php | 3 ++- CRM/Pledge/DAO/Pledge.php | 3 ++- CRM/Pledge/DAO/PledgePayment.php | 3 ++- tests/phpunit/api/v3/AddressTest.php | 15 +++++++++++++++ tests/phpunit/api/v3/ContributionTest.php | 14 ++++++++++++++ xml/schema/Contribute/Contribution.xml | 1 + xml/schema/Contribute/ContributionPage.xml | 1 + xml/schema/Contribute/ContributionRecur.xml | 1 + xml/schema/Contribute/ContributionSoft.xml | 1 + xml/schema/Contribute/Product.xml | 1 + xml/schema/Core/Address.xml | 1 + xml/schema/Event/Event.xml | 1 + xml/schema/Event/Participant.xml | 1 + xml/schema/Financial/FinancialItem.xml | 1 + xml/schema/Financial/FinancialTrxn.xml | 1 + xml/schema/Grant/Grant.xml | 19 ++++++++++--------- xml/schema/PCP/PCP.xml | 1 + xml/schema/Pledge/Pledge.xml | 1 + xml/schema/Pledge/PledgePayment.xml | 1 + 32 files changed, 88 insertions(+), 37 deletions(-) diff --git a/CRM/Contribute/DAO/Contribution.php b/CRM/Contribute/DAO/Contribution.php index 26ca0b9b93..a30e2042ea 100644 --- a/CRM/Contribute/DAO/Contribution.php +++ b/CRM/Contribute/DAO/Contribution.php @@ -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' => [ diff --git a/CRM/Contribute/DAO/ContributionPage.php b/CRM/Contribute/DAO/ContributionPage.php index c4b5382c4a..4ba652bdae 100644 --- a/CRM/Contribute/DAO/ContributionPage.php +++ b/CRM/Contribute/DAO/ContributionPage.php @@ -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' => [ diff --git a/CRM/Contribute/DAO/ContributionRecur.php b/CRM/Contribute/DAO/ContributionRecur.php index 0bb99f3a9f..a560211bdb 100644 --- a/CRM/Contribute/DAO/ContributionRecur.php +++ b/CRM/Contribute/DAO/ContributionRecur.php @@ -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' => [ diff --git a/CRM/Contribute/DAO/ContributionSoft.php b/CRM/Contribute/DAO/ContributionSoft.php index 2ae9dd65b5..651db6a883 100644 --- a/CRM/Contribute/DAO/ContributionSoft.php +++ b/CRM/Contribute/DAO/ContributionSoft.php @@ -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' => [ diff --git a/CRM/Contribute/DAO/Product.php b/CRM/Contribute/DAO/Product.php index 1e59b596ba..398b0ba375 100644 --- a/CRM/Contribute/DAO/Product.php +++ b/CRM/Contribute/DAO/Product.php @@ -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' => [ diff --git a/CRM/Core/CodeGen/Specification.php b/CRM/Core/CodeGen/Specification.php index e0bfedca50..17bfc45a55 100644 --- a/CRM/Core/CodeGen/Specification.php +++ b/CRM/Core/CodeGen/Specification.php @@ -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 diff --git a/CRM/Core/DAO/Address.php b/CRM/Core/DAO/Address.php index b1e00a83dc..4e896f5572 100644 --- a/CRM/Core/DAO/Address.php +++ b/CRM/Core/DAO/Address.php @@ -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' => [ diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index 96a6a86420..c53c451d2d 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -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']); diff --git a/CRM/Event/DAO/Event.php b/CRM/Event/DAO/Event.php index c6facb4012..a9abd91d8b 100644 --- a/CRM/Event/DAO/Event.php +++ b/CRM/Event/DAO/Event.php @@ -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' => [ diff --git a/CRM/Event/DAO/Participant.php b/CRM/Event/DAO/Participant.php index 68fa6bcc98..02f8046170 100644 --- a/CRM/Event/DAO/Participant.php +++ b/CRM/Event/DAO/Participant.php @@ -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' => [ diff --git a/CRM/Financial/DAO/FinancialItem.php b/CRM/Financial/DAO/FinancialItem.php index 2fe78840e2..2a106ef923 100644 --- a/CRM/Financial/DAO/FinancialItem.php +++ b/CRM/Financial/DAO/FinancialItem.php @@ -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' => [ diff --git a/CRM/Financial/DAO/FinancialTrxn.php b/CRM/Financial/DAO/FinancialTrxn.php index 1c18b19727..c740bff55f 100644 --- a/CRM/Financial/DAO/FinancialTrxn.php +++ b/CRM/Financial/DAO/FinancialTrxn.php @@ -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' => [ diff --git a/CRM/Grant/DAO/Grant.php b/CRM/Grant/DAO/Grant.php index bc447c32a9..af216a4e69 100644 --- a/CRM/Grant/DAO/Grant.php +++ b/CRM/Grant/DAO/Grant.php @@ -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' => [ diff --git a/CRM/PCP/DAO/PCP.php b/CRM/PCP/DAO/PCP.php index 554965ad5e..1a01fb5ddd 100644 --- a/CRM/PCP/DAO/PCP.php +++ b/CRM/PCP/DAO/PCP.php @@ -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' => [ diff --git a/CRM/Pledge/DAO/Pledge.php b/CRM/Pledge/DAO/Pledge.php index d38eb70577..fe6abc9014 100644 --- a/CRM/Pledge/DAO/Pledge.php +++ b/CRM/Pledge/DAO/Pledge.php @@ -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' => [ diff --git a/CRM/Pledge/DAO/PledgePayment.php b/CRM/Pledge/DAO/PledgePayment.php index a2c000037e..5e1da56ae5 100644 --- a/CRM/Pledge/DAO/PledgePayment.php +++ b/CRM/Pledge/DAO/PledgePayment.php @@ -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' => [ diff --git a/tests/phpunit/api/v3/AddressTest.php b/tests/phpunit/api/v3/AddressTest.php index f272499364..7f61b3ce5d 100644 --- a/tests/phpunit/api/v3/AddressTest.php +++ b/tests/phpunit/api/v3/AddressTest.php @@ -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']); + } + } diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 37d375f71b..5245b7498e 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -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']); + } + } diff --git a/xml/schema/Contribute/Contribution.xml b/xml/schema/Contribute/Contribution.xml index 376f5675be..8c47a84fa8 100644 --- a/xml/schema/Contribute/Contribution.xml +++ b/xml/schema/Contribute/Contribution.xml @@ -265,6 +265,7 @@ name full_name name + symbol Select diff --git a/xml/schema/Contribute/ContributionPage.xml b/xml/schema/Contribute/ContributionPage.xml index ace8c0f500..351eef9129 100644 --- a/xml/schema/Contribute/ContributionPage.xml +++ b/xml/schema/Contribute/ContributionPage.xml @@ -420,6 +420,7 @@ name full_name name + symbol Select diff --git a/xml/schema/Contribute/ContributionRecur.xml b/xml/schema/Contribute/ContributionRecur.xml index 9ac04a4f68..3ac72066ca 100644 --- a/xml/schema/Contribute/ContributionRecur.xml +++ b/xml/schema/Contribute/ContributionRecur.xml @@ -60,6 +60,7 @@ name full_name name + symbol Select diff --git a/xml/schema/Contribute/ContributionSoft.xml b/xml/schema/Contribute/ContributionSoft.xml index f1ddfc413a..85da611d77 100644 --- a/xml/schema/Contribute/ContributionSoft.xml +++ b/xml/schema/Contribute/ContributionSoft.xml @@ -79,6 +79,7 @@ name full_name name + symbol Select diff --git a/xml/schema/Contribute/Product.xml b/xml/schema/Contribute/Product.xml index e0095082ab..8c18004c2c 100644 --- a/xml/schema/Contribute/Product.xml +++ b/xml/schema/Contribute/Product.xml @@ -90,6 +90,7 @@ name full_name name + symbol Select diff --git a/xml/schema/Core/Address.xml b/xml/schema/Core/Address.xml index ba522711e2..5b792fd4a6 100644 --- a/xml/schema/Core/Address.xml +++ b/xml/schema/Core/Address.xml @@ -348,6 +348,7 @@ id name iso_code + iso_code country diff --git a/xml/schema/Event/Event.xml b/xml/schema/Event/Event.xml index 09343769a4..4dd1e206b6 100644 --- a/xml/schema/Event/Event.xml +++ b/xml/schema/Event/Event.xml @@ -773,6 +773,7 @@ name full_name name + symbol Select diff --git a/xml/schema/Event/Participant.xml b/xml/schema/Event/Participant.xml index 8b267c84eb..96db3000eb 100644 --- a/xml/schema/Event/Participant.xml +++ b/xml/schema/Event/Participant.xml @@ -234,6 +234,7 @@ name full_name name + symbol Select diff --git a/xml/schema/Financial/FinancialItem.xml b/xml/schema/Financial/FinancialItem.xml index c9c241f9a3..4c6b4c0b20 100644 --- a/xml/schema/Financial/FinancialItem.xml +++ b/xml/schema/Financial/FinancialItem.xml @@ -85,6 +85,7 @@ name full_name name + symbol Select diff --git a/xml/schema/Financial/FinancialTrxn.xml b/xml/schema/Financial/FinancialTrxn.xml index d0d9ce8572..55290a872e 100644 --- a/xml/schema/Financial/FinancialTrxn.xml +++ b/xml/schema/Financial/FinancialTrxn.xml @@ -146,6 +146,7 @@ name full_name name + symbol Select diff --git a/xml/schema/Grant/Grant.xml b/xml/schema/Grant/Grant.xml index d19965dde6..d76e52bd56 100644 --- a/xml/schema/Grant/Grant.xml +++ b/xml/schema/Grant/Grant.xml @@ -167,15 +167,16 @@ true 3 character string, value from config setting or input via user. 3.2 - - civicrm_currency
- name - full_name - name -
- - Select - + + civicrm_currency
+ name + full_name + name + symbol +
+ + Select + currency diff --git a/xml/schema/PCP/PCP.xml b/xml/schema/PCP/PCP.xml index 9ccd2b3c40..dfb8a13f8c 100644 --- a/xml/schema/PCP/PCP.xml +++ b/xml/schema/PCP/PCP.xml @@ -176,6 +176,7 @@ name full_name name + symbol Select diff --git a/xml/schema/Pledge/Pledge.xml b/xml/schema/Pledge/Pledge.xml index 22f672ea92..50ecd9c226 100644 --- a/xml/schema/Pledge/Pledge.xml +++ b/xml/schema/Pledge/Pledge.xml @@ -131,6 +131,7 @@ name full_name name + symbol Select diff --git a/xml/schema/Pledge/PledgePayment.xml b/xml/schema/Pledge/PledgePayment.xml index 5b70a94917..e13eb9e16b 100644 --- a/xml/schema/Pledge/PledgePayment.xml +++ b/xml/schema/Pledge/PledgePayment.xml @@ -87,6 +87,7 @@ name full_name name + symbol Select -- 2.25.1