From 643413a06e89a606e04d0ac437f245a3992c6527 Mon Sep 17 00:00:00 2001 From: jitendrapurohit Date: Tue, 26 Jul 2016 17:28:47 +0530 Subject: [PATCH] move updateRelatedComponent to BAO --- CRM/Contribute/BAO/Contribution.php | 99 +++++++++++++++++++++ CRM/Contribute/Form/AbstractEditPayment.php | 99 --------------------- CRM/Contribute/Form/Contribution.php | 2 +- CRM/Contribute/Form/Task/Batch.php | 2 +- 4 files changed, 101 insertions(+), 101 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index f1a56fbefe..9d161c90b2 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -5086,4 +5086,103 @@ LIMIT 1;"; return $contributeSettings; } + /** + * This function process contribution related objects. + * + * @param int $contributionId + * @param int $statusId + * @param int|null $previousStatusId + * + * @param string $receiveDate + * + * @return null|string + */ + public static function transitionComponentWithReturnMessage($contributionId, $statusId, $previousStatusId = NULL, $receiveDate = NULL) { + $statusMsg = NULL; + if (!$contributionId || !$statusId) { + return $statusMsg; + } + + $params = array( + 'contribution_id' => $contributionId, + 'contribution_status_id' => $statusId, + 'previous_contribution_status_id' => $previousStatusId, + 'receive_date' => $receiveDate, + ); + + $updateResult = CRM_Contribute_BAO_Contribution::transitionComponents($params); + + if (!is_array($updateResult) || + !($updatedComponents = CRM_Utils_Array::value('updatedComponents', $updateResult)) || + !is_array($updatedComponents) || + empty($updatedComponents) + ) { + return $statusMsg; + } + + // get the user display name. + $sql = " + SELECT display_name as displayName + FROM civicrm_contact +LEFT JOIN civicrm_contribution on (civicrm_contribution.contact_id = civicrm_contact.id ) + WHERE civicrm_contribution.id = {$contributionId}"; + $userDisplayName = CRM_Core_DAO::singleValueQuery($sql); + + // get the status message for user. + foreach ($updatedComponents as $componentName => $updatedStatusId) { + + if ($componentName == 'CiviMember') { + $updatedStatusName = CRM_Utils_Array::value($updatedStatusId, + CRM_Member_PseudoConstant::membershipStatus() + ); + if ($updatedStatusName == 'Cancelled') { + $statusMsg .= "
" . ts("Membership for %1 has been Cancelled.", array(1 => $userDisplayName)); + } + elseif ($updatedStatusName == 'Expired') { + $statusMsg .= "
" . ts("Membership for %1 has been Expired.", array(1 => $userDisplayName)); + } + else { + $endDate = CRM_Utils_Array::value('membership_end_date', $updateResult); + if ($endDate) { + $statusMsg .= "
" . ts("Membership for %1 has been updated. The membership End Date is %2.", + array( + 1 => $userDisplayName, + 2 => $endDate, + ) + ); + } + } + } + + if ($componentName == 'CiviEvent') { + $updatedStatusName = CRM_Utils_Array::value($updatedStatusId, + CRM_Event_PseudoConstant::participantStatus() + ); + if ($updatedStatusName == 'Cancelled') { + $statusMsg .= "
" . ts("Event Registration for %1 has been Cancelled.", array(1 => $userDisplayName)); + } + elseif ($updatedStatusName == 'Registered') { + $statusMsg .= "
" . ts("Event Registration for %1 has been updated.", array(1 => $userDisplayName)); + } + } + + if ($componentName == 'CiviPledge') { + $updatedStatusName = CRM_Utils_Array::value($updatedStatusId, + CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name') + ); + if ($updatedStatusName == 'Cancelled') { + $statusMsg .= "
" . ts("Pledge Payment for %1 has been Cancelled.", array(1 => $userDisplayName)); + } + elseif ($updatedStatusName == 'Failed') { + $statusMsg .= "
" . ts("Pledge Payment for %1 has been Failed.", array(1 => $userDisplayName)); + } + elseif ($updatedStatusName == 'Completed') { + $statusMsg .= "
" . ts("Pledge Payment for %1 has been updated.", array(1 => $userDisplayName)); + } + } + } + + return $statusMsg; + } + } diff --git a/CRM/Contribute/Form/AbstractEditPayment.php b/CRM/Contribute/Form/AbstractEditPayment.php index 622c027a0e..c5f8855dc0 100644 --- a/CRM/Contribute/Form/AbstractEditPayment.php +++ b/CRM/Contribute/Form/AbstractEditPayment.php @@ -300,105 +300,6 @@ WHERE contribution_id = {$id} $dao->free(); } - /** - * This function process contribution related objects. - * - * @param int $contributionId - * @param int $statusId - * @param int|null $previousStatusId - * - * @param string $receiveDate - * - * @return null|string - */ - public static function updateRelatedComponent($contributionId, $statusId, $previousStatusId = NULL, $receiveDate = NULL) { - $statusMsg = NULL; - if (!$contributionId || !$statusId) { - return $statusMsg; - } - - $params = array( - 'contribution_id' => $contributionId, - 'contribution_status_id' => $statusId, - 'previous_contribution_status_id' => $previousStatusId, - 'receive_date' => $receiveDate, - ); - - $updateResult = CRM_Contribute_BAO_Contribution::transitionComponents($params); - - if (!is_array($updateResult) || - !($updatedComponents = CRM_Utils_Array::value('updatedComponents', $updateResult)) || - !is_array($updatedComponents) || - empty($updatedComponents) - ) { - return $statusMsg; - } - - // get the user display name. - $sql = " - SELECT display_name as displayName - FROM civicrm_contact -LEFT JOIN civicrm_contribution on (civicrm_contribution.contact_id = civicrm_contact.id ) - WHERE civicrm_contribution.id = {$contributionId}"; - $userDisplayName = CRM_Core_DAO::singleValueQuery($sql); - - // get the status message for user. - foreach ($updatedComponents as $componentName => $updatedStatusId) { - - if ($componentName == 'CiviMember') { - $updatedStatusName = CRM_Utils_Array::value($updatedStatusId, - CRM_Member_PseudoConstant::membershipStatus() - ); - if ($updatedStatusName == 'Cancelled') { - $statusMsg .= "
" . ts("Membership for %1 has been Cancelled.", array(1 => $userDisplayName)); - } - elseif ($updatedStatusName == 'Expired') { - $statusMsg .= "
" . ts("Membership for %1 has been Expired.", array(1 => $userDisplayName)); - } - else { - $endDate = CRM_Utils_Array::value('membership_end_date', $updateResult); - if ($endDate) { - $statusMsg .= "
" . ts("Membership for %1 has been updated. The membership End Date is %2.", - array( - 1 => $userDisplayName, - 2 => $endDate, - ) - ); - } - } - } - - if ($componentName == 'CiviEvent') { - $updatedStatusName = CRM_Utils_Array::value($updatedStatusId, - CRM_Event_PseudoConstant::participantStatus() - ); - if ($updatedStatusName == 'Cancelled') { - $statusMsg .= "
" . ts("Event Registration for %1 has been Cancelled.", array(1 => $userDisplayName)); - } - elseif ($updatedStatusName == 'Registered') { - $statusMsg .= "
" . ts("Event Registration for %1 has been updated.", array(1 => $userDisplayName)); - } - } - - if ($componentName == 'CiviPledge') { - $updatedStatusName = CRM_Utils_Array::value($updatedStatusId, - CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name') - ); - if ($updatedStatusName == 'Cancelled') { - $statusMsg .= "
" . ts("Pledge Payment for %1 has been Cancelled.", array(1 => $userDisplayName)); - } - elseif ($updatedStatusName == 'Failed') { - $statusMsg .= "
" . ts("Pledge Payment for %1 has been Failed.", array(1 => $userDisplayName)); - } - elseif ($updatedStatusName == 'Completed') { - $statusMsg .= "
" . ts("Pledge Payment for %1 has been updated.", array(1 => $userDisplayName)); - } - } - } - - return $statusMsg; - } - /** * @return array * Array of valid processors. The array resembles the DB table but also has 'object' as a key diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index ab2789805c..4b3ad1d7b4 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -1714,7 +1714,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP // process associated membership / participant, CRM-4395 if ($contribution->id && $action & CRM_Core_Action::UPDATE) { - $this->statusMessage[] = self::updateRelatedComponent($contribution->id, + $this->statusMessage[] = CRM_Contribute_BAO_Contribution::transitionComponentWithReturnMessage($contribution->id, $contribution->contribution_status_id, CRM_Utils_Array::value('contribution_status_id', $this->_values diff --git a/CRM/Contribute/Form/Task/Batch.php b/CRM/Contribute/Form/Task/Batch.php index a97547a942..2f3a4c4b5c 100644 --- a/CRM/Contribute/Form/Task/Batch.php +++ b/CRM/Contribute/Form/Task/Batch.php @@ -235,7 +235,7 @@ class CRM_Contribute_Form_Task_Batch extends CRM_Contribute_Form_Task { $contribution = CRM_Contribute_BAO_Contribution::add($value, $ids); if (!empty($value['contribution_status_id'])) { - CRM_Contribute_Form_AbstractEditPayment::updateRelatedComponent($contribution->id, + CRM_Contribute_BAO_Contribution::transitionComponentWithReturnMessage($contribution->id, $value['contribution_status_id'], CRM_Utils_Array::value("field[{$key}][contribution_status_id]", $this->_defaultValues -- 2.25.1