Example #1
0
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     $this->addFormRule(array('CRM_Custom_Import_Form_MapField', 'formRule'));
 }
Example #2
0
 /**
  * Set variables up before form is built.
  */
 public function preProcess()
 {
     $dataSource = $this->get('dataSource');
     $skipColumnHeader = $this->get('skipColumnHeader');
     $this->_mapperFields = $this->get('fields');
     $this->_importTableName = $this->get('importTableName');
     $this->_onDuplicate = $this->get('onDuplicate');
     $highlightedFields = array();
     $highlightedFields[] = 'email';
     $highlightedFields[] = 'external_identifier';
     //format custom field names, CRM-2676
     switch ($this->get('contactType')) {
         case CRM_Import_Parser::CONTACT_INDIVIDUAL:
             $contactType = 'Individual';
             $highlightedFields[] = 'first_name';
             $highlightedFields[] = 'last_name';
             break;
         case CRM_Import_Parser::CONTACT_HOUSEHOLD:
             $contactType = 'Household';
             $highlightedFields[] = 'household_name';
             break;
         case CRM_Import_Parser::CONTACT_ORGANIZATION:
             $contactType = 'Organization';
             $highlightedFields[] = 'organization_name';
             break;
     }
     $this->_contactType = $contactType;
     if ($this->_onDuplicate == CRM_Import_Parser::DUPLICATE_SKIP) {
         unset($this->_mapperFields['id']);
     } else {
         $highlightedFields[] = 'id';
     }
     if ($this->_onDuplicate != CRM_Import_Parser::DUPLICATE_NOCHECK) {
         //Mark Dedupe Rule Fields as required, since it's used in matching contact
         foreach (array('Individual', 'Household', 'Organization') as $cType) {
             $ruleParams = array('contact_type' => $cType, 'used' => 'Unsupervised');
             $this->_dedupeFields[$cType] = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
         }
         //Modify mapper fields title if fields are present in dedupe rule
         if (is_array($this->_dedupeFields[$contactType])) {
             foreach ($this->_dedupeFields[$contactType] as $val) {
                 if ($valTitle = CRM_Utils_Array::value($val, $this->_mapperFields)) {
                     $this->_mapperFields[$val] = $valTitle . ' (match to contact)';
                 }
             }
         }
     }
     // retrieve and highlight required custom fields
     $formattedFieldNames = $this->formatCustomFieldName($this->_mapperFields);
     self::$customFields = CRM_Core_BAO_CustomField::getFields($this->_contactType);
     foreach (self::$customFields as $key => $attr) {
         if (!empty($attr['is_required'])) {
             $highlightedFields[] = "custom_{$key}";
         }
     }
     $this->assign('highlightedFields', $highlightedFields);
     $this->_formattedFieldNames[$contactType] = $this->_mapperFields = array_merge($this->_mapperFields, $formattedFieldNames);
     $columnNames = array();
     //get original col headers from csv if present.
     if ($dataSource == 'CRM_Import_DataSource_CSV' && $skipColumnHeader) {
         $columnNames = $this->get('originalColHeader');
     } else {
         // get the field names from the temp. DB table
         $dao = new CRM_Core_DAO();
         $db = $dao->getDatabaseConnection();
         $columnsQuery = "SHOW FIELDS FROM {$this->_importTableName}\n                         WHERE Field NOT LIKE '\\_%'";
         $columnsResult = $db->query($columnsQuery);
         while ($row = $columnsResult->fetchRow(DB_FETCHMODE_ASSOC)) {
             $columnNames[] = $row['Field'];
         }
     }
     $showColNames = TRUE;
     if ($dataSource == 'CRM_Import_DataSource_CSV' && !$skipColumnHeader) {
         $showColNames = FALSE;
     }
     $this->assign('showColNames', $showColNames);
     $this->_columnCount = count($columnNames);
     $this->_columnNames = $columnNames;
     $this->assign('columnNames', $columnNames);
     //$this->_columnCount = $this->get( 'columnCount' );
     $this->assign('columnCount', $this->_columnCount);
     $this->_dataValues = $this->get('dataValues');
     $this->assign('dataValues', $this->_dataValues);
     $this->assign('rowDisplayCount', 2);
 }