-
-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial Event Message Template previewability
- Loading branch information
1 parent
5493e78
commit 2f19b6e
Showing
14 changed files
with
164 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
xml/templates/message_templates/event_offline_receipt_subject.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
xml/templates/message_templates/event_online_receipt_subject.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters