From 6844be6437e325c4fa211f2a211ab6b765f2f26e Mon Sep 17 00:00:00 2001 From: Monish Deb Date: Tue, 1 Jun 2021 14:11:55 +0530 Subject: [PATCH] Add pseudoconstant callback for LineItem and Financial item entity --- CRM/Financial/BAO/FinancialItem.php | 12 ++++++++++++ CRM/Financial/DAO/FinancialItem.php | 9 ++++++--- CRM/Price/BAO/LineItem.php | 13 +++++++++++++ CRM/Price/DAO/LineItem.php | 9 ++++++--- xml/schema/Financial/FinancialItem.xml | 5 ++++- xml/schema/Price/LineItem.xml | 6 ++++-- 6 files changed, 45 insertions(+), 9 deletions(-) diff --git a/CRM/Financial/BAO/FinancialItem.php b/CRM/Financial/BAO/FinancialItem.php index 215159bb99..e3cc03c6a9 100644 --- a/CRM/Financial/BAO/FinancialItem.php +++ b/CRM/Financial/BAO/FinancialItem.php @@ -289,4 +289,16 @@ WHERE cc.id IN (' . implode(',', $contactIds) . ') AND con.is_test = 0'; return civicrm_api3('FinancialItem', 'getsingle', $params); } + /** + * Whitelist of possible values for the entity_table field + * + * @return array + */ + public static function entityTables(): array { + return [ + 'civicrm_line_item' => ts('Line Item'), + 'civicrm_financial_trxn' => ts('Financial Trxn'), + ]; + } + } diff --git a/CRM/Financial/DAO/FinancialItem.php b/CRM/Financial/DAO/FinancialItem.php index 6d1f8098f7..2e99cdfd69 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:b63c826a61c494010c7628672e82fc27) + * (GenCodeChecksum:c9deaca104b5b1126ad3a064c520d0c3) */ /** @@ -93,7 +93,7 @@ class CRM_Financial_DAO_FinancialItem extends CRM_Core_DAO { public $status_id; /** - * The table providing the source of this item such as civicrm_line_item + * May contain civicrm_line_item, civicrm_financial_trxn etc * * @var string */ @@ -315,7 +315,7 @@ class CRM_Financial_DAO_FinancialItem extends CRM_Core_DAO { 'name' => 'entity_table', 'type' => CRM_Utils_Type::T_STRING, 'title' => ts('Entity Table'), - 'description' => ts('The table providing the source of this item such as civicrm_line_item'), + 'description' => ts('May contain civicrm_line_item, civicrm_financial_trxn etc'), 'maxlength' => 64, 'size' => CRM_Utils_Type::BIG, 'where' => 'civicrm_financial_item.entity_table', @@ -323,6 +323,9 @@ class CRM_Financial_DAO_FinancialItem extends CRM_Core_DAO { 'entity' => 'FinancialItem', 'bao' => 'CRM_Financial_BAO_FinancialItem', 'localizable' => 0, + 'pseudoconstant' => [ + 'callback' => 'CRM_Financial_BAO_FinancialItem::entityTables', + ], 'add' => '4.3', ], 'entity_id' => [ diff --git a/CRM/Price/BAO/LineItem.php b/CRM/Price/BAO/LineItem.php index 0d6f12c6a8..e7e891b70a 100644 --- a/CRM/Price/BAO/LineItem.php +++ b/CRM/Price/BAO/LineItem.php @@ -1229,4 +1229,17 @@ WHERE li.contribution_id = %1"; return CRM_Contribute_BAO_Contribution::checkContributeSettings('tax_term'); } + /** + * Whitelist of possible values for the entity_table field + * + * @return array + */ + public static function entityTables(): array { + return [ + 'civicrm_contribution' => ts('Contribution'), + 'civicrm_participant' => ts('Participant'), + 'civicrm_membership' => ts('Membership'), + ]; + } + } diff --git a/CRM/Price/DAO/LineItem.php b/CRM/Price/DAO/LineItem.php index c226921b4b..0aa851939e 100644 --- a/CRM/Price/DAO/LineItem.php +++ b/CRM/Price/DAO/LineItem.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Price/LineItem.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:1c10b6b406bb73014b2fbe6ceb95fda3) + * (GenCodeChecksum:cffc97712c8823323cbeb39a0851363a) */ /** @@ -39,7 +39,7 @@ class CRM_Price_DAO_LineItem extends CRM_Core_DAO { public $id; /** - * table which has the transaction + * May contain civicrm_contribution, civicrm_participant or civicrm_membership * * @var string */ @@ -195,7 +195,7 @@ class CRM_Price_DAO_LineItem extends CRM_Core_DAO { 'name' => 'entity_table', 'type' => CRM_Utils_Type::T_STRING, 'title' => ts('Line Item Entity Type'), - 'description' => ts('table which has the transaction'), + 'description' => ts('May contain civicrm_contribution, civicrm_participant or civicrm_membership'), 'required' => TRUE, 'maxlength' => 64, 'size' => CRM_Utils_Type::BIG, @@ -204,6 +204,9 @@ class CRM_Price_DAO_LineItem extends CRM_Core_DAO { 'entity' => 'LineItem', 'bao' => 'CRM_Price_BAO_LineItem', 'localizable' => 0, + 'pseudoconstant' => [ + 'callback' => 'CRM_Price_BAO_LineItem::entityTables', + ], 'add' => '1.7', ], 'entity_id' => [ diff --git a/xml/schema/Financial/FinancialItem.xml b/xml/schema/Financial/FinancialItem.xml index 8e1f5a7454..f7790e49ed 100644 --- a/xml/schema/Financial/FinancialItem.xml +++ b/xml/schema/Financial/FinancialItem.xml @@ -139,7 +139,10 @@ varchar Entity Table 64 - The table providing the source of this item such as civicrm_line_item + + CRM_Financial_BAO_FinancialItem::entityTables + + May contain civicrm_line_item, civicrm_financial_trxn etc 4.3 diff --git a/xml/schema/Price/LineItem.xml b/xml/schema/Price/LineItem.xml index 6b2733e717..4e0f795bec 100644 --- a/xml/schema/Price/LineItem.xml +++ b/xml/schema/Price/LineItem.xml @@ -28,7 +28,10 @@ varchar 64 true - table which has the transaction + + CRM_Price_BAO_LineItem::entityTables + + May contain civicrm_contribution, civicrm_participant or civicrm_membership 1.7 @@ -225,4 +228,3 @@ - -- 2.25.1