Skip to content

Commit

Permalink
Add initial Event Message Template previewability
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Aug 20, 2022
1 parent 5493e78 commit 2f19b6e
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 13 deletions.
1 change: 1 addition & 0 deletions CRM/Case/Workflow/ActivityExample.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
1 change: 1 addition & 0 deletions CRM/Case/Workflow/CaseActivity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
5 changes: 4 additions & 1 deletion CRM/Event/BAO/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -1189,12 +1189,15 @@ public static function sendMail($contactID, $values, $participantId, $isTest = F
}

$sendTemplateParams = [
'groupName' => 'msg_tpl_workflow_event',
'workflow' => 'event_online_receipt',
'contactId' => $contactID,
'isTest' => $isTest,
'tplParams' => $tplParams,
'PDFFilename' => ts('confirmation') . '.pdf',
'modelProps' => [
'participantID' => (int) $participantId,
'eventID' => (int) $values['event']['id'],
],
];

// address required during receipt processing (pdf and email receipt)
Expand Down
5 changes: 4 additions & 1 deletion CRM/Event/Form/SelfSvcTransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ public function participantTransfer($participant): void {
];

$sendTemplateParams = [
'groupName' => 'msg_tpl_workflow_event',
'workflow' => 'event_online_receipt',
'contactId' => $participantDetails[$participant->id]['contact_id'],
'tplParams' => $tplParams,
Expand All @@ -407,6 +406,10 @@ public function participantTransfer($participant): void {
'toEmail' => $toEmail,
'cc' => $eventDetails['cc_confirm'] ?? NULL,
'bcc' => $eventDetails['bcc_confirm'] ?? NULL,
'modelProps' => [
'participantID' => $participant->id,
'eventID' => $participant->event_id,
],
];
CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
}
Expand Down
107 changes: 107 additions & 0 deletions CRM/Event/WorkflowMessage/EventExamples.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

use Civi\Api4\PriceSetEntity;
use Civi\Api4\WorkflowMessage;
use Civi\WorkflowMessage\GenericWorkflowMessage;
use Civi\WorkflowMessage\WorkflowMessageExample;

