Add workflow template for offline event
authorEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 8 Mar 2022 01:54:35 +0000 (14:54 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Sat, 19 Mar 2022 02:19:49 +0000 (15:19 +1300)
This locks in availability of participant and event tokens
along with the standard smarty variables of {contactID},
{participantID} and {eventID}

CRM/Event/Form/Participant.php
CRM/Event/Form/ParticipantFeeSelection.php
CRM/Event/Tokens.php
CRM/Event/WorkflowMessage/EventOfflineReceipt.php [new file with mode: 0644]
CRM/Event/WorkflowMessage/ParticipantTrait.php
tests/phpunit/CRM/Event/Form/ParticipantTest.php
tests/phpunit/CRM/Utils/TokenConsistencyTest.php
tests/templates/message_templates/event_offline_receipt_text.tpl [new file with mode: 0644]

index e99eb186dfedc7c78a3ace5d54c52561da92cabb..510de2684949d0771bf7d05724e325aa70092fe2 100644 (file)
@@ -1499,7 +1499,6 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
                 }
               }
             }
-            $this->assign('totalTaxAmount', $totalTaxAmount);
             $this->assign('taxTerm', $this->getSalesTaxTerm());
             $this->assign('dataArray', $dataArray);
           }
@@ -1516,13 +1515,16 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
           $eventAmount = array_merge($eventAmount, $additionalParticipantDetails);
           $this->assign('amount', $eventAmount);
         }
-
+        $this->assign('totalTaxAmount', $totalTaxAmount ?? 0);
         $sendTemplateParams = [
-          'groupName' => 'msg_tpl_workflow_event',
-          'valueName' => 'event_offline_receipt',
+          'workflow' => 'event_offline_receipt',
           'contactId' => $contactID,
           'isTest' => !empty($this->_defaultValues['is_test']),
           'PDFFilename' => ts('confirmation') . '.pdf',
+          'modelProps' => [
+            'participantID' => $this->_id,
+            'eventID' => $params['event_id'],
+          ],
         ];
 
         // try to send emails only if email id is present
index 19a0a1174e424266d4a9171c47f5466d8cc0e7f7..ef254316500a230806fc8e7a5cc0d9c2202e8e7b 100644 (file)
@@ -358,14 +358,16 @@ class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form {
       $this->assign('isOnWaitlist', TRUE);
     }
     $this->assign('contactID', $this->_contactId);
-    $this->assign('participantID', $this->_participantId);
 
     $sendTemplateParams = [
-      'groupName' => 'msg_tpl_workflow_event',
-      'valueName' => 'event_offline_receipt',
+      'workflow' => 'event_offline_receipt',
       'contactId' => $this->_contactId,
       'isTest' => FALSE,
       'PDFFilename' => ts('confirmation') . '.pdf',
+      'modelProps' => [
+        'participantID' => $this->_participantId,
+        'eventID' => $params['event_id'],
+      ],
     ];
 
     // try to send emails only if email id is present
