_mapperFields['participant_is_test']); if ($this->getSubmittedValue('onDuplicate') == CRM_Import_Parser::DUPLICATE_UPDATE) { $remove = [ 'participant_contact_id', 'email', 'first_name', 'last_name', 'external_identifier', ]; foreach ($remove as $value) { unset($this->_mapperFields[$value]); } } elseif ( $this->getSubmittedValue('onDuplicate') == CRM_Import_Parser::DUPLICATE_SKIP || $this->getSubmittedValue('onDuplicate') == CRM_Import_Parser::DUPLICATE_NOCHECK) { unset($this->_mapperFields['participant_id']); } } /** * Build the form object. * * @return void */ public function buildQuickForm() { $savedMappingID = (int) $this->getSubmittedValue('savedMapping'); $this->buildSavedMappingFields($savedMappingID); $this->addFormRule(array('CRM_Event_Import_Form_MapField', 'formRule'), $this); $defaults = []; $mapperKeys = array_keys($this->_mapperFields); $hasHeaders = $this->getSubmittedValue('skipColumnHeader'); $headerPatterns = $this->getHeaderPatterns(); $dataPatterns = $this->getDataPatterns(); $fieldMappings = $this->getFieldMappings(); /* Initialize all field usages to false */ foreach ($mapperKeys as $key) { $this->_fieldUsed[$key] = FALSE; } $this->_location_types = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); $sel1 = $this->_mapperFields; $js = "\n"; $this->assign('initHideBoxes', $js); $this->setDefaults($defaults); $this->addButtons(array( array( 'type' => 'back', 'name' => ts('Previous'), ), array( 'type' => 'next', 'name' => ts('Continue'), 'spacing' => '          ', 'isDefault' => TRUE, ), array( 'type' => 'cancel', 'name' => ts('Cancel'), ), )); } /** * Global validation rules for the form. * * @param array $fields * Posted values of the form. * * @param $files * @param self $self * * @return array * list of errors to be posted back to the form */ public static function formRule($fields, $files, $self) { $errors = []; // define so we avoid notices below $errors['_qf_default'] = ''; $contactFieldsBelowWeightMessage = NULL; if (!array_key_exists('savedMapping', $fields)) { $importKeys = []; foreach ($fields['mapper'] as $mapperPart) { $importKeys[] = $mapperPart[0]; } // FIXME: should use the schema titles, not redeclare them $requiredFields = array( 'participant_contact_id' => ts('Contact ID'), 'event_id' => ts('Event ID'), ); $contactFieldsBelowWeightMessage = self::validateRequiredContactMatchFields($self->getContactType(), $importKeys); foreach ($requiredFields as $field => $title) { if (!in_array($field, $importKeys)) { if ($field == 'participant_contact_id') { if (!$contactFieldsBelowWeightMessage || in_array('external_identifier', $importKeys) || in_array('participant_id', $importKeys) ) { continue; } if ($self->_onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE) { $errors['_qf_default'] .= ts('Missing required field: Provide Participant ID') . '
'; } else { $errors['_qf_default'] .= ts('Missing required contact matching fields.') . " $contactFieldsBelowWeightMessage " . ' ' . ts('Or Provide Contact ID or External ID.') . '
'; } } elseif (!in_array('event_title', $importKeys)) { $errors['_qf_default'] .= ts('Missing required field: Provide %1 or %2', array(1 => $title, 2 => 'Event Title') ) . '
'; } } } } if (!empty($fields['saveMapping'])) { $nameField = $fields['saveMappingName'] ?? NULL; if (empty($nameField)) { $errors['saveMappingName'] = ts('Name is required to save Import Mapping'); } else { if (CRM_Core_BAO_Mapping::checkMapping($nameField, CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Mapping', 'mapping_type_id', 'Import Participant'))) { $errors['saveMappingName'] = ts('Duplicate Import Participant Mapping Name'); } } } //display Error if loaded mapping is not selected if (array_key_exists('loadMapping', $fields)) { $getMapName = $fields['savedMapping'] ?? NULL; if (empty($getMapName)) { $errors['savedMapping'] = ts('Select saved mapping'); } } if (empty($errors['_qf_default'])) { unset($errors['_qf_default']); } if (!empty($errors)) { if (!empty($errors['saveMappingName'])) { $_flag = 1; $assignError = new CRM_Core_Page(); $assignError->assign('mappingDetailsError', $_flag); } return $errors; } return TRUE; } /** * @return CRM_Event_Import_Parser_Participant */ protected function getParser(): CRM_Event_Import_Parser_Participant { if (!$this->parser) { $this->parser = new CRM_Event_Import_Parser_Participant(); $this->parser->setUserJobID($this->getUserJobID()); $this->parser->init(); } return $this->parser; } /** * Get the fields to highlight. * * @return array * @throws \CRM_Core_Exception */ protected function getHighlightedFields(): array { $highlightedFields = []; if ($this->getSubmittedValue('onDuplicate') == CRM_Import_Parser::DUPLICATE_UPDATE) { $highlightedFieldsArray = [ 'participant_id', 'event_id', 'event_title', 'participant_status_id', ]; foreach ($highlightedFieldsArray as $name) { $highlightedFields[] = $name; } } elseif ($this->getSubmittedValue('onDuplicate') == CRM_Import_Parser::DUPLICATE_SKIP || $this->getSubmittedValue('onDuplicate') == CRM_Import_Parser::DUPLICATE_NOCHECK ) { $highlightedFieldsArray = [ 'participant_contact_id', 'event_id', 'email', 'first_name', 'last_name', 'external_identifier', 'participant_status_id', ]; foreach ($highlightedFieldsArray as $name) { $highlightedFields[] = $name; } } return $highlightedFields; } /** * Get the mapping name per the civicrm_mapping_field.type_id option group. * * @return string */ public function getMappingTypeName(): string { return 'Import Participants'; } }