From b9e1e20d6f04793ab6031c78067b8c777b89634e Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 16 Aug 2022 10:09:29 +1200 Subject: [PATCH] Fix use of legacy pseudoConstant methods --- CRM/Contribute/PseudoConstant.php | 6 +++++ CRM/Member/Page/RecurringContributions.php | 3 +-- CRM/Report/Form/Member/Detail.php | 28 ++++++++++------------ 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/CRM/Contribute/PseudoConstant.php b/CRM/Contribute/PseudoConstant.php index cfad6fbb67..430bdafba1 100644 --- a/CRM/Contribute/PseudoConstant.php +++ b/CRM/Contribute/PseudoConstant.php @@ -289,6 +289,12 @@ class CRM_Contribute_PseudoConstant extends CRM_Core_PseudoConstant { * * @param int $id * @param string $columnName + * @deprecated use standard methods like + * CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $contributionStatusID); + * CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $contributionStatusID); + * CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $contributionStatusID); + * & don't specify 'CRM_Contribute_BAO_Contribution' if you mean 'CRM_Contribute_BAO_ContributionRecur' ... + * * @return array * array reference of all contribution statuses */ diff --git a/CRM/Member/Page/RecurringContributions.php b/CRM/Member/Page/RecurringContributions.php index 44c9c1062b..5bd340fd9d 100644 --- a/CRM/Member/Page/RecurringContributions.php +++ b/CRM/Member/Page/RecurringContributions.php @@ -76,7 +76,6 @@ class CRM_Member_Page_RecurringContributions extends CRM_Core_Page { 'membership_id' => $membershipID, ]); $recurringContributions = []; - $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'label'); foreach ($result['values'] as $payment) { $recurringContributionID = (int) $payment['contribution_id.contribution_recur_id.id']; @@ -96,7 +95,7 @@ class CRM_Member_Page_RecurringContributions extends CRM_Core_Page { $recurringContributions[$recurringContributionID]['id'] = $recurringContributionID; $recurringContributions[$recurringContributionID]['contactId'] = $contactID; - $recurringContributions[$recurringContributionID]['contribution_status'] = $contributionStatuses[$contributionStatusID] ?? NULL; + $recurringContributions[$recurringContributionID]['contribution_status'] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_ContributionRecur', 'contribution_status_id', $contributionStatusID); $this->setActionsForRecurringContribution($recurringContributionID, $recurringContributions[$recurringContributionID]); } diff --git a/CRM/Report/Form/Member/Detail.php b/CRM/Report/Form/Member/Detail.php index 67ced4a650..abab6c9d4f 100644 --- a/CRM/Report/Form/Member/Detail.php +++ b/CRM/Report/Form/Member/Detail.php @@ -277,7 +277,7 @@ class CRM_Report_Form_Member_Detail extends CRM_Report_Form { } } - public function from() { + public function from(): void { $this->setFromBase('civicrm_contact'); $this->_from .= " {$this->_aclFrom} @@ -312,7 +312,7 @@ HERESQL; * Override to add handling for autorenew status. */ public function whereClause(&$field, $op, $value, $min, $max) { - if ($field['dbAlias'] == "{$this->_aliases['civicrm_contribution_recur']}.contribution_status_id") { + if ($field['dbAlias'] === "{$this->_aliases['civicrm_contribution_recur']}.contribution_status_id") { $clauseParts = []; switch ($op) { case 'in': @@ -378,7 +378,7 @@ HERESQL; public function getOperationPair($type = "string", $fieldName = NULL) { //re-name IS NULL/IS NOT NULL for clarity - if ($fieldName == 'owner_membership_id') { + if ($fieldName === 'owner_membership_id') { $result = []; $result['nll'] = ts('Primary members only'); $result['nnll'] = ts('Non-primary members only'); @@ -404,14 +404,10 @@ HERESQL; * @param array $rows * Rows generated by SQL, with an array for each row. */ - public function alterDisplay(&$rows) { + public function alterDisplay(&$rows): void { $entryFound = FALSE; $checkList = []; - $contributionTypes = CRM_Contribute_PseudoConstant::financialType(); - $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'label'); - $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument(); - $repeatFound = FALSE; foreach ($rows as $rowNum => $row) { if ($repeatFound == FALSE || @@ -420,7 +416,7 @@ HERESQL; unset($checkList); $checkList = []; } - if (!empty($this->_noRepeats) && $this->_outputMode != 'csv') { + if (!empty($this->_noRepeats) && $this->_outputMode !== 'csv') { // not repeat contact display names if it matches with the one // in previous row foreach ($row as $colName => $colVal) { @@ -431,10 +427,10 @@ HERESQL; (!empty($checkList[$colName]) && in_array($colVal, $checkList[$colName])) ) { - $rows[$rowNum][$colName] = ""; + $rows[$rowNum][$colName] = ''; // CRM-15917: Don't blank the name if it's a different contact - if ($colName == 'civicrm_contact_exposed_id') { - $rows[$rowNum]['civicrm_contact_sort_name'] = ""; + if ($colName === 'civicrm_contact_exposed_id') { + $rows[$rowNum]['civicrm_contact_sort_name'] = ''; } $repeatFound = $rowNum; } @@ -466,19 +462,19 @@ HERESQL; } if ($value = CRM_Utils_Array::value('civicrm_contribution_financial_type_id', $row)) { - $rows[$rowNum]['civicrm_contribution_financial_type_id'] = $contributionTypes[$value]; + $rows[$rowNum]['civicrm_contribution_financial_type_id'] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Contribution', 'financial_type_id', $value); $entryFound = TRUE; } if ($value = CRM_Utils_Array::value('civicrm_contribution_contribution_status_id', $row)) { - $rows[$rowNum]['civicrm_contribution_contribution_status_id'] = $contributionStatus[$value]; + $rows[$rowNum]['civicrm_contribution_contribution_status_id'] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $value); $entryFound = TRUE; } if ($value = CRM_Utils_Array::value('civicrm_contribution_payment_instrument_id', $row)) { - $rows[$rowNum]['civicrm_contribution_payment_instrument_id'] = $paymentInstruments[$value]; + $rows[$rowNum]['civicrm_contribution_payment_instrument_id'] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', $value); $entryFound = TRUE; } if ($value = $row['civicrm_contribution_recur_autorenew_status_id'] ?? NULL) { - $rows[$rowNum]['civicrm_contribution_recur_autorenew_status_id'] = $contributionStatus[$value]; + $rows[$rowNum]['civicrm_contribution_recur_autorenew_status_id'] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_ContributionRecur', 'contribution_status_id', $value); if (!empty($row['civicrm_contribution_recur_end_date']) && strtotime($row['civicrm_contribution_recur_end_date']) < time()) { $ended = ts('ended'); -- 2.25.1