index 44afb797f114520d5dcd084986c0a906efbd9775..4b78ab400d74b5132b216e1c3cb4ad9305252dad 100644 (file)
@@ -175,10 +175,12 @@ class CRM_Event_Tokens extends CRM_Core_EntityTokens {
    *
    */
   protected function getExposedFields(): array {
-    return ['event_type_id',
+    return [
+      'event_type_id',
       'title',
       'id',
       'event_tz',
+      'pay_later_receipt',
       'start_date',
       'end_date',
       'summary',
diff --git a/CRM/Event/WorkflowMessage/EventOfflineReceipt.php b/CRM/Event/WorkflowMessage/EventOfflineReceipt.php
new file mode 100644 (file)
index 0000000..3b88596
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved.                        |
+ |                                                                    |
+ | This work is published under the GNU AGPLv3 license with some      |
+ | permitted exceptions and without any warranty. For full license    |
+ | and copyright information, see https://civicrm.org/licensing       |
+ +--------------------------------------------------------------------+
+ */
+
+use Civi\WorkflowMessage\GenericWorkflowMessage;
+
+/**
+ * Receipt sent when confirming a back office participation record.
+ *
+ * @support template-only
+ *
+ * @see CRM_Event_Form_Participant::submit()
+ * @see CRM_Event_Form_ParticipantFeeSelection::emailReceipt
+ */
+class CRM_Event_WorkflowMessage_EventOfflineReceipt extends GenericWorkflowMessage {
+  use CRM_Event_WorkflowMessage_ParticipantTrait;
+  public const WORKFLOW = 'event_offline_receipt';
+
+}
index 511e4a8df972be4b2b45d63043d3014f151cdc27..619bb6abdd7a107ab313f2843e80822117d83696 100644 (file)
@@ -8,8 +8,15 @@ trait CRM_Event_WorkflowMessage_ParticipantTrait {
   /**
    * @var int
    *
-   * @scope tokenContext as participantId
+   * @scope tokenContext as participantId, tplParams as participantID
    */
-  public $participantId;
+  public $participantID;
+
+  /**
+   * @var int
+   *
+   * @scope tokenContext as eventId, tplParams as eventID
+   */
+  public $eventID;
 
 }
index 80e654683a9d412662de48f4e665f18df697fc8c..33e303b76256a54a94bd7f5d32ecdea39ff62c57 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use Civi\Api4\Participant;
+
 /**
  *  Test CRM_Event_Form_Registration functions.
  *
@@ -21,19 +23,12 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase {
     parent::setUp();
   }
 
-  /**
-   * Should financials be checked after the test but before tear down.
-   *
-   * @var bool
-   */
-  protected $isValidateFinancialsOnPostAssert = TRUE;
-
   /**
    * Initial test of submit function.
    *
    * @throws \Exception
    */
-  public function testSubmit() {
+  public function testSubmit(): void {
     $form = $this->getForm();
     $form->submit([
       'register_date' => date('Ymd'),
@@ -262,8 +257,9 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase {
    * @dataProvider getThousandSeparators
    * @throws \Exception
    */
-  public function testParticipantOfflineReceipt($thousandSeparator) {
+  public function testParticipantOfflineReceipt(string $thousandSeparator): void {
     $this->setCurrencySeparators($thousandSeparator);
+    $this->swapMessageTemplateForTestTemplate('event_offline_receipt', 'text');
     $mut = new CiviMailUtils($this, TRUE);
     // Create an email associated with the logged in contact
     $loggedInContactID = $this->createLoggedInUser();
@@ -298,7 +294,7 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase {
 
     // Use the email created as the from email ensuring we are passing a numeric from to test dev/core#1069
     $this->setCurrencySeparators($thousandSeparator);
-    $form = $this->getForm(['is_monetary' => 1, 'financial_type_id' => 1]);
+    $form = $this->getForm(['is_monetary' => 1, 'financial_type_id' => 1, 'pay_later_receipt' => 'pay us']);
     $form->_mode = 'Live';
     $form->_quickConfig = TRUE;
     $form->_fromEmails = [
@@ -308,13 +304,24 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase {
     $submitParams = $this->getSubmitParamsForCreditCardPayment($paymentProcessorID);
     $submitParams['from_email_address'] = $email['id'];
     $form->submit($submitParams);
+    $participantID = Participant::get()->addWhere('event_id', '=', $this->getEventID())->execute()->first()['id'];
     //Check if type is correctly populated in mails.
     //Also check the string email is present not numeric from.
     $mut->checkMailLog([
+      'contactID:::' . $this->getContactID(),
+      'contact.id:::' . $this->getContactID(),
+      'eventID:::' . $this->getEventID(),
+      'event.id:::' . $this->getEventID(),
+      'participantID:::' . $participantID,
+      'participant.id:::' . $participantID,
       '<p>Test event type - 1</p>',
+      'event.title:::Annual CiviCRM meet',
+      'participant.status_id:name:::Registered',
       'testloggedinreceiptemail@civicrm.org',
+      'event.pay_later_receipt:::pay us',
       $this->formatMoneyInput(1550.55),
     ]);
+
     $this->callAPISuccess('Email', 'delete', ['id' => $email['id']]);
   }
 
index 0f625f4dd7993d91b22d265bf033b52618291979..cb922430ed9c0cc6d02afc58fa61366d89eb99bf 100644 (file)
@@ -619,6 +619,7 @@ Emerald City, Maine 90210
 
 event.info_url :' . CRM_Utils_System::url('civicrm/event/info', NULL, TRUE) . '&reset=1&id=1
 event.registration_url :' . CRM_Utils_System::url('civicrm/event/register', NULL, TRUE) . '&reset=1&id=1
+event.pay_later_receipt :
 event.custom_1 :my field
 ';
   }
@@ -904,6 +905,7 @@ December 21st, 2007
       '{event.location}' => 'Event Location',
       '{event.info_url}' => 'Event Info URL',
       '{event.registration_url}' => 'Event Registration URL',
+      '{event.pay_later_receipt}' => 'Pay Later Receipt Text',
       '{event.' . $this->getCustomFieldName('text') . '}' => 'Enter text here :: Group with field text',
     ];
   }
diff --git a/tests/templates/message_templates/event_offline_receipt_text.tpl b/tests/templates/message_templates/event_offline_receipt_text.tpl
new file mode 100644 (file)
index 0000000..99cd019
--- /dev/null
@@ -0,0 +1,10 @@
+contactID:::{$contactID}
+eventID:::{$eventID}
+participantID:::{$participantID}
+contact.id:::{contact.id}
+event.id:::{event.id}
+participant.id:::{participant.id}
+event.title:::{event.title}
+participant.status_id:name:::{participant.status_id:name}
+email:::{$email}
+event.pay_later_receipt:::{event.pay_later_receipt}