From ac5a0d1c163c1ffc33a66556371e322f65d2f1df Mon Sep 17 00:00:00 2001 From: Edsel Date: Fri, 26 Feb 2016 13:31:38 +0530 Subject: [PATCH] CRM-16526 CIVI-3 Added BAO function to filter the financial types instead of logic in API ---------------------------------------- * CRM-16526: ACLs for Financial Types https://issues.civicrm.org/jira/browse/CRM-16526 --- CRM/Price/BAO/LineItem.php | 28 ++++++++++++++++++++++++++++ api/v3/LineItem.php | 21 ++------------------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/CRM/Price/BAO/LineItem.php b/CRM/Price/BAO/LineItem.php index cb750b32bc..6e16600c9c 100644 --- a/CRM/Price/BAO/LineItem.php +++ b/CRM/Price/BAO/LineItem.php @@ -116,6 +116,34 @@ class CRM_Price_BAO_LineItem extends CRM_Price_DAO_LineItem { return NULL; } + /** + * Modifies $params array for filtering financial types. + * + * @param array $params + * (reference ) an assoc array of name/value pairs. + * + */ + public static function getAPILineItemParams(&$params) { + CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types); + if ($types && empty($params['financial_type_id'])) { + $params['financial_type_id'] = array('IN' => array_keys($types)); + } + elseif ($types) { + if (is_array($params['financial_type_id'])) { + $invalidFts = array_diff($params['financial_type_id'], array_keys($types)); + } + elseif (!in_array($params['financial_type_id'], array_keys($types))) { + $invalidFts = $params['financial_type_id']; + } + if ($invalidFts) { + $params['financial_type_id'] = array('NOT IN' => $invalidFts); + } + } + else { + $params['financial_type_id'] = 0; + } + } + /** * @param int $entityId * @param $entityTable diff --git a/api/v3/LineItem.php b/api/v3/LineItem.php index 3ed9556b45..437df48118 100644 --- a/api/v3/LineItem.php +++ b/api/v3/LineItem.php @@ -76,21 +76,7 @@ function _civicrm_api3_line_item_create_spec(&$params) { */ function civicrm_api3_line_item_get($params) { if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && CRM_Utils_Array::value('check_permissions', $params)) { - CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types); - if (empty($params['financial_type_id'])) { - $params['financial_type_id'] = array('IN' => array_keys($types)); - } - else { - if (is_array($params['financial_type_id'])) { - $invalidFts = array_diff($params['financial_type_id'], array_keys($types)); - } - elseif (!in_array($params['financial_type_id'], array_keys($types))) { - $invalidFts = $params['financial_type_id']; - } - if ($invalidFts) { - $params['financial_type_id'] = array('NOT IN' => $invalidFts); - } - } + CRM_Price_BAO_LineItem::getAPILineItemParams($params); } return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); } @@ -110,10 +96,7 @@ function civicrm_api3_line_item_delete($params) { if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && CRM_Utils_Array::value('check_permissions', $params)) { CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types, CRM_Core_Action::DELETE); if (empty($params['financial_type_id'])) { - $params['financial_type_id'] = civicrm_api3('LineItem', 'getvalue', array( - 'id' => $params['id'], - 'return' => 'financial_type_id', - )); + $params['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_LineItem', $params['id'], 'financial_type_id'); } if (!in_array($params['financial_type_id'], array_keys($types))) { throw new API_Exception('You do not have permission to delete this line item'); -- 2.25.1