X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContact%2FImport%2FForm%2FMapField.php;h=58423b71a8a34c3ee66ab6eafe6a897ba38855c7;hb=3c23826507d740d79ea52a6a26fc6cea526b4632;hp=8c0ef827acb92e406f6bdb47ecae46cb2a01db8f;hpb=98af96fb4c98d37c3022f624a7adb813ff795183;p=civicrm-core.git diff --git a/CRM/Contact/Import/Form/MapField.php b/CRM/Contact/Import/Form/MapField.php index 8c0ef827ac..58423b71a8 100644 --- a/CRM/Contact/Import/Form/MapField.php +++ b/CRM/Contact/Import/Form/MapField.php @@ -209,13 +209,10 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { else { $savedMapping = $this->get('savedMapping'); - list($mappingName, $mappingContactType, $mappingLocation, $mappingPhoneType, $mappingImProvider, $mappingRelation, $mappingOperator, $mappingValue, $mappingWebsiteType) = CRM_Core_BAO_Mapping::getMappingFields($savedMapping, TRUE); + list($mappingName) = CRM_Core_BAO_Mapping::getMappingFields($savedMapping, TRUE); //get loaded Mapping Fields $mappingName = CRM_Utils_Array::value(1, $mappingName); - $mappingLocation = CRM_Utils_Array::value(1, $mappingLocation); - $mappingRelation = CRM_Utils_Array::value(1, $mappingRelation); - $mappingWebsiteType = CRM_Utils_Array::value(1, $mappingWebsiteType); $this->assign('loadedMapping', $savedMapping); $this->set('loadedMapping', $savedMapping); @@ -402,12 +399,13 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { $processor->setMappingID($savedMappingID); $processor->setFormName($formName); $processor->setMetadata($this->getContactImportMetadata()); + $processor->setContactTypeByConstant($this->get('contactType')); for ($i = 0; $i < $this->_columnCount; $i++) { $sel = &$this->addElement('hierselect', "mapper[$i]", ts('Mapper for Field %1', [1 => $i]), NULL); if ($this->get('savedMapping')) { - list($defaults, $js) = $this->loadSavedMapping($processor, $mappingName, $i, $mappingRelation, $mappingWebsiteType, $mappingLocation, $defaults, $js, $hasColumnNames, $dataPatterns, $columnPatterns); + list($defaults, $js) = $this->loadSavedMapping($processor, $mappingName, $i, $defaults, $js, $hasColumnNames, $dataPatterns, $columnPatterns); } else { $js .= "swapOptions($formName, 'mapper[$i]', 0, 3, 'hs_mapper_0_');\n"; @@ -849,9 +847,6 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { * @param \CRM_Import_ImportProcessor $processor * @param $mappingName * @param int $i - * @param $mappingRelation - * @param $mappingWebsiteType - * @param $mappingLocation * @param array $defaults * @param string $js * @param bool $hasColumnNames @@ -861,26 +856,14 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { * @return array * @throws \CiviCRM_API3_Exception */ - public function loadSavedMapping($processor, $mappingName, $i, $mappingRelation, $mappingWebsiteType, $mappingLocation, $defaults, $js, $hasColumnNames, $dataPatterns, $columnPatterns) { + public function loadSavedMapping($processor, $mappingName, $i, $defaults, $js, $hasColumnNames, $dataPatterns, $columnPatterns) { $jsSet = FALSE; $formName = $processor->getFormName(); if (isset($mappingName[$i])) { if ($mappingName[$i] != ts('- do not import -')) { - if (isset($mappingRelation[$i])) { - // relationship mapping - switch ($this->get('contactType')) { - case CRM_Import_Parser::CONTACT_INDIVIDUAL: - $contactType = 'Individual'; - break; - - case CRM_Import_Parser::CONTACT_HOUSEHOLD: - $contactType = 'Household'; - break; - - case CRM_Import_Parser::CONTACT_ORGANIZATION: - $contactType = 'Organization'; - } + if ($processor->getRelationshipKey($i)) { + $contactType = $processor->getContactType(); //CRM-5125 $contactSubType = NULL; if ($this->get('contactSubType')) { @@ -892,33 +875,24 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { ); foreach ($relations as $key => $var) { - if ($key == $mappingRelation[$i]) { - $relation = $key; + if ($processor->getValidRelationshipKey($i)) { + $relation = $processor->getValidRelationshipKey($i); break; } } $contactDetails = strtolower(str_replace(" ", "_", $mappingName[$i])); - $websiteTypeId = isset($mappingWebsiteType[$i]) ? $mappingWebsiteType[$i] : NULL; - $locationId = isset($mappingLocation[$i]) ? $mappingLocation[$i] : 0; + $websiteTypeId = $processor->getWebsiteTypeID($i); + $locationId = $processor->getLocationTypeID($i); $phoneType = $processor->getPhoneTypeID($i); $imProvider = $processor->getIMProviderID($i); + $typeId = $processor->getPhoneOrIMTypeID($i); if ($websiteTypeId) { $defaults["mapper[$i]"] = [$relation, $contactDetails, $websiteTypeId]; - if (!$websiteTypeId) { - $js .= "{$formName}['mapper[$i][2]'].style.display = 'none';\n"; - } } else { - // default for IM/phone when mapping with relation is true - $typeId = NULL; - if (isset($phoneType)) { - $typeId = $phoneType; - } - elseif (isset($imProvider)) { - $typeId = $imProvider; - } + $defaults["mapper[$i]"] = [$relation, $contactDetails, $locationId, $typeId]; if (!$locationId) { $js .= "{$formName}['mapper[$i][2]'].style.display = 'none';\n"; @@ -940,35 +914,20 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { $jsSet = TRUE; } else { - $mappingHeader = array_keys((array) $this->_mapperFields, $mappingName[$i]); - $websiteTypeId = isset($mappingWebsiteType[$i]) ? $mappingWebsiteType[$i] : NULL; - $locationId = isset($mappingLocation[$i]) ? $mappingLocation[$i] : 0; - $phoneType = $processor->getPhoneTypeID($i); - $imProvider = $processor->getIMProviderID($i); + $mappingHeader = $processor->getFieldName($i); + $websiteTypeId = $processor->getWebsiteTypeID($i); + $locationId = $processor->getLocationTypeID($i); + $typeId = $processor->getPhoneOrIMTypeID($i); if ($websiteTypeId) { - $defaults["mapper[$i]"] = [$mappingHeader[0], $websiteTypeId]; + $defaults["mapper[$i]"] = [$mappingHeader, $websiteTypeId]; } else { - if (!$locationId) { - $js .= "{$formName}['mapper[$i][1]'].style.display = 'none';\n"; - } //default for IM/phone without related contact - $typeId = NULL; - if (isset($phoneType)) { - $typeId = $phoneType; - } - elseif (isset($imProvider)) { - $typeId = $imProvider; - } - $defaults["mapper[$i]"] = [$mappingHeader[0] ?? '', $locationId, $typeId]; - } - - if ((!$phoneType) && (!$imProvider)) { - $js .= "{$formName}['mapper[$i][2]'].style.display = 'none';\n"; + $defaults["mapper[$i]"] = [$mappingHeader ?? '', $locationId, $typeId]; } - $js .= "{$formName}['mapper[$i][3]'].style.display = 'none';\n"; + $js .= $processor->getQuickFormJSForField($i); $jsSet = TRUE; }