$re) { // Skip empty key/patterns if (!$key || !$re || strlen("$re") < 5) { continue; } // Scan through the headerPatterns defined in the schema for a match if (preg_match($re, $header)) { $this->_fieldUsed[$key] = TRUE; return $key; } } return ''; } /** * Guess at the field names given the data and patterns from the schema. * * @param array $patterns * @param string $index * * @return string */ public function defaultFromData($patterns, $index) { $best = ''; $bestHits = 0; $n = count($this->_dataValues); foreach ($patterns as $key => $re) { // Skip empty key/patterns if (!$key || !$re || strlen("$re") < 5) { continue; } /* Take a vote over the preview data set */ $hits = 0; for ($i = 0; $i < $n; $i++) { if (isset($this->_dataValues[$i][$index])) { if (preg_match($re, $this->_dataValues[$i][$index])) { $hits++; } } } if ($hits > $bestHits) { $bestHits = $hits; $best = $key; } } if ($best != '') { $this->_fieldUsed[$best] = TRUE; } return $best; } /** * Add the saved mapping fields to the form. * * @param int|null $savedMappingID * * @throws \CiviCRM_API3_Exception */ protected function buildSavedMappingFields($savedMappingID) { //to save the current mappings if (!$savedMappingID) { $saveDetailsName = ts('Save this field mapping'); $this->applyFilter('saveMappingName', 'trim'); $this->add('text', 'saveMappingName', ts('Name')); $this->add('text', 'saveMappingDesc', ts('Description')); } else { $savedMapping = $this->get('savedMapping'); $mappingName = (string) civicrm_api3('Mapping', 'getvalue', ['id' => $savedMappingID, 'return' => 'name']); $this->set('loadedMapping', $savedMapping); $this->assign('loadedMapping', $mappingName); $this->assign('savedName', $mappingName); $this->add('hidden', 'mappingId', $savedMappingID); $this->addElement('checkbox', 'updateMapping', ts('Update this field mapping'), NULL); $saveDetailsName = ts('Save as a new field mapping'); $this->add('text', 'saveMappingName', ts('Name')); $this->add('text', 'saveMappingDesc', ts('Description')); } $this->addElement('checkbox', 'saveMapping', $saveDetailsName, NULL, ['onclick' => "showSaveDetails(this)"]); } }