3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
30 * @copyright CiviCRM LLC (c) 2004-2018
34 * This class gets the name of the file to upload.
36 * TODO: CRM-11254 - There's still a lot of duplicate code in the 5 child classes that should be moved here
38 abstract class CRM_Import_Form_MapField
extends CRM_Core_Form
{
41 * Cache of preview data values
45 protected $_dataValues;
52 protected $_mapperFields;
59 protected $_loadedMappingId;
62 * Number of columns in import file
66 protected $_columnCount;
69 * Column headers, if we have them
73 protected $_columnHeaders;
76 * An array of booleans to keep track of whether a field has been used in
77 * form building already.
81 protected $_fieldUsed;
84 * Return a descriptive name for the page, used in wizard header.
88 public function getTitle() {
89 return ts('Match Fields');
93 * Attempt to match header labels with our mapper fields.
95 * @param string $header
96 * @param array $patterns
100 public function defaultFromHeader($header, &$patterns) {
101 foreach ($patterns as $key => $re) {
102 // Skip empty key/patterns
103 if (!$key ||
!$re ||
strlen("$re") < 5) {
107 // Scan through the headerPatterns defined in the schema for a match
108 if (preg_match($re, $header)) {
109 $this->_fieldUsed
[$key] = TRUE;
117 * Guess at the field names given the data and patterns from the schema.
119 * @param array $patterns
120 * @param string $index
124 public function defaultFromData(&$patterns, $index) {
127 $n = count($this->_dataValues
);
129 foreach ($patterns as $key => $re) {
130 // Skip empty key/patterns
131 if (!$key ||
!$re ||
strlen("$re") < 5) {
135 /* Take a vote over the preview data set */
137 for ($i = 0; $i < $n; $i++
) {
138 if (isset($this->_dataValues
[$i][$index])) {
139 if (preg_match($re, $this->_dataValues
[$i][$index])) {
144 if ($hits > $bestHits) {
151 $this->_fieldUsed
[$best] = TRUE;