From: Edsel Date: Thu, 16 Mar 2017 07:11:23 +0000 (+0530) Subject: CRM-20272 Generalised function to add labels X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=a51858a18cc2a068e595e43014333fd73d356e06;p=civicrm-core.git CRM-20272 Generalised function to add labels ---------------------------------------- * CRM-20272: Add credit card type field for Contribution Summary Report https://issues.civicrm.org/jira/browse/CRM-20272 CRM-20272 Generalised function to add labels ---------------------------------------- * CRM-20272: Add credit card type field for Contribution Summary Report https://issues.civicrm.org/jira/browse/CRM-20272 --- diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 6b25b69736..d4e4740ea7 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -4894,20 +4894,22 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a } /** - * Get all labels for credit card type rows in report. + * Get all labels for fields that are used in a group concat. * - * @param string $creditCardTypes - * comma separated option values of option group "credit_card_type". + * @param string $options + * comma separated option values. + * @param string $baoName + * The BAO name for the field. + * @param string $fieldName + * The name of the field for which labels should be retrieved. + * + * return string */ - public function getGroupCreditCardType($creditCardTypes) { - $cardTypes = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialTrxn', 'card_type'); - $types = explode(',', $creditCardTypes); + public function getLabels($options, $baoName, $fieldName) { + $types = explode(',', $options); $labels = array(); foreach ($types as $value) { - $label = CRM_Utils_Array::value($value, $cardTypes); - if (!in_array($label, $labels)) { - $labels[] = $label; - } + $labels[$value] = CRM_Core_PseudoConstant::getLabel($baoName, $fieldName, $value); } return implode(', ', array_filter($labels)); } diff --git a/CRM/Report/Form/Contribute/Summary.php b/CRM/Report/Form/Contribute/Summary.php index dde477e7d8..59e66b11b0 100644 --- a/CRM/Report/Form/Contribute/Summary.php +++ b/CRM/Report/Form/Contribute/Summary.php @@ -966,7 +966,7 @@ ROUND(AVG({$this->_aliases['civicrm_contribution_soft']}.amount), 2) as civicrm_ } if (!empty($row['civicrm_financial_trxn_card_type'])) { - $rows[$rowNum]['civicrm_financial_trxn_card_type'] = $this->getGroupCreditCardType($row['civicrm_financial_trxn_card_type']); + $rows[$rowNum]['civicrm_financial_trxn_card_type'] = $this->getLabels($row['civicrm_financial_trxn_card_type'], 'CRM_Financial_DAO_FinancialTrxn', 'card_type'); $entryFound = TRUE; }