From e80f22617fb40dfcc5c1597507edc99983aeb6c6 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 29 Sep 2021 07:31:03 +1300 Subject: [PATCH] Participant tokens on scheduled reminders (wip- upgrade script needed at minimum) --- CRM/Admin/Form/ScheduleReminders.php | 2 +- CRM/Contact/Form/Task/EmailTrait.php | 2 +- CRM/Core/EntityTokens.php | 82 +++++++++- CRM/Core/SelectValues.php | 27 ++-- CRM/Event/ParticipantTokens.php | 63 ++++++++ CRM/Event/Tokens.php | 84 ++-------- .../Incremental/php/FiveFortyThree.php | 15 ++ .../CRM/Utils/TokenConsistencyTest.php | 143 +++++++++++++++--- 8 files changed, 298 insertions(+), 120 deletions(-) diff --git a/CRM/Admin/Form/ScheduleReminders.php b/CRM/Admin/Form/ScheduleReminders.php index 7218283ed3..40ae4aa356 100644 --- a/CRM/Admin/Form/ScheduleReminders.php +++ b/CRM/Admin/Form/ScheduleReminders.php @@ -698,7 +698,7 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { $tokenProcessor = new \Civi\Token\TokenProcessor(\Civi::dispatcher(), [ 'controller' => get_class(), 'smarty' => FALSE, - 'schema' => ['activityId'], + 'schema' => ['activityId', 'participantId'], ]); $tokens = $tokenProcessor->listTokens(); diff --git a/CRM/Contact/Form/Task/EmailTrait.php b/CRM/Contact/Form/Task/EmailTrait.php index 10054718f5..5ce268803d 100644 --- a/CRM/Contact/Form/Task/EmailTrait.php +++ b/CRM/Contact/Form/Task/EmailTrait.php @@ -511,7 +511,7 @@ trait CRM_Contact_Form_Task_EmailTrait { * * @return array */ - public function listTokens() { + public function listTokens(): array { return CRM_Core_SelectValues::contactTokens(); } diff --git a/CRM/Core/EntityTokens.php b/CRM/Core/EntityTokens.php index 2901360468..e8b5362ca6 100644 --- a/CRM/Core/EntityTokens.php +++ b/CRM/Core/EntityTokens.php @@ -11,6 +11,7 @@ */ use Civi\Token\AbstractTokenSubscriber; +use Civi\Token\Event\TokenRegisterEvent; use Civi\Token\Event\TokenValueEvent; use Civi\Token\TokenRow; use Civi\ActionSchedule\Event\MailingQueryEvent; @@ -33,6 +34,27 @@ class CRM_Core_EntityTokens extends AbstractTokenSubscriber { */ protected $prefetch = []; + /** + * Register the declared tokens. + * + * @param \Civi\Token\Event\TokenRegisterEvent $e + * The registration event. Add new tokens using register(). + */ + public function registerTokens(TokenRegisterEvent $e) { + if (!$this->checkActive($e->getTokenProcessor())) { + return; + } + foreach ($this->getAllTokens() as $name => $label) { + if (!in_array($name, $this->getHiddenTokens(), TRUE)) { + $e->register([ + 'entity' => $this->entity, + 'field' => $name, + 'label' => $label, + ]); + } + } + } + /** * @inheritDoc * @throws \CRM_Core_Exception @@ -56,6 +78,10 @@ class CRM_Core_EntityTokens extends AbstractTokenSubscriber { return $row->tokens($entity, $field, $this->getPseudoValue($split[0], $split[1], $this->getFieldValue($row, $split[0]))); } if ($this->isCustomField($field)) { + $prefetchedValue = $this->getCustomFieldValue($this->getFieldValue($row, 'id'), $field); + if ($prefetchedValue) { + return $row->format('text/html')->tokens($entity, $field, $prefetchedValue); + } return $row->customToken($entity, \CRM_Core_BAO_CustomField::getKeyID($field), $this->getFieldValue($row, 'id')); } if ($this->isMoneyField($field)) { @@ -148,7 +174,7 @@ class CRM_Core_EntityTokens extends AbstractTokenSubscriber { unset($basicTokens[$fieldName]); } } - return array_merge($basicTokens, $this->getPseudoTokens(), CRM_Utils_Token::getCustomFieldTokens($this->getApiEntityName())); + return array_merge($basicTokens, $this->getPseudoTokens(), $this->getBespokeTokens(), CRM_Utils_Token::getCustomFieldTokens($this->getApiEntityName())); } /** @@ -246,6 +272,13 @@ class CRM_Core_EntityTokens extends AbstractTokenSubscriber { return $return; } + /** + * Get any tokens with custom calculation. + */ + public function getBespokeTokens(): array { + return []; + } + /** * Is this a field we should add pseudo-tokens to? * @@ -256,7 +289,7 @@ class CRM_Core_EntityTokens extends AbstractTokenSubscriber { * @param string $fieldName */ public function isAddPseudoTokens($fieldName): bool { - if ($fieldName === 'currency') { + if (in_array($fieldName, $this->getCurrencyFieldName())) { // 'currency' is manually added to the skip list as an anomaly. // name & label aren't that suitable for 'currency' (symbol, which // possibly maps to 'abbr' would be) and we can't gather that @@ -314,6 +347,9 @@ class CRM_Core_EntityTokens extends AbstractTokenSubscriber { return $actionSearchResult->{$aliasedField}; } $entityID = $row->context[$this->getEntityIDField()]; + if ($field === 'id') { + return $entityID; + } return $this->prefetch[$entityID][$field] ?? ''; } @@ -353,6 +389,17 @@ class CRM_Core_EntityTokens extends AbstractTokenSubscriber { } } + /** + * Get tokens to be suppressed from the widget. + * + * Note this is expected to be an interim function. Now we are no + * longer working around the parent function we can just define them once... + * with metadata, in a future refactor. + */ + protected function getHiddenTokens(): array { + return []; + } + /** * Get tokens supporting the syntax we are migrating to. * @@ -488,4 +535,35 @@ class CRM_Core_EntityTokens extends AbstractTokenSubscriber { return []; } + /** + * Get the apiv4 style custom field name. + * + * @param int $id + * + * @return string + */ + protected function getCustomFieldName(int $id): string { + foreach ($this->getFieldMetadata() as $key => $field) { + if (($field['custom_field_id'] ?? NULL) === $id) { + return $key; + } + } + } + + /** + * @param $entityID + * @param string $field eg. 'custom_1' + * + * @return array|string|void|null $mixed + * + * @throws \CRM_Core_Exception + */ + protected function getCustomFieldValue($entityID, string $field) { + $id = str_replace('custom_', '', $field); + $value = $this->prefetch[$entityID][$this->getCustomFieldName($id)] ?? NULL; + if ($value !== NULL) { + return CRM_Core_BAO_CustomField::displayValue($value, $id); + } + } + } diff --git a/CRM/Core/SelectValues.php b/CRM/Core/SelectValues.php index b0e5f24d51..ab9f1892ba 100644 --- a/CRM/Core/SelectValues.php +++ b/CRM/Core/SelectValues.php @@ -590,28 +590,19 @@ class CRM_Core_SelectValues { /** * Different type of Participant Tokens. * + * @deprecated + * * @return array */ public static function participantTokens(): array { - $tokens = [ - '{participant.status_id}' => 'Status ID', - '{participant.role_id}' => 'Participant Role (ID)', - '{participant.register_date}' => 'Register date', - '{participant.source}' => 'Participant Source', - '{participant.fee_level}' => 'Fee level', - '{participant.fee_amount}' => 'Fee Amount', - '{participant.registered_by_id}' => 'Registered By Participant ID', - '{participant.transferred_to_contact_id}' => 'Transferred to Contact ID', - '{participant.role_id:label}' => 'Participant Role (label)', - '{participant.fee_label}' => 'Fee Label', - ]; - $customFields = CRM_Core_BAO_CustomField::getFields('Participant'); - - foreach ($customFields as $customField) { - $tokens['{participant.custom_' . $customField['id'] . '}'] = $customField['label'] . " :: " . $customField['groupTitle']; + $tokenProcessor = new TokenProcessor(Civi::dispatcher(), ['schema' => ['participantId']]); + $allTokens = $tokenProcessor->listTokens(); + foreach (array_keys($allTokens) as $token) { + if (strpos($token, '{domain.') === 0) { + unset($allTokens[$token]); + } } - - return $tokens; + return $allTokens; } /** diff --git a/CRM/Event/ParticipantTokens.php b/CRM/Event/ParticipantTokens.php index 717b11756f..e132d8faa1 100644 --- a/CRM/Event/ParticipantTokens.php +++ b/CRM/Event/ParticipantTokens.php @@ -10,6 +10,8 @@ +--------------------------------------------------------------------+ */ +use Civi\Token\TokenRow; + /** * Class CRM_Event_ParticipantTokens * @@ -17,6 +19,13 @@ */ class CRM_Event_ParticipantTokens extends CRM_Core_EntityTokens { + public static function getSubscribedEvents() { + $events = parent::getSubscribedEvents(); + // Set the weight so it runs before event tokens. + $events['civi.token.eval'] = ['evaluateTokens', 400]; + return $events; + } + /** * Get the entity name for api v4 calls. * @@ -33,4 +42,58 @@ class CRM_Event_ParticipantTokens extends CRM_Core_EntityTokens { return ['fee_currency']; } + /** + * Get any tokens with custom calculation. + */ + public function getBespokeTokens(): array { + return ['balance' => ts('Event Balance')]; + } + + /** + * @inheritDoc + * @throws \CiviCRM_API3_Exception + */ + public function evaluateToken(TokenRow $row, $entity, $field, $prefetch = NULL) { + $this->prefetch = (array) $prefetch; + if (empty($row->context['eventId'])) { + $row->context['eventId'] = $this->getFieldValue($row, 'event_id'); + } + if ($field === 'balance') { + // @todo - is this really a good idea to call this & potentially get the + // balance of the contribution attached to 'registered_by_id' + $info = \CRM_Contribute_BAO_Contribution::getPaymentInfo($this->getFieldValue($row, 'id'), 'event'); + $balancePay = $info['balance'] ?? NULL; + $balancePay = \CRM_Utils_Money::format($balancePay); + $row->tokens($entity, $field, $balancePay); + return; + } + parent::evaluateToken($row, $entity, $field, $prefetch); + } + + /** + * Do not show event id in the UI as event.id will also be available. + * + * Discount id is probably a bit esoteric. + * + * @return string[] + */ + protected function getHiddenTokens(): array { + return ['event_id', 'discount_id']; + } + + /** + * Get entity fields that should not be exposed as tokens. + * + * @return string[] + */ + public function getSkippedFields(): array { + $fields = parent::getSkippedFields(); + // Never add these 2 fields - may not be a stable part of the schema. + // This field is on it's way out of core. + $fields[] = 'cart_id'; + // this will probably get schema changed out of the table at some point. + $fields[] = 'is_pay_later'; + return $fields; + } + } diff --git a/CRM/Event/Tokens.php b/CRM/Event/Tokens.php index ab40f43967..061e7197fa 100644 --- a/CRM/Event/Tokens.php +++ b/CRM/Event/Tokens.php @@ -10,8 +10,8 @@ +--------------------------------------------------------------------+ */ -use Civi\ActionSchedule\Event\MailingQueryEvent; use Civi\Api4\Event; +use Civi\Token\TokenRow; /** * Class CRM_Event_Tokens @@ -44,9 +44,9 @@ class CRM_Event_Tokens extends CRM_Core_EntityTokens { public function getAllTokens(): array { return array_merge( [ - 'event_type' => ts('Event Type'), + 'event_type_id:label' => ts('Event Type'), 'title' => ts('Event Title'), - 'event_id' => ts('Event ID'), + 'id' => ts('Event ID'), 'start_date' => ts('Event Start Date'), 'end_date' => ts('Event End Date'), 'summary' => ts('Event Summary'), @@ -54,10 +54,8 @@ class CRM_Event_Tokens extends CRM_Core_EntityTokens { 'location' => ts('Event Location'), 'info_url' => ts('Event Info URL'), 'registration_url' => ts('Event Registration URL'), - 'fee_amount' => ts('Event Fee'), 'contact_email' => ts('Event Contact Email'), 'contact_phone' => ts('Event Contact Phone'), - 'balance' => ts('Event Balance'), ], CRM_Utils_Token::getCustomFieldTokens('Event') ); @@ -65,78 +63,17 @@ class CRM_Event_Tokens extends CRM_Core_EntityTokens { /** * @inheritDoc + * @throws \API_Exception */ - public function checkActive(\Civi\Token\TokenProcessor $processor) { - // Extracted from scheduled-reminders code. See the class description. - return ((!empty($processor->context['actionMapping']) - && $processor->context['actionMapping']->getEntity() === 'civicrm_participant')) - || in_array($this->getEntityIDField(), $processor->context['schema'], TRUE); - } - - /** - * Alter action schedule query. - * - * @param \Civi\ActionSchedule\Event\MailingQueryEvent $e - */ - public function alterActionScheduleQuery(MailingQueryEvent $e): void { - if ($e->mapping->getEntity() !== 'civicrm_participant') { - return; + public function evaluateToken(TokenRow $row, $entity, $field, $prefetch = NULL) { + $eventID = $this->getFieldValue($row, 'id'); + if (!$eventID) { + $eventID = $row->context['actionSearchResult']->event_id; } - - // FIXME: seems too broad. - $e->query->select('e.*'); - $e->query->select('ov.label as event_type, ev.title, ev.id as event_id, ev.start_date, ev.end_date, ev.summary, ev.description, address.street_address, address.city, address.state_province_id, address.postal_code, email.email as contact_email, phone.phone as contact_phone'); - $e->query->join('participant_stuff', " -!casMailingJoinType civicrm_event ev ON e.event_id = ev.id -!casMailingJoinType civicrm_option_group og ON og.name = 'event_type' -!casMailingJoinType civicrm_option_value ov ON ev.event_type_id = ov.value AND ov.option_group_id = og.id -LEFT JOIN civicrm_loc_block lb ON lb.id = ev.loc_block_id -LEFT JOIN civicrm_address address ON address.id = lb.address_id -LEFT JOIN civicrm_email email ON email.id = lb.email_id -LEFT JOIN civicrm_phone phone ON phone.id = lb.phone_id -"); - } - - /** - * @inheritDoc - */ - public function evaluateToken(\Civi\Token\TokenRow $row, $entity, $field, $prefetch = NULL) { - $actionSearchResult = $row->context['actionSearchResult']; - $eventID = $row->context['eventId'] ?? $actionSearchResult->event_id; if (array_key_exists($field, $this->getEventTokenValues($eventID))) { foreach ($this->getEventTokenValues($eventID)[$field] as $format => $value) { $row->format($format)->tokens($entity, $field, $value); } - return; - } - - if ($field === 'event_id') { - // @todo - migrate this to 'id' - $row->tokens($entity, $field, $eventID); - } - elseif ($field === 'event_type') { - // temporary - @todo db update to event_type_id:label - $row->tokens($entity, $field, $this->getEventTokenValues($eventID)['event_type_id:label']['text/html']); - } - elseif ($field === 'balance') { - if ($actionSearchResult->entityTable === 'civicrm_contact') { - $balancePay = 'N/A'; - } - elseif (!empty($actionSearchResult->entityID)) { - $info = \CRM_Contribute_BAO_Contribution::getPaymentInfo($actionSearchResult->entityID, 'event'); - $balancePay = $info['balance'] ?? NULL; - $balancePay = \CRM_Utils_Money::format($balancePay); - } - $row->tokens($entity, $field, $balancePay); - } - elseif ($field === 'fee_amount') { - $row->tokens($entity, $field, \CRM_Utils_Money::format($actionSearchResult->$field)); - } - elseif ($cfID = CRM_Core_BAO_CustomField::getKeyID($field)) { - $row->customToken($entity, $cfID, $actionSearchResult->event_id); - } - else { - parent::evaluateToken($row, $entity, $field, $prefetch); } } @@ -191,9 +128,10 @@ LEFT JOIN civicrm_phone phone ON phone.id = lb.phone_id $tokens['contact_email']['text/html'] = $event['loc_block_id.email_id.email']; foreach (array_keys($this->getAllTokens()) as $field) { - if (!isset($tokens[$field]) && isset($event[$field])) { + if (!isset($tokens[$field])) { if ($this->isCustomField($field)) { - $tokens[$field]['text/html'] = CRM_Core_BAO_CustomField::displayValue($event[$field], str_replace('custom_', '', $field)); + $this->prefetch[$eventID] = $event; + $tokens[$field]['text/html'] = $this->getCustomFieldValue($eventID, $field); } else { $tokens[$field]['text/html'] = $event[$field]; diff --git a/CRM/Upgrade/Incremental/php/FiveFortyThree.php b/CRM/Upgrade/Incremental/php/FiveFortyThree.php index 075c25c9a0..95c0e02df1 100644 --- a/CRM/Upgrade/Incremental/php/FiveFortyThree.php +++ b/CRM/Upgrade/Incremental/php/FiveFortyThree.php @@ -74,6 +74,21 @@ class CRM_Upgrade_Incremental_php_FiveFortyThree extends CRM_Upgrade_Incremental $this->addTask('Replace membership type token in action schedule', 'updateActionScheduleToken', 'membership.type', 'membership.membership_type_id:label', $rev ); + $this->addTask('Replace event fee amount token in action schedule', + 'updateActionScheduleToken', 'event.fee_amount', 'participant.fee_amount', $rev + ); + $this->addTask('Replace event type token in action schedule', + 'updateActionScheduleToken', 'event.event_type_id', 'participant.event_type_id:label', $rev + ); + $this->addTask('Replace event balance in action schedule', + 'updateActionScheduleToken', 'event.balance', 'participant.balance', $rev + ); + $this->addTask('Replace event fee amount in action schedule', + 'updateActionScheduleToken', 'event.fee_amount', 'participant.fee_amount', $rev + ); + $this->addTask('Replace event event_id in action schedule', + 'updateActionScheduleToken', 'event.event_id', 'event.id', $rev + ); $this->addTask('Replace duplicate event title token in event badges', 'updatePrintLabelToken', 'participant.event_title', 'event.title', $rev ); diff --git a/tests/phpunit/CRM/Utils/TokenConsistencyTest.php b/tests/phpunit/CRM/Utils/TokenConsistencyTest.php index 3b398fc453..662966748b 100644 --- a/tests/phpunit/CRM/Utils/TokenConsistencyTest.php +++ b/tests/phpunit/CRM/Utils/TokenConsistencyTest.php @@ -44,12 +44,9 @@ class CRM_Utils_TokenConsistencyTest extends CiviUnitTestCase { /** * Post test cleanup. - * - * @throws \API_Exception - * @throws \CRM_Core_Exception */ public function tearDown(): void { - $this->quickCleanup(['civicrm_case', 'civicrm_case_type'], TRUE); + $this->quickCleanup(['civicrm_case', 'civicrm_case_type', 'civicrm_participant', 'civicrm_event'], TRUE); parent::tearDown(); } @@ -456,9 +453,35 @@ Check'; * * @return string */ - protected function getExpectedEventTokenOutput(): string { - return ' + protected function getExpectedParticipantTokenOutput(): string { + return '2 1 +February 19th, 2007 +Wimbeldon +steep +$ 50.00 + + +Attendee + +99999 +2 +USD + +Attended +Attended +Attendee +No +'; + } + + /** + * Get expected output from token parsing. + * + * @return string + */ + protected function getExpectedEventTokenOutput(): string { + return $this->ids['event'][0] . ' Annual CiviCRM meet October 21st, 2008 October 23rd, 2008 @@ -470,10 +493,8 @@ event description 15 Walton St Emerald City, Maine 90210 -$ 50.00 ' . CRM_Utils_System::url('civicrm/event/info', NULL, TRUE) . '&reset=1&id=1 ' . CRM_Utils_System::url('civicrm/event/register', NULL, TRUE) . '&reset=1&id=1 - my field'; } @@ -502,9 +523,29 @@ December 21st, 2007 */ public function testParticipantTokenConsistency(): void { $this->createLoggedInUser(); - $this->createCustomGroupWithFieldOfType(['extends' => 'Participant']); + $this->setupParticipantScheduledReminder(); + $tokens = CRM_Core_SelectValues::participantTokens(); $this->assertEquals($this->getParticipantTokens(), $tokens); + + $mut = new CiviMailUtils($this); + + $tokenProcessor = new TokenProcessor(\Civi::dispatcher(), [ + 'controller' => __CLASS__, + 'smarty' => FALSE, + 'schema' => ['participantId'], + ]); + $this->assertEquals(array_merge($tokens, $this->getDomainTokens()), $tokenProcessor->listTokens()); + + $this->callAPISuccess('job', 'send_reminder', []); + $expected = $this->getExpectedParticipantTokenOutput(); + $mut->checkMailLog([$expected]); + + $tokenProcessor->addMessage('html', implode("\n", array_keys($this->getParticipantTokens())), 'text/plain'); + $tokenProcessor->addRow(['participantId' => $this->ids['participant'][0]]); + $tokenProcessor->evaluate(); + $this->assertEquals($expected, $tokenProcessor->getRow(0)->render('html')); + } /** @@ -515,16 +556,24 @@ December 21st, 2007 public function getParticipantTokens(): array { return [ '{participant.status_id}' => 'Status ID', - '{participant.role_id}' => 'Participant Role (ID)', + '{participant.role_id}' => 'Participant Role ID', '{participant.register_date}' => 'Register date', '{participant.source}' => 'Participant Source', '{participant.fee_level}' => 'Fee level', '{participant.fee_amount}' => 'Fee Amount', '{participant.registered_by_id}' => 'Registered By Participant ID', '{participant.transferred_to_contact_id}' => 'Transferred to Contact ID', - '{participant.role_id:label}' => 'Participant Role (label)', - '{participant.fee_label}' => 'Fee Label', - '{participant.' . $this->getCustomFieldName('text') . '}' => 'Enter text here :: Group with field text', + '{participant.role_id:label}' => 'Participant Role', + '{participant.balance}' => 'Event Balance', + '{participant.' . $this->getCustomFieldName('participant_int') . '}' => 'Enter integer here :: participant_Group with field int', + '{participant.id}' => 'Participant ID', + '{participant.fee_currency}' => 'Fee Currency', + '{participant.discount_amount}' => 'Discount Amount', + '{participant.status_id:label}' => 'Status', + '{participant.status_id:name}' => 'Machine name: Status', + '{participant.role_id:name}' => 'Machine name: Participant Role', + '{participant.is_test:label}' => 'Test', + '{participant.must_wait}' => 'Must Wait on List', ]; } @@ -577,7 +626,7 @@ December 21st, 2007 'msg_text' => '{domain.now|crmDate:shortdate}', ], ])['text']; - $this->fail("Expected unquoted parameter to fail"); + $this->fail('Expected unquoted parameter to fail'); } catch (\CRM_Core_Exception $e) { $this->assertRegExp(';Malformed token param;', $e->getMessage()); @@ -602,7 +651,7 @@ December 21st, 2007 } /** - * Test that domain tokens are consistently rendered. + * Test that event tokens are consistently rendered. * * @throws \API_Exception */ @@ -619,9 +668,40 @@ December 21st, 2007 ]); $this->assertEquals(array_merge($tokens, $this->getDomainTokens()), $tokenProcessor->listTokens()); + $this->callAPISuccess('job', 'send_reminder', []); + $expected = $this->getExpectedEventTokenOutput(); + $mut->checkMailLog([$expected, $this->getExpectedParticipantTokenOutput()]); + + $tokenProcessor->addMessage('html', implode("\n", array_keys($this->getEventTokens())), 'text/plain'); + $tokenProcessor->addRow(['eventId' => $this->ids['event'][0]]); + $tokenProcessor->evaluate(); + $this->assertEquals($expected, $tokenProcessor->getRow(0)->render('html')); + } + + /** + * Test that event tokens work absent participant tokens. + * + * @throws \API_Exception + */ + public function testEventTokenConsistencyNoParticipantTokens(): void { + $mut = new CiviMailUtils($this); + $this->setupParticipantScheduledReminder(FALSE); + $this->callAPISuccess('job', 'send_reminder', []); $expected = $this->getExpectedEventTokenOutput(); $mut->checkMailLog([$expected]); + + $tokenProcessor = new TokenProcessor(\Civi::dispatcher(), [ + 'controller' => __CLASS__, + 'smarty' => FALSE, + 'schema' => ['eventId'], + ]); + + $tokenProcessor->addMessage('html', implode("\n", array_keys($this->getEventTokens())), 'text/plain'); + $tokenProcessor->addRow(['eventId' => $this->ids['event'][0]]); + $tokenProcessor->evaluate(); + $this->assertEquals($expected, $tokenProcessor->getRow(0)->render('html')); + } /** @@ -629,8 +709,18 @@ December 21st, 2007 * * @throws \API_Exception */ - public function setupParticipantScheduledReminder(): void { + public function setupParticipantScheduledReminder($includeParticipant = TRUE): void { $this->createCustomGroupWithFieldOfType(['extends' => 'Event']); + $this->createCustomGroupWithFieldOfType(['extends' => 'Participant'], 'int', 'participant_'); + + if ($includeParticipant) { + $html = implode("\n", array_keys(array_merge($this->getEventTokens(), $this->getParticipantTokens()))); + } + else { + $html = implode("\n", array_keys($this->getEventTokens())); + + } + $emailID = Email::create()->setValues(['email' => 'event@example.com'])->execute()->first()['id']; $addressID = Address::create()->setValues([ 'street_address' => '15 Walton St', @@ -648,15 +738,20 @@ December 21st, 2007 'phone_id' => $phoneID, ], ])->execute()->first()['id']; - $event = $this->eventCreate([ + $this->ids['event'][0] = $this->eventCreate([ 'description' => 'event description', $this->getCustomFieldName('text') => 'my field', 'loc_block_id' => $locationBlockID, - ]); + ])['id']; // Create an unrelated participant record so that the ids don't match. // this prevents things working just because the id 'happens to be valid' - $this->participantCreate(['register_date' => '2020-01-01', 'event_id' => $event['id']]); - $this->participantCreate(['event_id' => $event['id'], 'fee_amount' => 50]); + $this->participantCreate(['register_date' => '2020-01-01', 'event_id' => $this->ids['event'][0]]); + $this->ids['participant'][0] = $this->participantCreate([ + 'event_id' => $this->ids['event'][0], + 'fee_amount' => 50, + 'fee_level' => 'steep', + $this->getCustomFieldName('participant_int') => '99999', + ]); CRM_Utils_Time::setTime('2007-02-20 15:00:00'); $this->callAPISuccess('action_schedule', 'create', [ 'title' => 'job', @@ -667,7 +762,7 @@ December 21st, 2007 'start_action_offset' => 1, 'start_action_condition' => 'after', 'start_action_unit' => 'day', - 'body_html' => implode("\n", array_keys($this->getEventTokens())), + 'body_html' => $html, ]); } @@ -678,20 +773,18 @@ December 21st, 2007 */ protected function getEventTokens(): array { return [ - '{event.event_id}' => 'Event ID', + '{event.id}' => 'Event ID', '{event.title}' => 'Event Title', '{event.start_date}' => 'Event Start Date', '{event.end_date}' => 'Event End Date', - '{event.event_type}' => 'Event Type', + '{event.event_type_id:label}' => 'Event Type', '{event.summary}' => 'Event Summary', '{event.contact_email}' => 'Event Contact Email', '{event.contact_phone}' => 'Event Contact Phone', '{event.description}' => 'Event Description', '{event.location}' => 'Event Location', - '{event.fee_amount}' => 'Event Fee', '{event.info_url}' => 'Event Info URL', '{event.registration_url}' => 'Event Registration URL', - '{event.balance}' => 'Event Balance', '{event.' . $this->getCustomFieldName('text') . '}' => 'Enter text here :: Group with field text', ]; } -- 2.25.1