/**
* Basic contribution example for contribution templates.
*
* @noinspection PhpUnused
*/
class CRM_Event_WorkflowMessage_EventExamples extends WorkflowMessageExample {

/**
* Get the examples this class is able to deliver.
*
* @throws \API_Exception
*/
public function getExamples(): iterable {
$workflows = ['event_online_receipt', 'event_offline_receipt'];
foreach ($workflows as $workflow) {
$priceSets = $this->getPriceSets();
foreach ($priceSets as $priceSet) {
yield [
'name' => 'workflow/' . $workflow . '/' . 'price_set_' . $priceSet['name'],
'title' => ts('Completed Registration') . ' : ' . $priceSet['title'],
'tags' => ['preview'],
'workflow' => $workflow,
'is_show_line_items' => !$priceSet['is_quick_config'],
'event_id' => $priceSet['event_id'],
];
}
}
}

/**
* Build an example to use when rendering the workflow.
*
* @param array $example
*
* @throws \API_Exception
*/
public function build(array &$example): void {
$workFlow = WorkflowMessage::get(TRUE)->addWhere('name', '=', $example['workflow'])->execute()->first();
$this->setWorkflowName($workFlow['name']);
$messageTemplate = new $workFlow['class']();
$this->addExampleData($messageTemplate, $example);
$example['data'] = $this->toArray($messageTemplate);
}

/**
* Add relevant example data.
*
* @param \CRM_Event_WorkflowMessage_EventOnlineReceipt|\CRM_Event_WorkflowMessage_EventOfflineReceipt $messageTemplate
* @param array $example
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
private function addExampleData(GenericWorkflowMessage $messageTemplate, $example): void {
$messageTemplate->setContact(\Civi\Test::example('entity/Contact/Barb'));
$messageTemplate->setEventID($example['event_id']);
}

/**
* Get prices sets from the site - ideally one quick config & one not.
*
* @return array
*
* @throws \API_Exception
*/
private function getPriceSets(): ?array {
// Permission check defaults to true - likely implicitly OK but may need to be false.
$quickConfigPriceSet = $this->getPriceSet(TRUE);
$nonQuickConfigPriceSet = $this->getPriceSet(FALSE);

return array_filter([$quickConfigPriceSet, $nonQuickConfigPriceSet]);
}

/**
* @param $isQuickConfig
*
* @return array|null
* @throws \API_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
private function getPriceSet(bool $isQuickConfig): ?array {
$priceSetEntity = PriceSetEntity::get()
->addWhere('entity_table', '=', 'civicrm_event')
->addSelect('price_set_id.id', 'entity_id', 'price_set_id.is_quick_config', 'price_set_id.name', 'price_set_id.title')
->setLimit(1)
->addWhere('price_set_id.is_quick_config', '=', $isQuickConfig)
->execute()->first();

return empty($priceSetEntity) ? NULL : [
'id' => $priceSetEntity['price_set_id'],
'name' => $priceSetEntity['price_set_id.name'],
'title' => $priceSetEntity['price_set_id.title'],
'event_id' => $priceSetEntity['entity_id'],
'is_quick_config' => $priceSetEntity['price_set_id.is_quick_config'],
];
}

}
26 changes: 26 additions & 0 deletions CRM/Event/WorkflowMessage/EventOnlineReceipt.php
Original file line number Diff line number Diff line change
@@ -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_BAO_Event::sendMail()
* @see \CRM_Event_Form_SelfSvcTransfer::participantTransfer
*/
class CRM_Event_WorkflowMessage_EventOnlineReceipt extends GenericWorkflowMessage {
use CRM_Event_WorkflowMessage_ParticipantTrait;
public const WORKFLOW = 'event_online_receipt';

}
10 changes: 10 additions & 0 deletions CRM/Event/WorkflowMessage/ParticipantTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,14 @@ trait CRM_Event_WorkflowMessage_ParticipantTrait {
*/
public $eventID;

/**
* @param int $eventID
*
* @return CRM_Event_WorkflowMessage_ParticipantTrait
*/
public function setEventID(int $eventID) {
$this->eventID = $eventID;
return $this;
}

}
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function testSubmit(): void {
*
* @dataProvider getThousandSeparators
*/
public function testPaidSubmit($thousandSeparator) {
public function testPaidSubmit(string $thousandSeparator): void {
// @todo - figure out why this doesn't pass validate financials
$this->isValidateFinancialsOnPostAssert = FALSE;
$this->setCurrencySeparators($thousandSeparator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
</tr>
<tr>
<td colspan="2" {$valueStyle}>
{$event.event_title}<br />
{$event.event_start_date|crmDate}{if $event.event_end_date}-{if $event.event_end_date|crmDate:"%Y%m%d" == $event.event_start_date|crmDate:"%Y%m%d"}{$event.event_end_date|crmDate:0:1}{else}{$event.event_end_date|crmDate}{/if}{/if}
{event.title}<br />
{event.start_date|crmDate}{if $event.event_end_date}-{if $event.event_end_date|crmDate:"%Y%m%d" == $event.event_start_date|crmDate:"%Y%m%d"}{$event.event_end_date|crmDate:0:1}{else}{$event.event_end_date|crmDate}{/if}{/if}
</td>
</tr>

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ts}Event Confirmation{/ts} - {$event.title} - {contact.display_name}
{ts}Event Confirmation{/ts} - {event.title} - {contact.display_name}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@

==========================================================={if !empty($pricesetFieldsCount) }===================={/if}

{$event.event_title}
{$event.event_start_date|crmDate}{if $event.event_end_date}-{if $event.event_end_date|crmDate:"%Y%m%d" == $event.event_start_date|crmDate:"%Y%m%d"}{$event.event_end_date|crmDate:0:1}{else}{$event.event_end_date|crmDate}{/if}{/if}
{event.title}
{event.start_date|crmDate}{if $event.event_end_date}-{if $event.event_end_date|crmDate:"%Y%m%d" == $event.event_start_date|crmDate:"%Y%m%d"}{$event.event_end_date|crmDate:0:1}{else}{$event.event_end_date|crmDate}{/if}{/if}

{if !empty($event.participant_role) and $event.participant_role neq 'Attendee' and empty($defaultRole)}
{ts}Participant Role{/ts}: {$event.participant_role}
Expand Down
4 changes: 2 additions & 2 deletions xml/templates/message_templates/event_online_receipt_html.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
</tr>
<tr>
<td colspan="2" {$valueStyle}>
{$event.event_title}<br />
{$event.event_start_date|crmDate:"%A"} {$event.event_start_date|crmDate}{if $event.event_end_date}-{if $event.event_end_date|crmDate:"%Y%m%d" == $event.event_start_date|crmDate:"%Y%m%d"}{$event.event_end_date|crmDate:0:1}{else}{$event.event_end_date|crmDate:"%A"} {$event.event_end_date|crmDate}{/if}{/if}
{event.title}<br />
{event.start_date|crmDate:"%A"} {event.start_date|crmDate}{if $event.event_end_date}-{if $event.event_end_date|crmDate:"%Y%m%d" == $event.event_start_date|crmDate:"%Y%m%d"}{$event.event_end_date|crmDate:0:1}{else}{$event.event_end_date|crmDate:"%A"} {$event.event_end_date|crmDate}{/if}{/if}
</td>
</tr>

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{if !empty($isOnWaitlist)}{ts}Wait List Confirmation{/ts}{elseif !empty($isRequireApproval)}{ts}Registration Request Confirmation{/ts}{else}{ts}Registration Confirmation{/ts}{/if} - {$event.event_title} - {contact.display_name}
{if !empty($isOnWaitlist)}{ts}Wait List Confirmation{/ts}{elseif !empty($isRequireApproval)}{ts}Registration Request Confirmation{/ts}{else}{ts}Registration Confirmation{/ts}{/if} - {event.title} - {contact.display_name}
4 changes: 2 additions & 2 deletions xml/templates/message_templates/event_online_receipt_text.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@

==========================================================={if !empty($pricesetFieldsCount)}===================={/if}

{$event.event_title}
{$event.event_start_date|crmDate:"%A"} {$event.event_start_date|crmDate}{if $event.event_end_date}-{if $event.event_end_date|crmDate:"%Y%m%d" == $event.event_start_date|crmDate:"%Y%m%d"}{$event.event_end_date|crmDate:0:1}{else}{$event.event_end_date|crmDate:"%A"} {$event.event_end_date|crmDate}{/if}{/if}
{event.title}
{event.start_date|crmDate:"%A"} {event.start_date|crmDate}{if $event.event_end_date}-{if $event.event_end_date|crmDate:"%Y%m%d" == $event.event_start_date|crmDate:"%Y%m%d"}{$event.event_end_date|crmDate:0:1}{else}{$event.event_end_date|crmDate:"%A"} {$event.event_end_date|crmDate}{/if}{/if}
{if !empty($conference_sessions)}


Expand Down

0 comments on commit 2f19b6e

Please sign in to comment.