3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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
48 protected $_dataValues;
56 protected $_mapperFields;
64 protected $_loadedMappingId;
67 * number of columns in import file
72 protected $_columnCount;
75 * column headers, if we have them
80 protected $_columnHeaders;
83 * an array of booleans to keep track of whether a field has been used in
84 * form building already.
89 protected $_fieldUsed;
92 * Return a descriptive name for the page, used in wizard header
97 public function getTitle() {
98 return ts('Match Fields');
102 * Attempt to match header labels with our mapper fields
105 * @param mapperFields
110 public function defaultFromHeader($header, &$patterns) {
111 foreach ($patterns as $key => $re) {
112 // Skip empty key/patterns
113 if (!$key ||
!$re ||
strlen("$re") < 5) {
117 // Scan through the headerPatterns defined in the schema for a match
118 if (preg_match($re, $header)) {
119 $this->_fieldUsed
[$key] = TRUE;
127 * Guess at the field names given the data and patterns from the schema
135 public function defaultFromData(&$patterns, $index) {
138 $n = count($this->_dataValues
);
140 foreach ($patterns as $key => $re) {
141 // Skip empty key/patterns
142 if (!$key ||
!$re ||
strlen("$re") < 5) {
146 /* Take a vote over the preview data set */
148 for ($i = 0; $i < $n; $i++
) {
149 if (isset($this->_dataValues
[$i][$index])) {
150 if (preg_match($re, $this->_dataValues
[$i][$index])) {
155 if ($hits > $bestHits) {
162 $this->_fieldUsed
[$best] = TRUE;