Skip to content

Commit

Permalink
Move customValue retrieval to calling function.
Browse files Browse the repository at this point in the history
After digging on CRM_Batch_Form_Entry I couldn't find any evidence that the groupTree property would ever be set
  • Loading branch information
eileenmcnaughton committed Aug 20, 2018
1 parent 2073036 commit f73ad85
Showing 1 changed file with 45 additions and 26 deletions.
71 changes: 45 additions & 26 deletions CRM/Member/Form/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -955,45 +955,25 @@ private function convertIsOverrideValue() {
* @param array $formValues
* @param object $membership
* Object.
* @param array $customValues
*
* @return bool
* true if mail was sent successfully
*/
public static function emailReceipt(&$form, &$formValues, &$membership) {
public static function emailReceipt(&$form, &$formValues, &$membership, $customValues = NULL) {
// retrieve 'from email id' for acknowledgement
$receiptFrom = CRM_Utils_Array::value('from_email_address', $formValues);

// @tod figure out how much of the stuff below is genuinely shared with the batch form & a logical shared place.
if (!empty($formValues['payment_instrument_id'])) {
$paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
$formValues['paidBy'] = $paymentInstrument[$formValues['payment_instrument_id']];
}

// retrieve custom data
$customFields = $customValues = array();
if (property_exists($form, '_groupTree')
&& !empty($form->_groupTree)
) {
foreach ($form->_groupTree as $groupID => $group) {
if ($groupID == 'info') {
continue;
}
foreach ($group['fields'] as $k => $field) {
$field['title'] = $field['label'];
$customFields["custom_{$k}"] = $field;
}
}
}

$members = array(array('member_id', '=', $membership->id, 0, 0));
// check whether its a test drive
if ($form->_mode == 'test') {
$members[] = array('member_test', '=', 1, 0, 0);
}

CRM_Core_BAO_UFGroup::getValues($formValues['contact_id'], $customFields, $customValues, FALSE, $members);
$form->assign('customValues', $customValues);

if ($form->_mode) {
// @todo move this outside shared code as Batch entry just doesn't
$form->assign('address', CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters(
$form->_params,
$form->_bltID
Expand Down Expand Up @@ -1046,6 +1026,7 @@ public static function emailReceipt(&$form, &$formValues, &$membership) {
$form->assign('membership_name', CRM_Member_PseudoConstant::membershipType($membership->membership_type_id));
}

// @todo - if we have to figure out if this is for batch processing it doesn't belong in the shared function.
$isBatchProcess = is_a($form, 'CRM_Batch_Form_Entry');
if ((empty($form->_contributorDisplayName) || empty($form->_contributorEmail)) || $isBatchProcess) {
// in this case the form is being called statically from the batch editing screen
Expand All @@ -1059,6 +1040,7 @@ public static function emailReceipt(&$form, &$formValues, &$membership) {
$form->_receiptContactId = $formValues['contact_id'];
}
}
// @todo determine isEmailPdf in calling function.
$template = CRM_Core_Smarty::singleton();
$taxAmt = $template->get_template_vars('dataArray');
$eventTaxAmt = $template->get_template_vars('totalTaxAmount');
Expand Down Expand Up @@ -1953,12 +1935,49 @@ protected function isUpdateToExistingRecurringMembership() {
* Send a receipt for the membership.
*
* @param array $formValues
* @param array $membership
* @param object $membership
* @return array
*/
protected function emailMembershipReceipt($formValues, $membership) {
$mailSend = self::emailReceipt($this, $formValues, $membership);
$customValues = $this->getCustomValuesForReceipt($formValues, $membership);

$mailSend = self::emailReceipt($this, $formValues, $membership, $customValues);
return [$membership, $mailSend];
}

/**
* Filter the custom values from the input parameters (for display in the email).
*
* @todo figure out why the scary code this calls does & document.
*
* @param array $formValues
* @param array $membership
* @return array
*/
protected function getCustomValuesForReceipt($formValues, $membership) {
$customFields = $customValues = [];
if (property_exists($this, '_groupTree')
&& !empty($this->_groupTree)
) {
foreach ($this->_groupTree as $groupID => $group) {
if ($groupID == 'info') {
continue;
}
foreach ($group['fields'] as $k => $field) {
$field['title'] = $field['label'];
$customFields["custom_{$k}"] = $field;
}
}
}

$members = [['member_id', '=', $membership->id, 0, 0]];
// check whether its a test drive
if ($this->_mode == 'test') {
$members[] = ['member_test', '=', 1, 0, 0];
}

CRM_Core_BAO_UFGroup::getValues($formValues['contact_id'], $customFields, $customValues, FALSE, $members);
return $customValues;
}

}

0 comments on commit f73ad85

Please sign in to comment.