* FIXME: This is essentially the same function as parent::defaultFromHeader
*
* @param string $columnName name of column header
- * @param array $patterns pattern to match for the column
*
* @return string
*/
- public function defaultFromColumnName($columnName, $patterns) {
+ public function defaultFromColumnName($columnName) {
if (!preg_match('/^[a-z0-9 ]$/i', $columnName)) {
- if ($columnKey = array_search($columnName, $this->_mapperFields)) {
+ if ($columnKey = array_search($columnName, $this->getFieldTitles())) {
$this->_fieldUsed[$columnKey] = TRUE;
return $columnKey;
}
}
- foreach ($patterns as $key => $re) {
+ foreach ($this->getHeaderPatterns() as $key => $re) {
// Skip empty key/patterns
if (!$key || !$re || strlen("$re") < 5) {
continue;
$defaults = [];
$mapperKeys = array_keys($this->_mapperFields);
$hasColumnNames = !empty($this->_columnNames);
- $columnPatterns = $this->get('columnPatterns');
$dataPatterns = $this->get('dataPatterns');
$hasLocationTypes = $this->get('fieldTypes');
$processor->setFormName($formName);
$processor->setMetadata($this->getContactImportMetadata());
$processor->setContactTypeByConstant($this->get('contactType'));
+ $processor->setContactSubType($this->get('contactSubType'));
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, $defaults, $js, $hasColumnNames, $dataPatterns, $columnPatterns);
+ list($defaults, $js) = $this->loadSavedMapping($processor, $mappingName, $i, $defaults, $js, $hasColumnNames, $dataPatterns);
}
else {
$js .= "swapOptions($formName, 'mapper[$i]', 0, 3, 'hs_mapper_0_');\n";
if ($hasColumnNames) {
// do array search first to see if has mapped key
- $columnKey = array_search($this->_columnNames[$i], $this->_mapperFields);
+ $columnKey = array_search($this->_columnNames[$i], $this->getFieldTitles());
if (isset($this->_fieldUsed[$columnKey])) {
$defaults["mapper[$i]"] = $columnKey;
$this->_fieldUsed[$key] = TRUE;
else {
// Infer the default from the column names if we have them
$defaults["mapper[$i]"] = [
- $this->defaultFromColumnName($this->_columnNames[$i],
- $columnPatterns
- ),
+ $this->defaultFromColumnName($this->_columnNames[$i]),
0,
];
}
elseif (CRM_Utils_Array::value('1', $mapperKeys[$i]) == 'im') {
$updateMappingFields->im_provider_id = isset($mapperKeys[$i][3]) ? $mapperKeys[$i][3] : NULL;
}
- $updateMappingFields->location_type_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : NULL;
+ $updateMappingFields->location_type_id = isset($mapperKeys[$i][2]) && is_numeric($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : NULL;
}
}
else {
* @param string $js
* @param bool $hasColumnNames
* @param array $dataPatterns
- * @param array $columnPatterns
*
* @return array
* @throws \CiviCRM_API3_Exception
*/
- public function loadSavedMapping($processor, $mappingName, $i, $defaults, $js, $hasColumnNames, $dataPatterns, $columnPatterns) {
- $jsSet = FALSE;
+ public function loadSavedMapping($processor, $mappingName, $i, $defaults, $js, $hasColumnNames, $dataPatterns) {
$formName = $processor->getFormName();
if (isset($mappingName[$i])) {
if ($mappingName[$i] != ts('- do not import -')) {
-
- if ($processor->getRelationshipKey($i)) {
- $contactType = $processor->getContactType();
- //CRM-5125
- $contactSubType = NULL;
- if ($this->get('contactSubType')) {
- $contactSubType = $this->get('contactSubType');
- }
-
- $relations = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $contactType,
- FALSE, 'label', TRUE, $contactSubType
- );
-
- foreach ($relations as $key => $var) {
- if ($processor->getValidRelationshipKey($i)) {
- $relation = $processor->getValidRelationshipKey($i);
- break;
- }
- }
-
- $contactDetails = strtolower(str_replace(" ", "_", $mappingName[$i]));
- $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];
- }
- else {
-
- $defaults["mapper[$i]"] = [$relation, $contactDetails, $locationId, $typeId];
- if (!$locationId) {
- $js .= "{$formName}['mapper[$i][2]'].style.display = 'none';\n";
- }
- }
- // fix for edge cases, CRM-4954
- if ($contactDetails == 'image_url') {
- $contactDetails = str_replace('url', 'URL', $contactDetails);
- }
-
- if (!$contactDetails) {
- $js .= "{$formName}['mapper[$i][1]'].style.display = 'none';\n";
- }
-
- if ((!$phoneType) && (!$imProvider)) {
- $js .= "{$formName}['mapper[$i][3]'].style.display = 'none';\n";
- }
- //$js .= "{$formName}['mapper[$i][3]'].style.display = 'none';\n";
- $jsSet = TRUE;
- }
- else {
- $defaults["mapper[$i]"] = $processor->getSavedQuickformDefaultsForColumn($i);
- $js .= $processor->getQuickFormJSForField($i);
-
- $jsSet = TRUE;
- }
+ $defaults["mapper[$i]"] = $processor->getSavedQuickformDefaultsForColumn($i);
+ $js .= $processor->getQuickFormJSForField($i);
}
else {
$defaults["mapper[$i]"] = [];
- }
- if (!$jsSet) {
for ($k = 1; $k < 4; $k++) {
$js .= "{$formName}['mapper[$i][$k]'].style.display = 'none';\n";
}
$js .= "swapOptions($formName, 'mapper[$i]', 0, 3, 'hs_mapper_0_');\n";
if ($hasColumnNames) {
- $defaults["mapper[$i]"] = [$this->defaultFromColumnName($this->_columnNames[$i], $columnPatterns)];
+ $defaults["mapper[$i]"] = [$this->defaultFromColumnName($this->_columnNames[$i])];
}
else {
$defaults["mapper[$i]"] = [$this->defaultFromData($dataPatterns, $i)];