CRM-20272 Generalised function to add labels
authorEdsel <edsel.lopez@jmaconsulting.biz>
Thu, 16 Mar 2017 07:11:23 +0000 (12:41 +0530)
committerEdsel <edsel.lopez@jmaconsulting.biz>
Thu, 16 Mar 2017 08:34:23 +0000 (14:04 +0530)
----------------------------------------
* 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

CRM/Report/Form.php
CRM/Report/Form/Contribute/Summary.php

index 6b25b697361d124d4695ce9f605b9d301e40040b..d4e4740ea77b14becee3c17c26920fd599b8a4ed 100644 (file)
@@ -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));
   }
index dde477e7d823f1c4f39f5a25fe7f5f95ebfb17ac..59e66b11b0decbcaa3224f29416966fabefa4099 100644 (file)
@@ -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;
       }