*/
abstract class CRM_Import_Form_MapField extends CRM_Import_Forms {
- /**
- * Cache of preview data values
- *
- * @var array
- */
- protected $_dataValues;
-
/**
* Mapper fields
*
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.
*
*/
protected function assignMapFieldVariables(): void {
$this->addExpectedSmartyVariables(['highlightedRelFields', 'initHideBoxes']);
- $this->_dataValues = array_values($this->getDataRows([], 2));
$this->assign('columnNames', $this->getColumnHeaders());
$this->assign('showColumnNames', $this->getSubmittedValue('skipColumnHeader') || $this->getSubmittedValue('dataSource') !== 'CRM_Import_DataSource');
$this->assign('highlightedFields', $this->getHighlightedFields());
- $this->assign('dataValues', $this->_dataValues);
+ $this->assign('dataValues', array_values($this->getDataRows([], 2)));
}
/**