Merge remote-tracking branch 'upstream/4.3' into 4.3-4.4-2013-11-03-17-29-16
[civicrm-core.git] / CRM / Member / Import / Form / MapField.php
index 81ec6ce08e607d6577bd1f44632821756011c095..51123c3dc89a73652b2a2cebde576f2697443248 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
 /**
  * This class gets the name of the file to upload
  */
-class CRM_Member_Import_Form_MapField extends CRM_Core_Form {
+class CRM_Member_Import_Form_MapField extends CRM_Import_Form_MapField {
 
-  /**
-   * cache of preview data values
-   *
-   * @var array
-   * @access protected
-   */
-  protected $_dataValues;
 
-  /**
-   * mapper fields
-   *
-   * @var array
-   * @access protected
-   */
-  protected $_mapperFields;
-
-  /**
-   * loaded mapping ID
-   *
-   * @var int
-   * @access protected
-   */
-  protected $_loadedMappingId;
-
-  /**
-   * number of columns in import file
-   *
-   * @var int
-   * @access protected
-   */
-  protected $_columnCount;
-
-  /**
-   * column headers, if we have them
-   *
-   * @var array
-   * @access protected
-   */
-  protected $_columnHeaders;
-
-  /**
-   * an array of booleans to keep track of whether a field has been used in
-   * form building already.
-   *
-   * @var array
-   * @access protected
-   */
-  protected $_fieldUsed;
 
   /**
    * to store contactType
@@ -95,74 +48,6 @@ class CRM_Member_Import_Form_MapField extends CRM_Core_Form {
    */
   static $_contactType = NULL;
 
-  /**
-   * Attempt to match header labels with our mapper fields
-   *
-   * @param header
-   * @param mapperFields
-   *
-   * @return string
-   * @access public
-   */
-  public function defaultFromHeader($header, &$patterns) {
-    foreach ($patterns as $key => $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 patterns
-   * @param index
-   *
-   * @return string
-   * @access public
-   */
-  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;
-      }
-
-      //             if ($this->_fieldUsed[$key])
-      //                 continue;
-
-      /* Take a vote over the preview data set */
-
-      $hits = 0;
-      for ($i = 0; $i < $n; $i++) {
-        if (preg_match($re, $this->_dataValues[$i][$index])) {
-          $hits++;
-        }
-      }
-
-      if ($hits > $bestHits) {
-        $bestHits = $hits;
-        $best = $key;
-      }
-    }
-
-    if ($best != '') {
-      $this->_fieldUsed[$best] = TRUE;
-    }
-    return $best;
-  }
 
   /**
    * Function to set variables up before form is built
@@ -179,7 +64,7 @@ class CRM_Member_Import_Form_MapField extends CRM_Core_Form {
     $this->_dataValues = $this->get('dataValues');
     $this->assign('dataValues', $this->_dataValues);
 
-    $skipColumnHeader = $this->controller->exportValue('UploadFile', 'skipColumnHeader');
+    $skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader');
     $this->_onDuplicate = $this->get('onDuplicate', isset($onDuplicate) ? $onDuplicate : "");
 
     $highlightedFields = array();
@@ -196,7 +81,7 @@ class CRM_Member_Import_Form_MapField extends CRM_Core_Form {
 
     //CRM-2219 removing other required fields since for updation only
     //membership id is required.
-    if ($this->_onDuplicate == CRM_Member_Import_Parser::DUPLICATE_UPDATE) {
+    if ($this->_onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE) {
       $remove = array('membership_contact_id', 'email', 'first_name', 'last_name', 'external_identifier');
       foreach ($remove as $value) {
         unset($this->_mapperFields[$value]);
@@ -206,7 +91,7 @@ class CRM_Member_Import_Form_MapField extends CRM_Core_Form {
         $highlightedFields[] = $name;
       }
     }
-    elseif ($this->_onDuplicate == CRM_Member_Import_Parser::DUPLICATE_SKIP) {
+    elseif ($this->_onDuplicate == CRM_Import_Parser::DUPLICATE_SKIP) {
       unset($this->_mapperFields['membership_id']);
       $highlightedFieldsArray = array('membership_contact_id', 'email', 'external_identifier', 'membership_start_date', 'membership_type_id');
       foreach ($highlightedFieldsArray as $name) {
@@ -438,9 +323,9 @@ class CRM_Member_Import_Form_MapField extends CRM_Core_Form {
 
       $contactTypeId = $self->get('contactType');
       $contactTypes = array(
-        CRM_Member_Import_Parser::CONTACT_INDIVIDUAL => 'Individual',
-        CRM_Member_Import_Parser::CONTACT_HOUSEHOLD => 'Household',
-        CRM_Member_Import_Parser::CONTACT_ORGANIZATION => 'Organization',
+        CRM_Import_Parser::CONTACT_INDIVIDUAL => 'Individual',
+        CRM_Import_Parser::CONTACT_HOUSEHOLD => 'Household',
+        CRM_Import_Parser::CONTACT_ORGANIZATION => 'Organization',
       );
       $params = array(
         'used'         => 'Unsupervised',
@@ -462,7 +347,7 @@ class CRM_Member_Import_Form_MapField extends CRM_Core_Form {
         if (!in_array($field, $importKeys)) {
           if ($field == 'membership_contact_id') {
             if ((($weightSum >= $threshold || in_array('external_identifier', $importKeys)) &&
-                $self->_onDuplicate != CRM_Member_Import_Parser::DUPLICATE_UPDATE
+                $self->_onDuplicate != CRM_Import_Parser::DUPLICATE_UPDATE
               ) ||
               in_array('membership_id', $importKeys)
             ) {
@@ -530,8 +415,8 @@ class CRM_Member_Import_Form_MapField extends CRM_Core_Form {
       return;
     }
 
-    $fileName = $this->controller->exportValue('UploadFile', 'uploadFile');
-    $skipColumnHeader = $this->controller->exportValue('UploadFile', 'skipColumnHeader');
+    $fileName = $this->controller->exportValue('DataSource', 'uploadFile');
+    $skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader');
 
     $config = CRM_Core_Config::singleton();
     $seperator = $config->fieldSeparator;
@@ -626,20 +511,10 @@ class CRM_Member_Import_Form_MapField extends CRM_Core_Form {
 
     $parser = new CRM_Member_Import_Parser_Membership($mapperKeysMain, $mapperLocType, $mapperPhoneType);
     $parser->run($fileName, $seperator, $mapper, $skipColumnHeader,
-      CRM_Member_Import_Parser::MODE_PREVIEW, $this->get('contactType')
+      CRM_Import_Parser::MODE_PREVIEW, $this->get('contactType')
     );
     // add all the necessary variables to the form
     $parser->set($this);
   }
-
-  /**
-   * Return a descriptive name for the page, used in wizard header
-   *
-   * @return string
-   * @access public
-   */
-  public function getTitle() {
-    return ts('Match Fields');
-  }
 }