dev/core#3829 Fix failure of barcode to include participant & contact id
authorEileen McNaughton <emcnaughton@wikimedia.org>
Sat, 8 Oct 2022 15:03:06 +0000 (16:03 +0100)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Sat, 8 Oct 2022 15:03:46 +0000 (16:03 +0100)
CRM/Badge/BAO/Badge.php
tests/phpunit/CRM/Event/Form/Task/BadgeTest.php

index 5d1bdcfffdaa80326ad0ba0650799361c44c51c5..b83929b180e50091cfd213a42b00547d52d92c28 100644 (file)
@@ -78,7 +78,7 @@ class CRM_Badge_BAO_Badge {
    * @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'];
@@ -149,16 +149,16 @@ class CRM_Badge_BAO_Badge {
   /**
    * @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;
     }
   }
@@ -167,7 +167,7 @@ class CRM_Badge_BAO_Badge {
    * @param array $formattedRow
    * @param int $cellspacing
    */
-  public function labelCreator(&$formattedRow, $cellspacing = 0) {
+  public function labelCreator($formattedRow, $cellspacing = 0) {
     $this->lMarginLogo = 18;
     $this->tMarginName = 20;
 
@@ -229,7 +229,7 @@ class CRM_Badge_BAO_Badge {
     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'];
         }
 
@@ -256,7 +256,7 @@ class CRM_Badge_BAO_Badge {
     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 {
@@ -457,6 +457,8 @@ class CRM_Badge_BAO_Badge {
     }
     $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);
       }
index bff942902fb7e611c14edddc43ea5870ceb1e7b6..d1f8622dedbec3fb97ea19049be63940894fc123 100644 (file)
@@ -19,6 +19,8 @@ class CRM_Event_Form_Task_BadgeTest extends CiviUnitTestCase {
 
   /**
    * Test the the submit function on the event participant submit function.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testSubmit(): void {
     $this->createCustomGroupWithFieldOfType(['extends' => 'Participant']);
@@ -30,7 +32,7 @@ class CRM_Event_Form_Task_BadgeTest extends CiviUnitTestCase {
 
     $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;