/** * Build the form object. * * * @return void */ public function buildQuickForm() { CRM_Utils_System::setTitle(ts('Make Name Badges')); //add select for label $label = CRM_Badge_BAO_Layout::getList(); $this->add('select', 'badge_id', ts('Name Badge Format'), array('' => ts('- select -')) + $label, TRUE); $next = 'next'; $back = $this->_single ? 'cancel' : 'back'; $this->addDefaultButtons(ts('Make Name Badges'), $next, $back); }
/** * Build badges parameters before actually creating badges. * * @param array $params * Associated array of submitted values. * @param CRM_Core_Form $form * * @return void */ public static function buildBadges(&$params, &$form) { // get name badge layout info $layoutInfo = CRM_Badge_BAO_Layout::buildLayout($params); // split/get actual field names from token and individual contact image URLs $returnProperties = array(); if (!empty($layoutInfo['data']['token'])) { foreach ($layoutInfo['data']['token'] as $index => $value) { $element = ''; if ($value) { $token = CRM_Utils_Token::getTokens($value); if (key($token) == 'contact') { $element = $token['contact'][0]; } elseif (key($token) == 'event') { $element = $token['event'][0]; //FIX ME - we need to standardize event token names if (substr($element, 0, 6) != 'event_') { $element = 'event_' . $element; } } elseif (key($token) == 'participant') { $element = $token['participant'][0]; } // build returnproperties for query $returnProperties[$element] = 1; } // add actual field name to row element $layoutInfo['data']['rowElements'][$index] = $element; } } // add additional required fields for query execution $additionalFields = array('participant_register_date', 'participant_id', 'event_id', 'contact_id', 'image_URL'); foreach ($additionalFields as $field) { $returnProperties[$field] = 1; } if ($form->_single) { $queryParams = NULL; } else { $queryParams = $form->get('queryParams'); } $query = new CRM_Contact_BAO_Query($queryParams, $returnProperties, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_EVENT); list($select, $from, $where, $having) = $query->query(); if (empty($where)) { $where = "WHERE {$form->_componentClause}"; } else { $where .= " AND {$form->_componentClause}"; } $sortOrder = NULL; if ($form->get(CRM_Utils_Sort::SORT_ORDER)) { $sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER); if (!empty($sortOrder)) { $sortOrder = " ORDER BY {$sortOrder}"; } } $queryString = "{$select} {$from} {$where} {$having} {$sortOrder}"; $dao = CRM_Core_DAO::executeQuery($queryString); $rows = array(); while ($dao->fetch()) { $query->convertToPseudoNames($dao); $rows[$dao->participant_id] = array(); foreach ($returnProperties as $key => $dontCare) { $value = isset($dao->{$key}) ? $dao->{$key} : NULL; // Format custom fields if (strstr($key, 'custom_') && isset($value)) { $value = CRM_Core_BAO_CustomField::getDisplayValue($value, substr($key, 7), $query->_options, $dao->contact_id); } $rows[$dao->participant_id][$key] = $value; } } $eventBadgeClass = new CRM_Badge_BAO_Badge(); $eventBadgeClass->createLabels($rows, $layoutInfo); }
/** * Build layout structure. * * @param array $params * Associated array of submitted values. * * @return array * array formatted array */ public static function buildLayout(&$params) { $layoutParams = array('id' => $params['badge_id']); CRM_Badge_BAO_Layout::retrieve($layoutParams, $layoutInfo); $formatProperties = CRM_Core_OptionGroup::getValue('name_badge', $layoutInfo['label_format_name'], 'name'); $layoutInfo['format'] = json_decode($formatProperties, TRUE); $layoutInfo['data'] = CRM_Badge_BAO_Layout::getDecodedData($layoutInfo['data']); return $layoutInfo; }
/** * Function to process the form * * @access public * * @return void */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { CRM_Badge_BAO_Layout::del($this->_id); CRM_Core_Session::setStatus(ts('Selected badge layout has been deleted.'), ts('Record Deleted'), 'success'); return; } $params = $data = $this->exportValues(); unset($data['qfKey']); $params['data'] = json_encode($data); if ($this->_id) { $params['id'] = $this->_id; } // store the submitted values in an array $badgeInfo = CRM_Badge_BAO_Layout::create($params); if (isset($params['_qf_Layout_refresh'])) { $this->set('id', $badgeInfo->id); $params['badge_id'] = $badgeInfo->id; self::buildPreview($params); } else { CRM_Core_Session::setStatus(ts("The badge layout '%1' has been saved.", array(1 => $params['title'])), ts('Saved'), 'success'); } }