From f2f20028d6ee9ed0524478c4c97f1c70d956a3d8 Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 23 Aug 2019 15:50:41 +1200 Subject: [PATCH] [REF] extract send receipt in MembershipRenewal fn --- CRM/Member/Form/MembershipRenewal.php | 126 ++++++++++++++------------ 1 file changed, 69 insertions(+), 57 deletions(-) diff --git a/CRM/Member/Form/MembershipRenewal.php b/CRM/Member/Form/MembershipRenewal.php index 4c984618d3..d4067cc897 100644 --- a/CRM/Member/Form/MembershipRenewal.php +++ b/CRM/Member/Form/MembershipRenewal.php @@ -488,6 +488,8 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { * Process form submission. * * This function is also accessed by a unit test. + * + * @throws \CRM_Core_Exception */ protected function submit() { $this->storeContactFields($this->_params); @@ -651,72 +653,82 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { } if (!empty($this->_params['send_receipt'])) { + $this->sendReceipt($membership); + } + } - $receiptFrom = $this->_params['from_email_address']; - - if (!empty($this->_params['payment_instrument_id'])) { - $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument(); - $this->_params['paidBy'] = $paymentInstrument[$this->_params['payment_instrument_id']]; - } - //get the group Tree - $this->_groupTree = CRM_Core_BAO_CustomGroup::getTree('Membership', NULL, $this->_id, FALSE, $this->_memType); + /** + * Send a receipt. + * + * @param array $membership + * + * @throws \CRM_Core_Exception + */ + protected function sendReceipt($membership) { + $receiptFrom = $this->_params['from_email_address']; - // retrieve custom data - $customFields = $customValues = $fo = []; - foreach ($this->_groupTree as $groupID => $group) { - if ($groupID == 'info') { - continue; - } - foreach ($group['fields'] as $k => $field) { - $field['title'] = $field['label']; - $customFields["custom_{$k}"] = $field; - } + if (!empty($this->_params['payment_instrument_id'])) { + $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument(); + $this->_params['paidBy'] = $paymentInstrument[$this->_params['payment_instrument_id']]; + } + //get the group Tree + $this->_groupTree = CRM_Core_BAO_CustomGroup::getTree('Membership', NULL, $this->_id, FALSE, $this->_memType); + + // retrieve custom data + $customFields = $customValues = $fo = []; + foreach ($this->_groupTree as $groupID => $group) { + if ($groupID == 'info') { + continue; } - $members = [['member_id', '=', $this->_membershipId, 0, 0]]; - // check whether its a test drive - if ($this->_mode == 'test') { - $members[] = ['member_test', '=', 1, 0, 0]; + foreach ($group['fields'] as $k => $field) { + $field['title'] = $field['label']; + $customFields["custom_{$k}"] = $field; } - CRM_Core_BAO_UFGroup::getValues($this->_contactID, $customFields, $customValues, FALSE, $members); + } + $members = [['member_id', '=', $this->_membershipId, 0, 0]]; + // check whether its a test drive + if ($this->_mode == 'test') { + $members[] = ['member_test', '=', 1, 0, 0]; + } + CRM_Core_BAO_UFGroup::getValues($this->_contactID, $customFields, $customValues, FALSE, $members); - $this->assign_by_ref('formValues', $this->_params); - if (!empty($this->_params['contribution_id'])) { - $this->assign('contributionID', $this->_params['contribution_id']); - } + $this->assign_by_ref('formValues', $this->_params); + if (!empty($this->_params['contribution_id'])) { + $this->assign('contributionID', $this->_params['contribution_id']); + } - $this->assign('membership_name', CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', - $membership->membership_type_id + $this->assign('membership_name', CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', + $membership->membership_type_id + )); + $this->assign('customValues', $customValues); + $this->assign('mem_start_date', CRM_Utils_Date::customFormat($membership->start_date)); + $this->assign('mem_end_date', CRM_Utils_Date::customFormat($membership->end_date)); + if ($this->_mode) { + $this->assign('address', CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters( + $this->_params, + $this->_bltID )); - $this->assign('customValues', $customValues); - $this->assign('mem_start_date', CRM_Utils_Date::customFormat($membership->start_date)); - $this->assign('mem_end_date', CRM_Utils_Date::customFormat($membership->end_date)); - if ($this->_mode) { - $this->assign('address', CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters( - $this->_params, - $this->_bltID - )); - $this->assign('contributeMode', 'direct'); - $this->assign('isAmountzero', 0); - $this->assign('is_pay_later', 0); - $this->assign('isPrimary', 1); - $this->assign('receipt_text_renewal', $this->_params['receipt_text']); - if ($this->_mode == 'test') { - $this->assign('action', '1024'); - } + $this->assign('contributeMode', 'direct'); + $this->assign('isAmountzero', 0); + $this->assign('is_pay_later', 0); + $this->assign('isPrimary', 1); + $this->assign('receipt_text_renewal', $this->_params['receipt_text']); + if ($this->_mode == 'test') { + $this->assign('action', '1024'); } - - list($this->isMailSent) = CRM_Core_BAO_MessageTemplate::sendTemplate( - [ - 'groupName' => 'msg_tpl_workflow_membership', - 'valueName' => 'membership_offline_receipt', - 'contactId' => $this->_receiptContactId, - 'from' => $receiptFrom, - 'toName' => $this->_contributorDisplayName, - 'toEmail' => $this->_contributorEmail, - 'isTest' => $this->_mode == 'test', - ] - ); } + + list($this->isMailSent) = CRM_Core_BAO_MessageTemplate::sendTemplate( + [ + 'groupName' => 'msg_tpl_workflow_membership', + 'valueName' => 'membership_offline_receipt', + 'contactId' => $this->_receiptContactId, + 'from' => $receiptFrom, + 'toName' => $this->_contributorDisplayName, + 'toEmail' => $this->_contributorEmail, + 'isTest' => $this->_mode == 'test', + ] + ); } } -- 2.25.1