X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContribute%2FBAO%2FContributionPage.php;h=0d57b7d06f642ef72731969757582b45b4bf45f7;hb=84ad7693766a74f6a9e62bf1aed9209826ecd078;hp=346ca886ab16d327b6cc8be930a8543d17f44d3d;hpb=093e8cc14b638518ace7131472225302a9683eee;p=civicrm-core.git diff --git a/CRM/Contribute/BAO/ContributionPage.php b/CRM/Contribute/BAO/ContributionPage.php index 346ca886ab..0d57b7d06f 100644 --- a/CRM/Contribute/BAO/ContributionPage.php +++ b/CRM/Contribute/BAO/ContributionPage.php @@ -15,6 +15,9 @@ * @copyright CiviCRM LLC https://civicrm.org/licensing */ +use Civi\Api4\Contribution; +use Civi\Api4\LineItem; + /** * This class contains Contribution Page related functions. */ @@ -284,14 +287,14 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio $template = CRM_Core_Smarty::singleton(); if (!array_key_exists('related_contact', $values)) { - list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID, FALSE, CRM_Core_BAO_LocationType::getBilling()); + [$displayName, $email] = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID, FALSE, CRM_Core_BAO_LocationType::getBilling()); } // get primary location email if no email exist( for billing location). if (!$email) { - list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID); + [$displayName, $email] = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID); } if (empty($displayName)) { - list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID); + [$displayName, $email] = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID); } //for display profile need to get individual contact id, @@ -309,7 +312,7 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio $userID = $values['related_contact'] ?? NULL; } } - list($values['customPre_grouptitle'], $values['customPre']) = self::getProfileNameAndFields($preID, $userID, $params['custom_pre_id']); + [$values['customPre_grouptitle'], $values['customPre']] = self::getProfileNameAndFields($preID, $userID, $params['custom_pre_id']); } $userID = $contactID; if ($postID = CRM_Utils_Array::value('custom_post_id', $values)) { @@ -362,6 +365,7 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio 'pay_later_receipt' => $values['pay_later_receipt'] ?? NULL, 'honor_block_is_active' => $values['honor_block_is_active'] ?? NULL, 'contributionStatus' => $values['contribution_status'] ?? NULL, + 'currency' => CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $values['contribution_id'], 'currency') ?? CRM_Core_Config::singleton()->defaultCurrency, ]; if (!empty($values['financial_type_id'])) { @@ -481,7 +485,7 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio $fields = CRM_Core_BAO_UFGroup::getFields($gid, FALSE, CRM_Core_Action::VIEW, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL); foreach ($fields as $k => $v) { if (!$groupTitle) { - $groupTitle = $v['groupTitle']; + $groupTitle = $v['groupDisplayTitle']; } // suppress all file fields from display and formatting fields if ( @@ -503,55 +507,51 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio /** * Send the emails for Recurring Contribution Notification. * + * @param int $contributionID * @param string $type * TxnType. - * @param int $contactID - * Contact id for contributor. - * @param int $pageID * Contribution page id. * @param object $recur - * Object of recurring contribution table. - * @param bool|object $autoRenewMembership is it a auto renew membership. + * + * @throws \API_Exception */ - public static function recurringNotify($type, $contactID, $pageID, $recur, $autoRenewMembership = FALSE) { - $value = []; - $isEmailReceipt = FALSE; - if ($pageID) { - CRM_Core_DAO::commonRetrieveAll('CRM_Contribute_DAO_ContributionPage', 'id', $pageID, $value, [ - 'title', - 'is_email_receipt', - 'receipt_from_name', - 'receipt_from_email', - 'cc_receipt', - 'bcc_receipt', - ]); - $isEmailReceipt = $value[$pageID]['is_email_receipt'] ?? NULL; - } - elseif ($recur->id) { - // This means we are coming from back-office - ie. no page ID, but recurring. - // Ideally this information would be passed into the function clearly rather than guessing by convention. - $isEmailReceipt = TRUE; - } - - if ($isEmailReceipt) { - if ($pageID) { - $receiptFrom = '"' . CRM_Utils_Array::value('receipt_from_name', $value[$pageID]) . '" <' . $value[$pageID]['receipt_from_email'] . '>'; - - $receiptFromName = $value[$pageID]['receipt_from_name']; - $receiptFromEmail = $value[$pageID]['receipt_from_email']; + public static function recurringNotify($contributionID, $type, $recur): void { + $contribution = Contribution::get(FALSE) + ->addWhere('id', '=', $contributionID) + ->setSelect([ + 'contribution_page_id', + 'contact_id', + 'contribution_recur_id', + 'contribution_recur_id.is_email_receipt', + 'contribution_page_id.title', + 'contribution_page_id.is_email_receipt', + 'contribution_page_id.receipt_from_name', + 'contribution_page_id.receipt_from_email', + 'contribution_page_id.cc_receipt', + 'contribution_page_id.bcc_receipt', + ]) + ->execute()->first(); + + $isMembership = !empty(LineItem::get(FALSE) + ->addWhere('contribution_id', '=', $contributionID) + ->addWhere('entity_table', '=', 'civicrm_membership') + ->addSelect('id')->execute()->first()); + + if ($contribution['contribution_recur_id.is_email_receipt'] || $contribution['contribution_page_id.is_email_receipt']) { + if ($contribution['contribution_page_id.receipt_from_email']) { + $receiptFromName = $contribution['contribution_page_id.receipt_from_name']; + $receiptFromEmail = $contribution['contribution_page_id.receipt_from_email']; } else { - $domainValues = CRM_Core_BAO_Domain::getNameAndEmail(); - $receiptFrom = "$domainValues[0] <$domainValues[1]>"; - $receiptFromName = $domainValues[0]; - $receiptFromEmail = $domainValues[1]; + [$receiptFromName, $receiptFromEmail] = CRM_Core_BAO_Domain::getNameAndEmail(); } - list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID, FALSE); + $receiptFrom = "$receiptFromName <$receiptFromEmail>"; + [$displayName, $email] = CRM_Contact_BAO_Contact_Location::getEmailDetails($contribution['contact_id'], FALSE); $templatesParams = [ 'groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'contribution_recurring_notify', - 'contactId' => $contactID, + 'contactId' => $contribution['contact_id'], 'tplParams' => [ 'recur_frequency_interval' => $recur->frequency_interval, 'recur_frequency_unit' => $recur->frequency_unit, @@ -563,17 +563,15 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio 'displayName' => $displayName, 'receipt_from_name' => $receiptFromName, 'receipt_from_email' => $receiptFromEmail, - 'auto_renew_membership' => $autoRenewMembership, + 'auto_renew_membership' => $isMembership, ], 'from' => $receiptFrom, 'toName' => $displayName, 'toEmail' => $email, ]; //CRM-13811 - if ($pageID) { - $templatesParams['cc'] = $value[$pageID]['cc_receipt'] ?? NULL; - $templatesParams['bcc'] = $value[$pageID]['bcc_receipt'] ?? NULL; - } + $templatesParams['cc'] = $contribution['contribution_page_id.cc_receipt']; + $templatesParams['bcc'] = $contribution['contribution_page_id.cc_receipt']; if ($recur->id) { // in some cases its just recurringNotify() thats called for the first time and these urls don't get set. // like in PaypalPro, & therefore we set it here additionally. @@ -834,7 +832,7 @@ LEFT JOIN civicrm_premiums ON ( civicrm_premiums.entity_id = civicrm * * @return array|string */ - public static function formatModuleData($params, $setDefault = FALSE, $module) { + public static function formatModuleData($params, $setDefault, $module) { $tsLocale = CRM_Core_I18n::getLocale(); $config = CRM_Core_Config::singleton(); $json = $jsonDecode = NULL;