CRM-12966, more fixes and cleanup for badges
[civicrm-core.git] / CRM / Event / Form / Task / Badge.php
index 3c691cc94a8028cc68c4baffbbdc7a0696f2085d..403c80f3310fc0a8cda4c96197b5adcf52e3df7f 100644 (file)
@@ -87,7 +87,7 @@ class CRM_Event_Form_Task_Badge extends CRM_Event_Form_Task {
     CRM_Utils_System::setTitle(ts('Make Name Badges'));
 
     //add select for label
-    $label = CRM_Core_OptionGroup::values('event_badge');
+    $label = CRM_Badge_BAO_Layout::getList();
 
     $this->add('select',
       'badge_id',
@@ -110,11 +110,36 @@ class CRM_Event_Form_Task_Badge extends CRM_Event_Form_Task {
    */
   public function postProcess() {
     $params = $this->controller->exportValues($this->_name);
-    $config = CRM_Core_Config::singleton();
 
+    // get name badge layout info
+    $layoutInfo = CRM_Badge_BAO_Layout::buildLayout($params);
+
+    // spit / get actual field names from token
+    $returnProperties = array();
+    if (!empty($layoutInfo['data']['token'])) {
+      foreach ($layoutInfo['data']['token'] as $index => $value) {
+        $token = CRM_Utils_Token::getTokens($value);
+        if (key($token) == 'contact') {
+          $element = $token['contact'][0];
+        }
+        else {
+          $element = $token['event'][0];
+          //FIX ME - we need to standardize event token names
+          if (!strpos($element, 'event_')) {
+            $element = 'event_' .$element;
+          }
+        }
+
+        // build returnproperties for query
+        $returnProperties[$element] = 1;
+
+        // add actual field name to row element
+        $layoutInfo['data']['rowElements'][$index] = $element;
+      }
+    }
 
-    $returnProperties = CRM_Event_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_EVENT);
-    $additionalFields = array('first_name', 'last_name', 'middle_name', 'current_employer');
+    // add additional required fields for query execution
+    $additionalFields = array('participant_register_date', 'participant_id');
     foreach ($additionalFields as $field) {
       $returnProperties[$field] = 1;
     }
@@ -156,25 +181,8 @@ class CRM_Event_Form_Task_Badge extends CRM_Event_Form_Task {
       }
     }
 
-    // get the class name from the participantListingID
-    $className = CRM_Core_OptionGroup::getValue('event_badge',
-      $params['badge_id'],
-      'value',
-      'Integer',
-      'name'
-    );
-
-    $classFile = str_replace('_',
-      DIRECTORY_SEPARATOR,
-      $className
-    ) . '.php';
-    $error = include_once ($classFile);
-    if ($error == FALSE) {
-      CRM_Core_Error::fatal('Event Badge code file: ' . $classFile . ' does not exist. Please verify your custom event badge settings in CiviCRM administrative panel.');
-    }
-
-    $eventBadgeClass = new $className();
-    $eventBadgeClass->run($rows);
+    $eventBadgeClass = new CRM_Badge_BAO_Badge();
+    $eventBadgeClass->createLabels($rows, $layoutInfo);
   }
 }