Skip to content
Snippets Groups Projects
Unverified Commit 62d3fbb9 authored by Seamus Lee's avatar Seamus Lee Committed by GitHub
Browse files

Merge pull request #21520 from eileenmcnaughton/badger

Participant tokens - remove / replace unsupportable from badges (conversion preparation)
parents 088ae5a3 c9ce3966
No related branches found
No related tags found
No related merge requests found
......@@ -603,14 +603,9 @@ class CRM_Core_SelectValues {
'{participant.participant_registered_by_id}' => 'Registered By Participant ID',
'{participant.transferred_to_contact_id}' => 'Transferred to Contact ID',
'{participant.participant_role}' => 'Participant Role (label)',
'{participant.event_title}' => 'Event Title',
'{participant.event_start_date}' => 'Event Start Date',
'{participant.event_end_date}' => 'Event End Date',
'{participant.fee_label}' => 'Fee Label',
'{participant.default_role_id}' => 'Default Role',
'{participant.template_title}' => 'Event Template Title',
'{participant.currency}' => 'Currency',
'{participant.participant_note}' => 'Participant Note',
];
$customFields = CRM_Core_BAO_CustomField::getFields('Participant');
......
......@@ -269,7 +269,7 @@ class CRM_Upgrade_Incremental_Base {
}
/**
* Updated a message token within a template.
* Updated a message token within a scheduled reminder.
*
* @param CRM_Queue_TaskContext $ctx
* @param string $old
......@@ -284,6 +284,22 @@ class CRM_Upgrade_Incremental_Base {
return TRUE;
}
/**
* Updated a message token within a template.
*
* @param CRM_Queue_TaskContext $ctx
* @param string $old
* @param string $new
* @param $version
*
* @return bool
*/
public static function updatePrintLabelToken($ctx, string $old, string $new, $version):bool {
$messageObj = new CRM_Upgrade_Incremental_MessageTemplates($version);
$messageObj->replaceTokenInPrintLabel($old, $new);
return TRUE;
}
/**
* Re-save any valid values from contribute settings into the normal setting
* format.
......
......@@ -316,6 +316,21 @@ class CRM_Upgrade_Incremental_MessageTemplates {
");
}
/**
* Replace a token with the new preferred option in a print label.
*
* @param string $old
* @param string $new
*/
public function replaceTokenInPrintLabel(string $old, string $new): void {
$oldToken = '{' . $old . '}';
$newToken = '{' . $new . '}';
CRM_Core_DAO::executeQuery("UPDATE civicrm_print_label
SET
data = REPLACE(data, '$oldToken', '$newToken')
");
}
/**
* Get the upgrade messages.
*/
......
......@@ -74,6 +74,15 @@ 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 duplicate event title token in event badges',
'updatePrintLabelToken', 'participant.event_title', 'event.title', $rev
);
$this->addTask('Replace duplicate event start date token in event badges',
'updatePrintLabelToken', 'participant.event_start_date', 'event.start_date', $rev
);
$this->addTask('Replace duplicate event end date token in event badges',
'updatePrintLabelToken', 'participant.event_end_date', 'event.end_date', $rev
);
}
/**
......
<?php
use Civi\Api4\PrintLabel;
/**
* Test CRM_Event_Form_Registration functions.
*
......@@ -10,13 +12,35 @@ class CRM_Event_Form_Task_BadgeTest extends CiviUnitTestCase {
use CRMTraits_Custom_CustomDataTrait;
public function tearDown(): void {
$this->quickCleanup(['civicrm_participant', 'civicrm_print_label'], TRUE);
parent::tearDown();
}
/**
* Test the the submit function on the event participant submit function.
*/
public function testSubmit(): void {
$this->createCustomGroupWithFieldOfType(['extends' => 'Participant']);
$contactID = $this->individualCreate();
$participantID = $this->participantCreate(['contact_id' => $contactID]);
$contactID = $this->individualCreate(['employer_id' => 1]);
$participantID = $this->participantCreate([
'contact_id' => $contactID,
'fee_level' => 'low',
]);
$badgeLayout = PrintLabel::get()->addSelect('data')->execute()->first();
$values = [
'data' => array_merge($badgeLayout['data'], ['token' => [], 'font_name' => [''], 'font_size' => [], 'text_alignment' => []]),
];
foreach (array_keys($this->getAvailableTokens()) as $id => $token) {
$index = $id + 1;
$values['data']['token'][$index] = $token;
$values['data']['font_name'][$index] = 'dejavusans';
$values['data']['font_size'][$index] = '20';
$values['data']['font_style'][$index] = '';
$values['data']['text_alignment'][$index] = 'C';
}
PrintLabel::update()->addWhere('id', '=', 1)->setValues($values)->execute();
$_REQUEST['context'] = 'view';
$_REQUEST['id'] = $participantID;
......@@ -39,45 +63,48 @@ class CRM_Event_Form_Task_BadgeTest extends CiviUnitTestCase {
catch (CRM_Core_Exception_PrematureExitException $e) {
$tokens = $e->errorData['formattedRow']['token'];
$this->assertEquals([
1 => [
'value' => 'Annual CiviCRM meet',
'font_name' => 'dejavusans',
'font_size' => '9',
'font_style' => '',
'text_alignment' => 'L',
'token' => '{event.title}',
],
2 =>
[
'value' => 'Mr. Anthony Anderson II',
'font_name' => 'dejavusans',
'font_size' => '20',
'font_style' => '',
'text_alignment' => 'C',
'token' => '{contact.display_name}',
],
3 =>
[
'value' => NULL,
'font_name' => 'dejavusans',
'font_size' => '15',
'font_style' => '',
'text_alignment' => 'C',
'token' => '{contact.current_employer}',
],
4 =>
[
'value' => 'October 21st',
'font_name' => 'dejavusans',
'font_size' => '9',
'font_style' => '',
'text_alignment' => 'R',
'token' => '{event.start_date}',
],
], $tokens);
'value' => 'Annual CiviCRM meet',
'font_name' => 'dejavusans',
'font_size' => '20',
'font_style' => '',
'text_alignment' => 'C',
'token' => '{event.title}',
], $tokens[1]);
$index = 1;
foreach ($this->getAvailableTokens() as $token => $expected) {
$this->assertEquals($expected, $tokens[$index]['value'], 'failure in token ' . $token);
$index++;
}
return;
}
$this->fail('Should not be reached');
}
/**
* @return string[]
*/
protected function getAvailableTokens(): array {
$tokens = [
'{event.title}' => 'Annual CiviCRM meet',
'{contact.display_name}' => 'Mr. Anthony Anderson II',
'{contact.current_employer}' => 'Default Organization',
'{event.start_date}' => 'October 21st',
'{participant.participant_status_id}' => 2,
'{participant.participant_role_id}' => 1,
'{participant.participant_register_date}' => 'February 19th',
'{participant.participant_source}' => 'Wimbeldon',
'{participant.participant_fee_level}' => 'low',
'{participant.participant_fee_amount}' => NULL,
'{participant.participant_registered_by_id}' => NULL,
'{participant.transferred_to_contact_id}' => NULL,
'{participant.participant_role}' => 'Attendee',
'{participant.fee_label}' => NULL,
'{participant.default_role_id}' => 1,
'{participant.template_title}' => NULL,
'{event.end_date}' => 'October 23rd',
'{event.id}' => 1,
];
return $tokens;
}
}
......@@ -492,14 +492,9 @@ December 21st, 2007
'{participant.participant_registered_by_id}' => 'Registered By Participant ID',
'{participant.transferred_to_contact_id}' => 'Transferred to Contact ID',
'{participant.participant_role}' => 'Participant Role (label)',
'{participant.event_title}' => 'Event Title',
'{participant.event_start_date}' => 'Event Start Date',
'{participant.event_end_date}' => 'Event End Date',
'{participant.fee_label}' => 'Fee Label',
'{participant.default_role_id}' => 'Default Role',
'{participant.template_title}' => 'Event Template Title',
'{participant.currency}' => 'Currency',
'{participant.participant_note}' => 'Participant Note',
'{participant.' . $this->getCustomFieldName('text') . '}' => 'Enter text here :: Group with field text',
];
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment