3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
37 * This class gets the name of the file to upload
38 * TODO: CRM-11254 - There's still a lot of duplicate code in the 5 child classes that should be moved here
40 abstract class CRM_Import_Form_MapField
extends CRM_Core_Form
{
43 * Cache of preview data values
47 protected $_dataValues;
54 protected $_mapperFields;
61 protected $_loadedMappingId;
64 * Number of columns in import file
68 protected $_columnCount;
71 * Column headers, if we have them
75 protected $_columnHeaders;
78 * An array of booleans to keep track of whether a field has been used in
79 * form building already.
83 protected $_fieldUsed;
86 * Return a descriptive name for the page, used in wizard header
90 public function getTitle() {
91 return ts('Match Fields');
95 * Attempt to match header labels with our mapper fields.
97 * @param string $header
98 * @param array $patterns
102 public function defaultFromHeader($header, &$patterns) {
103 foreach ($patterns as $key => $re) {
104 // Skip empty key/patterns
105 if (!$key ||
!$re ||
strlen("$re") < 5) {
109 // Scan through the headerPatterns defined in the schema for a match
110 if (preg_match($re, $header)) {
111 $this->_fieldUsed
[$key] = TRUE;
119 * Guess at the field names given the data and patterns from the schema.
121 * @param array $patterns
122 * @param string $index
126 public function defaultFromData(&$patterns, $index) {
129 $n = count($this->_dataValues
);
131 foreach ($patterns as $key => $re) {
132 // Skip empty key/patterns
133 if (!$key ||
!$re ||
strlen("$re") < 5) {
137 /* Take a vote over the preview data set */
139 for ($i = 0; $i < $n; $i++
) {
140 if (isset($this->_dataValues
[$i][$index])) {
141 if (preg_match($re, $this->_dataValues
[$i][$index])) {
146 if ($hits > $bestHits) {
153 $this->_fieldUsed
[$best] = TRUE;