return $contributeSettings[$name] ?? NULL;
}
- /**
- * 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 = [
- '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()
- );
-
- $statusNameMsgPart = 'updated';
- switch ($updatedStatusName) {
- case 'Cancelled':
- case 'Expired':
- $statusNameMsgPart = $updatedStatusName;
- break;
- }
-
- $statusMsg .= "<br />" . ts("Membership for %1 has been %2.", [
- 1 => $userDisplayName,
- 2 => $statusNameMsgPart,
- ]);
- }
-
- if ($componentName == 'CiviEvent') {
- $updatedStatusName = CRM_Utils_Array::value($updatedStatusId,
- CRM_Event_PseudoConstant::participantStatus()
- );
- if ($updatedStatusName == 'Cancelled') {
- $statusMsg .= "<br />" . ts("Event Registration for %1 has been Cancelled.", [1 => $userDisplayName]);
- }
- elseif ($updatedStatusName == 'Registered') {
- $statusMsg .= "<br />" . ts("Event Registration for %1 has been updated.", [1 => $userDisplayName]);
- }
- }
-
- if ($componentName == 'CiviPledge') {
- $updatedStatusName = CRM_Utils_Array::value($updatedStatusId,
- CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name')
- );
- if ($updatedStatusName == 'Cancelled') {
- $statusMsg .= "<br />" . ts("Pledge Payment for %1 has been Cancelled.", [1 => $userDisplayName]);
- }
- elseif ($updatedStatusName == 'Failed') {
- $statusMsg .= "<br />" . ts("Pledge Payment for %1 has been Failed.", [1 => $userDisplayName]);
- }
- elseif ($updatedStatusName == 'Completed') {
- $statusMsg .= "<br />" . ts("Pledge Payment for %1 has been updated.", [1 => $userDisplayName]);
- }
- }
- }
-
- return $statusMsg;
- }
-
/**
* Get the contribution as it is in the database before being updated.
*
// process associated membership / participant, CRM-4395
if ($contribution->id && $action & CRM_Core_Action::UPDATE) {
- $this->statusMessage[] = CRM_Contribute_BAO_Contribution::transitionComponentWithReturnMessage($contribution->id,
- $contribution->contribution_status_id,
- CRM_Utils_Array::value('contribution_status_id',
- $this->_values
- ),
- $contribution->receive_date
- );
+ CRM_Contribute_BAO_Contribution::transitionComponents([
+ 'contribution_id' => $contribution->id,
+ 'contribution_status_id' => $contribution->contribution_status_id,
+ 'previous_contribution_status_id' => $this->_values['contribution_status_id'] ?? NULL,
+ 'receive_date' => $contribution->receive_date,
+ ]);
}
array_unshift($this->statusMessage, ts('The contribution record has been saved.'));