3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class gets the name of the file to upload
21 class CRM_Event_Import_Form_MapField
extends CRM_Import_Form_MapField
{
24 * Set variables up before form is built.
28 public function preProcess() {
30 unset($this->_mapperFields
['participant_is_test']);
32 if ($this->getSubmittedValue('onDuplicate') == CRM_Import_Parser
::DUPLICATE_UPDATE
) {
34 'participant_contact_id',
38 'external_identifier',
40 foreach ($remove as $value) {
41 unset($this->_mapperFields
[$value]);
45 $this->getSubmittedValue('onDuplicate') == CRM_Import_Parser
::DUPLICATE_SKIP
46 ||
$this->getSubmittedValue('onDuplicate') == CRM_Import_Parser
::DUPLICATE_NOCHECK
) {
47 unset($this->_mapperFields
['participant_id']);
52 * Build the form object.
56 public function buildQuickForm() {
57 $savedMappingID = (int) $this->getSubmittedValue('savedMapping');
58 $this->buildSavedMappingFields($savedMappingID);
59 $this->addFormRule(array('CRM_Event_Import_Form_MapField', 'formRule'), $this);
61 $this->addFormButtons();
65 * Global validation rules for the form.
67 * @param array $fields
68 * Posted values of the form.
74 * list of errors to be posted back to the form
76 public static function formRule($fields, $files, $self) {
78 // define so we avoid notices below
79 $errors['_qf_default'] = '';
81 if (!array_key_exists('savedMapping', $fields)) {
83 foreach ($fields['mapper'] as $mapperPart) {
84 $importKeys[] = $mapperPart[0];
86 // FIXME: should use the schema titles, not redeclare them
87 $requiredFields = array(
88 'contact_id' => ts('Contact ID'),
89 'event_id' => ts('Event ID'),
92 $contactFieldsBelowWeightMessage = self
::validateRequiredContactMatchFields($self->getContactType(), $importKeys);
94 foreach ($requiredFields as $field => $title) {
95 if (!in_array($field, $importKeys)) {
96 if ($field === 'contact_id') {
97 if (!$contactFieldsBelowWeightMessage ||
in_array('external_identifier', $importKeys) ||
98 in_array('participant_id', $importKeys)
102 if ($self->isUpdateExisting()) {
103 $errors['_qf_default'] .= ts('Missing required field: Provide Participant ID') . '<br />';
106 $errors['_qf_default'] .= ts('Missing required contact matching fields.') . " $contactFieldsBelowWeightMessage " . ' ' . ts('Or Provide Contact ID or External ID.') . '<br />';
109 elseif (!in_array('event_title', $importKeys)) {
110 $errors['_qf_default'] .= ts('Missing required field: Provide %1 or %2',
111 array(1 => $title, 2 => 'Event Title')
118 if (!empty($fields['saveMapping'])) {
119 $nameField = $fields['saveMappingName'] ??
NULL;
120 if (empty($nameField)) {
121 $errors['saveMappingName'] = ts('Name is required to save Import Mapping');
124 if (CRM_Core_BAO_Mapping
::checkMapping($nameField, CRM_Core_PseudoConstant
::getKey('CRM_Core_BAO_Mapping', 'mapping_type_id', 'Import Participant'))) {
125 $errors['saveMappingName'] = ts('Duplicate Import Participant Mapping Name');
130 //display Error if loaded mapping is not selected
131 if (array_key_exists('loadMapping', $fields)) {
132 $getMapName = $fields['savedMapping'] ??
NULL;
133 if (empty($getMapName)) {
134 $errors['savedMapping'] = ts('Select saved mapping');
138 if (empty($errors['_qf_default'])) {
139 unset($errors['_qf_default']);
141 if (!empty($errors)) {
142 if (!empty($errors['saveMappingName'])) {
144 $assignError = new CRM_Core_Page();
145 $assignError->assign('mappingDetailsError', $_flag);
154 * @return CRM_Event_Import_Parser_Participant
156 protected function getParser(): CRM_Event_Import_Parser_Participant
{
157 if (!$this->parser
) {
158 $this->parser
= new CRM_Event_Import_Parser_Participant();
159 $this->parser
->setUserJobID($this->getUserJobID());
160 $this->parser
->init();
162 return $this->parser
;
166 * Get the fields to highlight.
170 protected function getHighlightedFields(): array {
171 $highlightedFields = [];
172 if ($this->isUpdateExisting()) {
173 $highlightedFieldsArray = [
179 foreach ($highlightedFieldsArray as $name) {
180 $highlightedFields[] = $name;
183 elseif ($this->getSubmittedValue('onDuplicate') == CRM_Import_Parser
::DUPLICATE_SKIP ||
184 $this->getSubmittedValue('onDuplicate') == CRM_Import_Parser
::DUPLICATE_NOCHECK
186 // this should be retrieved from the parser.
187 $highlightedFieldsArray = [
195 'external_identifier',
198 foreach ($highlightedFieldsArray as $name) {
199 $highlightedFields[] = $name;
202 return $highlightedFields;
206 * Get the mapping name per the civicrm_mapping_field.type_id option group.
210 public function getMappingTypeName(): string {
211 return 'Import Participant';