Skip to content

Commit

Permalink
dev/core#3829 Fix failure of barcode to include participant & contact id
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Oct 8, 2022
1 parent e33fd91 commit 635a579
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 9 additions & 7 deletions CRM/Badge/BAO/Badge.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function createLabels($participants, &$layoutInfo) {
* @return array
* row with meta data
*/
public static function formatLabel(&$row, &$layout) {
public static function formatLabel(array $row, array $layout): array {
$formattedRow = ['labelFormat' => $layout['label_format_name']];
$formattedRow['labelTitle'] = $layout['title'];
$formattedRow['labelId'] = $layout['id'];
Expand Down Expand Up @@ -149,16 +149,16 @@ public static function formatLabel(&$row, &$layout) {
/**
* @param array $formattedRow
*/
public function generateLabel($formattedRow) {
public function generateLabel(array $formattedRow): void {
switch ($formattedRow['labelFormat']) {
case 'A6 Badge Portrait 150x106':
case 'Hanging Badge 3-3/4" x 4-3"/4':
self::labelCreator($formattedRow, 5);
$this->labelCreator($formattedRow, 5);
break;

case 'Avery 5395':
default:
self::labelCreator($formattedRow);
$this->labelCreator($formattedRow);
break;
}
}
Expand All @@ -167,7 +167,7 @@ public function generateLabel($formattedRow) {
* @param array $formattedRow
* @param int $cellspacing
*/
public function labelCreator(&$formattedRow, $cellspacing = 0) {
public function labelCreator($formattedRow, $cellspacing = 0) {
$this->lMarginLogo = 18;
$this->tMarginName = 20;

Expand Down Expand Up @@ -229,7 +229,7 @@ public function labelCreator(&$formattedRow, $cellspacing = 0) {
for ($i = 1; $i <= $rowCount; $i++) {
if (!empty($formattedRow['token'][$i]['token'])) {
$value = '';
if ($formattedRow['token'][$i]['token'] != 'spacer') {
if ($formattedRow['token'][$i]['token'] !== 'spacer') {
$value = $formattedRow['token'][$i]['value'];
}

Expand All @@ -256,7 +256,7 @@ public function labelCreator(&$formattedRow, $cellspacing = 0) {
if (!empty($formattedRow['barcode'])) {
$data = $formattedRow['values'];

if ($formattedRow['barcode']['type'] == 'barcode') {
if ($formattedRow['barcode']['type'] === 'barcode') {
$data['current_value'] = $formattedRow['values']['contact_id'] . '-' . $formattedRow['values']['participant_id'];
}
else {
Expand Down Expand Up @@ -457,6 +457,8 @@ public static function buildBadges(&$params, &$form) {
}
$tokenProcessor->evaluate();
foreach ($tokenProcessor->getRows() as $row) {
$rows[$row->context['participantId']]['contact_id'] = $row->context['contactId'];
$rows[$row->context['participantId']]['participant_id'] = $row->context['participantId'];
foreach ($processorTokens as $processorToken) {
$rows[$row->context['participantId']][$processorToken] = $row->render($processorToken);
}
Expand Down
4 changes: 3 additions & 1 deletion tests/phpunit/CRM/Event/Form/Task/BadgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public function tearDown(): void {

/**
* Test the the submit function on the event participant submit function.
*
* @throws \CRM_Core_Exception
*/
public function testSubmit(): void {
$this->createCustomGroupWithFieldOfType(['extends' => 'Participant']);
Expand All @@ -30,7 +32,7 @@ public function testSubmit(): void {

$badgeLayout = PrintLabel::get()->addSelect('data')->execute()->first();
$values = [
'data' => array_merge((array) $badgeLayout['data'], ['token' => [], 'font_name' => [''], 'font_size' => [], 'text_alignment' => []]),
'data' => array_merge((array) $badgeLayout['data'], ['token' => [], 'font_name' => [''], 'font_size' => [], 'text_alignment' => [], 'add_barcode' => 1]),
];
foreach (array_keys($this->getAvailableTokens()) as $id => $token) {
$index = $id + 1;
Expand Down

0 comments on commit 635a579

Please sign in to comment.