Clarify isPrimary, isPaidEvent
authorEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 18 May 2023 06:36:03 +0000 (18:36 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 22 May 2023 20:01:13 +0000 (08:01 +1200)
CRM/Event/Form/Participant.php
CRM/Event/Form/ParticipantFeeSelection.php
xml/templates/message_templates/event_offline_receipt_html.tpl
xml/templates/message_templates/event_offline_receipt_text.tpl

index a824a92bab6f99ab014fdfd66565acb106468c4f..ed6038f5f5d14f9daf6a2114d18128b94149c725 100644 (file)
@@ -1680,11 +1680,10 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
    * @param $eventID
    * @param $participantRoles
    * @param $receiptText
-   * @param $isPaidEvent
    *
    * @return void
    */
-  protected function assignEventDetailsToTpl($eventID, $participantRoles, $receiptText, $isPaidEvent) {
+  protected function assignEventDetailsToTpl($eventID, $participantRoles, $receiptText) {
     //use of the message template below requires variables in different format
     $events = [];
     $returnProperties = ['event_type_id', 'fee_label', 'start_date', 'end_date', 'is_show_location', 'title'];
@@ -1707,7 +1706,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
     else {
       $event['participant_role'] = $role[$participantRoles] ?? NULL;
     }
-    $event['is_monetary'] = $isPaidEvent;
+    $event['is_monetary'] = $this->_isPaidEvent;
 
     if ($receiptText) {
       $event['confirm_email_text'] = $receiptText;
@@ -1966,26 +1965,6 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
     return $this->_id ?: NULL;
   }
 
-  /**
-   * Get the contribution ID associated with the participant record.
-   *
-   *
-   * @api This function will not change in a minor release and is supported for
-   * use outside of core. This annotation / external support for properties
-   * is only given where there is specific test cover.
-   *
-   * @return int|null
-   * @throws \CRM_Core_Exception
-   */
-  public function getContributionID(): ?int {
-    if (!isset($this->contributionID)) {
-      $this->contributionID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment',
-        $this->getParticipantID(), 'contribution_id', 'participant_id'
-      );
-    }
-    return $this->contributionID;
-  }
-
   /**
    * Get the value for the revenue recognition date field.
    *
@@ -2139,8 +2118,12 @@ INNER JOIN civicrm_price_field_value value ON ( value.id = lineItem.price_field_
     $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), $this->_isPaidEvent);
-
+    $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) {
@@ -2154,7 +2137,6 @@ INNER JOIN civicrm_price_field_value value ON ( value.id = lineItem.price_field_
       }
 
       $this->assign('totalAmount', $params['total_amount'] ?? $total_amount);
-      $this->assign('isPrimary', 1);
       $this->assign('checkNumber', CRM_Utils_Array::value('check_number', $params));
     }
     if ($this->_mode) {
@@ -2167,7 +2149,6 @@ INNER JOIN civicrm_price_field_value value ON ( value.id = lineItem.price_field_
       $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('isPrimary', 1);
     }
 
     $this->assign('register_date', $params['register_date']);
@@ -2203,6 +2184,9 @@ INNER JOIN civicrm_price_field_value value ON ( value.id = lineItem.price_field_
       $this->assign('contactID', $contactID);
       $this->assign('participantID', $participants[$num]->id);
 
+      $contributionID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment',
+        $participants[$num]->id, 'contribution_id', 'participant_id'
+      );
       $this->_id = $participants[$num]->id;
 
       if ($this->_isPaidEvent) {
@@ -2255,7 +2239,7 @@ INNER JOIN civicrm_price_field_value value ON ( value.id = lineItem.price_field_
         'modelProps' => [
           'participantID' => $this->_id,
           'eventID' => $params['event_id'],
-          'contributionID' => $this->getContributionID(),
+          'contributionID' => $contributionID,
         ],
       ];
 
@@ -2274,7 +2258,7 @@ INNER JOIN civicrm_price_field_value value ON ( value.id = lineItem.price_field_
       $taxAmt = $template->get_template_vars('dataArray');
       if (Civi::settings()->get('invoice_is_email_pdf')) {
         $sendTemplateParams['isEmailPdf'] = TRUE;
-        $sendTemplateParams['contributionId'] = $this->getContributionID();
+        $sendTemplateParams['contributionId'] = $contributionID;
       }
       [$mailSent, $subject, $message, $html] = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
       if ($mailSent) {
index 98378855d7795cab8e2394ab3c7a2ed0aeeaa0f5..883048922a78011d9b39304c053fab18e149b4ed 100644 (file)
@@ -32,7 +32,7 @@ class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form {
 
   protected $_toDoNotEmail = NULL;
 
-  protected $_contributionId = NULL;
+  protected $contributionID;
 
   protected $fromEmailId = NULL;
 
@@ -58,14 +58,7 @@ class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form {
     $this->_eventId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_participantId, 'event_id');
     $this->_fromEmails = CRM_Event_BAO_Event::getFromEmailIds($this->_eventId);
 
-    $this->_contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_participantId, 'contribution_id', 'participant_id');
-    if (!$this->_contributionId) {
-      if ($primaryParticipantId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $this->_participantId, 'registered_by_id')) {
-        $this->_contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantPayment', $primaryParticipantId, 'contribution_id', 'participant_id');
-      }
-    }
-
-    if ($this->_contributionId) {
+    if ($this->getContributionID()) {
       $this->_isPaidEvent = TRUE;
     }
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, TRUE);
@@ -86,9 +79,9 @@ class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form {
     $this->assign('paymentInfo', $paymentInfo);
     $this->assign('feePaid', $this->_paidAmount);
 
-    $ids = CRM_Event_BAO_Participant::getParticipantIds($this->_contributionId);
+    $ids = CRM_Event_BAO_Participant::getParticipantIds($this->getContributionID());
     if (count($ids) > 1) {
-      $total = CRM_Price_BAO_LineItem::getLineTotal($this->_contributionId);
+      $total = CRM_Price_BAO_LineItem::getLineTotal($this->getContributionID());
       $this->assign('totalLineTotal', $total);
       $this->assign('lineItemTotal', $total);
     }
@@ -99,6 +92,29 @@ class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form {
     }
   }
 
+  /**
+   * Get the contribution ID.
+   *
+   * @api This function will not change in a minor release and is supported for
+   * use outside of core. This annotation / external support for properties
+   * is only given where there is specific test cover.
+   *
+   * @noinspection PhpUnhandledExceptionInspection
+   */
+  public function getContributionID(): ?int {
+    if ($this->contributionID === NULL) {
+      $this->contributionID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_participantId, 'contribution_id', 'participant_id') ?: FALSE;
+
+      if (!$this->contributionID) {
+        $primaryParticipantID = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $this->_participantId, 'registered_by_id');
+        if ($primaryParticipantID) {
+          $this->contributionID = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantPayment', $primaryParticipantID, 'contribution_id', 'participant_id') ?: FALSE;
+        }
+      }
+    }
+    return $this->contributionID ?: NULL;
+  }
+
   /**
    * Set default values for the form.
    *
@@ -231,8 +247,8 @@ class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form {
 
     $feeBlock = $this->_values['fee'];
     $lineItems = $this->_values['line_items'];
-    CRM_Price_BAO_LineItem::changeFeeSelections($params, $this->_participantId, 'participant', $this->_contributionId, $feeBlock, $lineItems);
-    $this->contributionAmt = CRM_Core_DAO::getFieldValue('CRM_Contribute_BAO_Contribution', $this->_contributionId, 'total_amount');
+    CRM_Price_BAO_LineItem::changeFeeSelections($params, $this->_participantId, 'participant', $this->getContributionID(), $feeBlock, $lineItems);
+    $this->contributionAmt = CRM_Core_DAO::getFieldValue('CRM_Contribute_BAO_Contribution', $this->getContributionID(), 'total_amount');
     // email sending
     if (!empty($params['send_receipt'])) {
       $fetchParticipantVals = ['id' => $this->_participantId];
@@ -332,11 +348,13 @@ class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form {
       }
 
       $this->assign('totalAmount', $this->contributionAmt);
-
-      $this->assign('isPrimary', 1);
       $this->assign('checkNumber', CRM_Utils_Array::value('check_number', $params));
     }
-
+    // @todo isPrimary no longer used from 5.63 in core templates, remove
+    // once users have been 'pushed' to update their templates (via
+    // upgrade message - which we don't always do whenever we change
+    // a minor variable.
+    $this->assign('isPrimary', $this->_isPaidEvent);
     $this->assign('register_date', $params['register_date']);
 
     // Retrieve the name and email of the contact - this will be the TO for receipt email
@@ -356,6 +374,7 @@ class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form {
       'modelProps' => [
         'participantID' => $this->_participantId,
         'eventID' => $params['event_id'],
+        'contributionID' => $this->getContributionID(),
       ],
     ];
 
index 5237c950fa373a3d888f3fde7889cca7b6f1682e..2d8fd66e1e3f3386dd9e1e1f439d6ab248284988 100644 (file)
     {/if}
 
     {if !empty($isOnWaitlist)}
-     <p>{ts}You have been added to the WAIT LIST for this event.{/ts}</p>
-     {if !empty($isPrimary)}
-       <p>{ts}If space becomes available you will receive an email with a link to a web page where you can complete your registration.{/ts}</p>
-     {/if}
+      <p>{ts}You have been added to the WAIT LIST for this event.{/ts}</p>
+      <p>{ts}If space becomes available you will receive an email with a link to a web page where you can complete your registration.{/ts}</p>
     {elseif !empty($isRequireApproval)}
-     <p>{ts}Your registration has been submitted.{/ts}</p>
-     {if !empty($isPrimary)}
+      <p>{ts}Your registration has been submitted.{/ts}</p>
       <p>{ts}Once your registration has been reviewed, you will receive an email with a link to a web page where you can complete the registration process.{/ts}</p>
-     {/if}
     {elseif $is_pay_later}
      <p>{$pay_later_receipt}</p> {* FIXME: this might be text rather than HTML *}
     {/if}
      {/if}
 
 
-     {if !empty($event.is_monetary)}
+     {if {event.is_monetary|boolean}}
 
       <tr>
        <th {$headerStyle}>
       {if !empty($lineItem)}
        {foreach from=$lineItem item=value key=priceset}
         {if $value neq 'skip'}
-         {if !empty($isPrimary)}
           {if $lineItem|@count GT 1} {* Header for multi participant registration cases. *}
            <tr>
             <td colspan="2" {$labelStyle}>
             </td>
            </tr>
           {/if}
-         {/if}
+
          <tr>
           <td colspan="2" {$valueStyle}>
            <table>
         </td>
        </tr>
       {/if}
-      {if !empty($isPrimary)}
+      {if {event.is_monetary|boolean}}
        {if {contribution.balance_amount|boolean}}
          <tr>
            <td {$labelStyle}>{ts}Total Paid{/ts}</td>
index 95c1f1d5396b531873ca4ff14881068b37c62883..99c4d04430661e2c47bf6464a1e9e493b79cd096 100644 (file)
@@ -8,10 +8,8 @@
 
 {ts}You have been added to the WAIT LIST for this event.{/ts}
 
-{if !empty($isPrimary)}
 {ts}If space becomes available you will receive an email with a link to a web page where you can complete your registration.{/ts}
 
-{/if}
 ==========================================================={if !empty($pricesetFieldsCount) }===================={/if}
 
 {elseif !empty($isRequireApproval)}
 
 {ts}Your registration has been submitted.{/ts}
 
-{if !empty($isPrimary)}
 {ts}Once your registration has been reviewed, you will receive an email with a link to a web page where you can complete the registration process.{/ts}
 
-{/if}
 ==========================================================={if !empty($pricesetFieldsCount) }===================={/if}
 
 {elseif $is_pay_later}
@@ -93,7 +89,7 @@
 {if !empty($lineItem)}{foreach from=$lineItem item=value key=priceset}
 
 {if $value neq 'skip'}
-{if !empty($isPrimary)}
+{if {event.is_monetary|boolean}}
 {if $lineItem|@count GT 1} {* Header for multi participant registration cases. *}
 {ts 1=$priceset+1}Participant %1{/ts}
 {/if}
 {if $totalTaxAmount}
 {ts}Total Tax Amount{/ts}: {$totalTaxAmount|crmMoney:$currency}
 {/if}
-{if !empty($isPrimary)}
+{if {event.is_monetary|boolean}}
 
 {if {contribution.balance_amount|boolean}}{ts}Total Paid{/ts}: {if {contribution.paid_amount|boolean}}{contribution.paid_amount}{/if} {if !empty($hookDiscount.message)}({$hookDiscount.message}){/if}
 {ts}Balance{/ts}: {contribution.balance_amount}