Merge pull request #27596 from eileenmcnaughton/participant_custom_assign
authorcolemanw <coleman@civicrm.org>
Sat, 14 Oct 2023 19:01:31 +0000 (15:01 -0400)
committerGitHub <noreply@github.com>
Sat, 14 Oct 2023 19:01:31 +0000 (15:01 -0400)
Move assigning customGroup to offline participant template out of the form layer

1  2 
CRM/Core/BAO/CustomField.php
CRM/Event/Form/Participant.php
CRM/Event/WorkflowMessage/ParticipantTrait.php

Simple merge
index 11095d98464d7f4a9d49ab787aaaf473b3323213,a008c8aca1f01afafd250223bf00c73bfc31833b..8e7b5e58288ebcaa7b13c13b34db5686908017f5
@@@ -1897,41 -2095,49 +1897,26 @@@ INNER JOIN civicrm_price_field_value va
    protected function sendReceipts($params, array $participants, $lineItem, $additionalParticipantDetails): array {
      $sent = [];
      $notSent = [];
 -    $this->assign('module', 'Event Registration');
      $this->assignEventDetailsToTpl($params['event_id'], CRM_Utils_Array::value('role_id', $params), CRM_Utils_Array::value('receipt_text', $params));
 -    // @todo - this is no longer in core templates as of 5.63
 -    // we should remove once we have done a 'push upgrade' on addresses - ie advised
 -    // people to upgrade their templates in an upgrade message, as
 -    // opposed to just updating unmodified templates.
 -    $this->assign('isPrimary', (int) $this->_isPaidEvent);
 -    if ($this->_isPaidEvent) {
 -      $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
 -      if (!$this->_mode) {
 -        if (isset($params['payment_instrument_id'])) {
 -          $this->assign('paidBy',
 -            CRM_Utils_Array::value($params['payment_instrument_id'],
 -              $paymentInstrument
 -            )
 -          );
 -        }
 -      }
 -    }
  
 -    $this->assign('checkNumber', $params['check_number'] ?? NULL);
      if ($this->_mode) {
 -      $this->assignBillingName($params);
 -      $this->assign('address', CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters(
 -        $this->_params,
 -        $this->_bltID
 -      ));
 -
        $valuesForForm = CRM_Contribute_Form_AbstractEditPayment::formatCreditCardDetails($params);
        $this->assignVariables($valuesForForm, ['credit_card_exp_date', 'credit_card_type', 'credit_card_number']);
 -      $this->assign('is_pay_later', 0);
 -    }
 -
 -    $this->assign('register_date', $params['register_date']);
 -    if (isset($params['receive_date'])) {
 -      $this->assign('receive_date', $params['receive_date']);
      }
  
-     $customGroup = [];
-     $customFieldFilters = [
-       'ParticipantRole' => $this->getSubmittedValue('role_id'),
-       'ParticipantEventName' => $this->getEventID(),
-       'ParticipantEventType' => $this->getEventValue('event_type_id'),
-     ];
-     $customFields = CRM_Core_BAO_CustomField::getViewableCustomFields('Participant', $customFieldFilters);
-     foreach ($params['custom'] as $fieldID => $values) {
-       foreach ($values as $fieldValue) {
-         $formattedValue = CRM_Core_BAO_CustomField::displayValue($fieldValue['value'], $fieldID, $participants[0]->id);
-         $customGroup[$customFields[$fieldID]['custom_group_id.title']][$customFields[$fieldID]['label']] = str_replace('&nbsp;', '', $formattedValue);
-       }
-     }
-     $this->assign('customGroup', $customGroup);
      $fromEmails = CRM_Event_BAO_Event::getFromEmailIds($this->getEventID());
 -    foreach ($this->_contactIds as $num => $contactID) {
 -      // Retrieve the name and email of the contact - this will be the TO for receipt email
 -      [, $this->_contributorEmail, $this->_toDoNotEmail] = CRM_Contact_BAO_Contact::getContactDetails($contactID);
 -
 +    foreach ($participants as $num => $participant) {
 +      $participantID = $participant->id;
 +      $contactID = $participant->contact_id;
 +      $key = 'contact_' . $contactID;
 +
 +      $this->define('Contact', $key, ['id' => $contactID]);
 +      if (!$this->lookup($key, 'email_primary.email') || $this->lookup($key, 'do_not_email')) {
 +        // try to send emails only if email id is present
 +        // and the do-not-email option is not checked for that contact
 +        $notSent[] = $contactID;
 +        continue;
 +      }
        $waitStatus = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Waiting'");
        $waitingStatus = $waitStatus[$params['status_id']] ?? NULL;
        if ($waitingStatus) {