Skip to content

Commit

Permalink
Move pcpNotifyOwner to ContributionSoft
Browse files Browse the repository at this point in the history
This is cleanup towards #19096 in that
it gets the function out of the form layer and also makes it so it does
not require a BAO. This does add one extra db lookup in some cases but I think
it's pretty low volume and will mean this is not required

https://github.com/civicrm/civicrm-core/pull/19096/files#diff-4c9d0b1abe07057a4eea2b47bc627eecb95face8ed8d86c1c005312a52cca811R4271-R4273
  • Loading branch information
eileenmcnaughton committed Jun 7, 2021
1 parent 8f630a4 commit 01921b4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CRM/Contribute/BAO/ContributionSoft.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ public static function formatHonoreeProfileFields($form, $params, $honorId = NUL
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
* @throws \API_Exception
*/
protected static function processPCP($pcp, $contribution) {
$pcpId = self::getSoftCreditIds($contribution->id, TRUE);
Expand All @@ -609,7 +610,7 @@ protected static function processPCP($pcp, $contribution) {
$contributionSoft = self::add($softParams);
//Send notification to owner for PCP
if ($contributionSoft->pcp_id && empty($pcpId)) {
CRM_Contribute_Form_Contribution_Confirm::pcpNotifyOwner($contribution, (array) $contributionSoft);
CRM_Contribute_Form_Contribution_Confirm::pcpNotifyOwner($contribution->id, (array) $contributionSoft);
}
}
//Delete PCP against this contribution and create new on submitted PCP information
Expand Down
21 changes: 13 additions & 8 deletions CRM/Contribute/Form/Contribution/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/

use Civi\Api4\Contribution;

/**
* form to process actions on the group aspect of Custom Data
*/
Expand Down Expand Up @@ -1393,41 +1395,44 @@ public static function processOnBehalfOrganization(&$behalfOrganization, &$conta
*
* This is used by contribution and also event PCPs.
*
* @param object $contribution
* @param int $contributionID
* @param array $contributionSoft
* Contribution object.
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
*/
public static function pcpNotifyOwner($contribution, array $contributionSoft) {
public static function pcpNotifyOwner(int $contributionID, array $contributionSoft): void {
$params = ['id' => $contributionSoft['pcp_id']];
$contribution = Contribution::get(FALSE)
->addWhere('id', '=', $contributionID)
->addSelect('receive_date', 'contact_id')->execute()->first();
CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo);
$ownerNotifyID = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCPBlock', $pcpInfo['pcp_block_id'], 'owner_notify_id');
$ownerNotifyOption = CRM_Core_PseudoConstant::getName('CRM_PCP_DAO_PCPBlock', 'owner_notify_id', $ownerNotifyID);

if ($ownerNotifyOption != 'no_notifications' &&
(($ownerNotifyOption == 'owner_chooses' &&
if ($ownerNotifyOption !== 'no_notifications' &&
(($ownerNotifyOption === 'owner_chooses' &&
CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $contributionSoft['pcp_id'], 'is_notify')) ||
$ownerNotifyOption == 'all_owners')) {
$ownerNotifyOption === 'all_owners')) {
$pcpInfoURL = CRM_Utils_System::url('civicrm/pcp/info',
"reset=1&id={$contributionSoft['pcp_id']}",
TRUE, NULL, FALSE, TRUE
);
// set email in the template here

if (CRM_Core_BAO_LocationType::getBilling()) {
[$donorName, $email] = CRM_Contact_BAO_Contact_Location::getEmailDetails($contribution->contact_id,
[$donorName, $email] = CRM_Contact_BAO_Contact_Location::getEmailDetails($contribution['contact_id'],
FALSE, CRM_Core_BAO_LocationType::getBilling());
}
// get primary location email if no email exist( for billing location).
if (!$email) {
[$donorName, $email] = CRM_Contact_BAO_Contact_Location::getEmailDetails($contribution->contact_id);
[$donorName, $email] = CRM_Contact_BAO_Contact_Location::getEmailDetails($contribution['contact_id']);
}
[$ownerName, $ownerEmail] = CRM_Contact_BAO_Contact_Location::getEmailDetails($contributionSoft['contact_id']);
$tplParams = [
'page_title' => $pcpInfo['title'],
'receive_date' => $contribution->receive_date,
'receive_date' => $contribution['receive_date'],
'total_amount' => $contributionSoft['amount'],
'donors_display_name' => $donorName,
'donors_email' => $email,
Expand Down

0 comments on commit 01921b4

Please sign in to comment.