From a7c0277bc9d3e8a48152e3eea0c065fb24926cac Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 18 May 2023 18:36:03 +1200 Subject: [PATCH] Clarify isPrimary, isPaidEvent --- CRM/Event/Form/Participant.php | 42 +++++---------- CRM/Event/Form/ParticipantFeeSelection.php | 51 +++++++++++++------ .../event_offline_receipt_html.tpl | 17 +++---- .../event_offline_receipt_text.tpl | 8 +-- 4 files changed, 56 insertions(+), 62 deletions(-) diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index a824a92bab..ed6038f5f5 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -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) { diff --git a/CRM/Event/Form/ParticipantFeeSelection.php b/CRM/Event/Form/ParticipantFeeSelection.php index 98378855d7..883048922a 100644 --- a/CRM/Event/Form/ParticipantFeeSelection.php +++ b/CRM/Event/Form/ParticipantFeeSelection.php @@ -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(), ], ]; diff --git a/xml/templates/message_templates/event_offline_receipt_html.tpl b/xml/templates/message_templates/event_offline_receipt_html.tpl index 5237c950fa..2d8fd66e1e 100644 --- a/xml/templates/message_templates/event_offline_receipt_html.tpl +++ b/xml/templates/message_templates/event_offline_receipt_html.tpl @@ -27,15 +27,11 @@ {/if} {if !empty($isOnWaitlist)} -

{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} +

{ts}You have been added to the WAIT LIST for this event.{/ts}

+

{ts}If space becomes available you will receive an email with a link to a web page where you can complete your registration.{/ts}

{elseif !empty($isRequireApproval)} -

{ts}Your registration has been submitted.{/ts}

- {if !empty($isPrimary)} +

{ts}Your registration has been submitted.{/ts}

{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} {elseif $is_pay_later}

{$pay_later_receipt}

{* FIXME: this might be text rather than HTML *} {/if} @@ -141,7 +137,7 @@ {/if} - {if !empty($event.is_monetary)} + {if {event.is_monetary|boolean}} @@ -152,7 +148,6 @@ {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. *} @@ -160,7 +155,7 @@ {/if} - {/if} + @@ -262,7 +257,7 @@ {/if} - {if !empty($isPrimary)} + {if {event.is_monetary|boolean}} {if {contribution.balance_amount|boolean}} diff --git a/xml/templates/message_templates/event_offline_receipt_text.tpl b/xml/templates/message_templates/event_offline_receipt_text.tpl index 95c1f1d539..99c4d04430 100644 --- a/xml/templates/message_templates/event_offline_receipt_text.tpl +++ b/xml/templates/message_templates/event_offline_receipt_text.tpl @@ -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)} @@ -19,10 +17,8 @@ {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} @@ -143,7 +139,7 @@ {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} -- 2.25.1
{ts}Total Paid{/ts}