/** * class constructor */ function CRM_Import_Parser_Contact(&$mapperKeys, $mapperLocType = null, $mapperPhoneType = null, $mapperRelated = null, $mapperRelatedContactType = null, $mapperRelatedContactDetails = null, $mapperRelatedContactLocType = null, $mapperRelatedContactPhoneType = null) { parent::CRM_Import_Parser(); $this->_mapperKeys =& $mapperKeys; $this->_mapperLocType =& $mapperLocType; $this->_mapperPhoneType =& $mapperPhoneType; $this->_mapperRelated =& $mapperRelated; $this->_mapperRelatedContactType =& $mapperRelatedContactType; $this->_mapperRelatedContactDetails =& $mapperRelatedContactDetails; $this->_mapperRelatedContactLocType =& $mapperRelatedContactLocType; $this->_mapperRelatedContactPhoneType =& $mapperRelatedContactPhoneType; }
/** * class constructor */ function __construct(&$mapperKeys, $mapperLocType = null, $mapperPhoneType = null, $mapperImProvider = null, $mapperRelated = null, $mapperRelatedContactType = null, $mapperRelatedContactDetails = null, $mapperRelatedContactLocType = null, $mapperRelatedContactPhoneType = null, $mapperRelatedContactImProvider = null) { parent::__construct(); $this->_mapperKeys =& $mapperKeys; $this->_mapperLocType =& $mapperLocType; $this->_mapperPhoneType =& $mapperPhoneType; // get IM service provider type id for contact $this->_mapperImProvider =& $mapperImProvider; $this->_mapperRelated =& $mapperRelated; $this->_mapperRelatedContactType =& $mapperRelatedContactType; $this->_mapperRelatedContactDetails =& $mapperRelatedContactDetails; $this->_mapperRelatedContactLocType =& $mapperRelatedContactLocType; $this->_mapperRelatedContactPhoneType =& $mapperRelatedContactPhoneType; // get IM service provider type id for related contact $this->_mapperRelatedContactImProvider =& $mapperRelatedContactImProvider; }
/** * Determines the file name based on error code. * * @param int $type * Error code constant. * * @return string */ public static function saveFileName($type) { $fileName = NULL; if (empty($type)) { return $fileName; } switch ($type) { case CRM_Contribute_Import_Parser::SOFT_CREDIT_ERROR: $fileName = 'Import_Soft_Credit_Errors.csv'; break; case CRM_Contribute_Import_Parser::PLEDGE_PAYMENT_ERROR: $fileName = 'Import_Pledge_Payment_Errors.csv'; break; default: $fileName = parent::saveFileName($type); break; } return $fileName; }
function saveFileName($type) { $fileName = null; if (empty($type)) { return $fileName; } switch ($type) { case CRM_Contribute_Import_Parser::ERROR: case CRM_Contribute_Import_Parser::NO_MATCH: case CRM_Contribute_Import_Parser::CONFLICT: case CRM_Contribute_Import_Parser::DUPLICATE: //here constants get collides. require_once 'CRM/Import/Parser.php'; if ($type == CRM_Contribute_Import_Parser::ERROR) { $type = CRM_Import_Parser::ERROR; } else { if ($type == CRM_Contribute_Import_Parser::NO_MATCH) { $type = CRM_Import_Parser::NO_MATCH; } else { if ($type == CRM_Contribute_Import_Parser::CONFLICT) { $type = CRM_Import_Parser::CONFLICT; } else { $type = CRM_Import_Parser::DUPLICATE; } } } $fileName = CRM_Import_Parser::saveFileName($type); break; case CRM_Contribute_Import_Parser::SOFT_CREDIT_ERROR: $fileName = 'Import_Soft_Credit_Errors.csv'; break; case CRM_Contribute_Import_Parser::PLEDGE_PAYMENT_ERROR: $fileName = 'Import_Pledge_Payment_Errors.csv'; break; } return $fileName; }
function saveFileName($type) { require_once 'CRM/Import/Parser.php'; $fileName = CRM_Import_Parser::saveFileName($type); return $fileName; }
function saveFileName($type) { $fileName = CRM_Import_Parser::saveFileName($type); return $fileName; }
function run($fileName, $seperator = ',', &$mapper, $skipColumnHeader = false, $mode = CRM_IMPORT_PARSER_MODE_PREVIEW, $contactType = CRM_IMPORT_PARSER_CONTACT_INDIVIDUAL, $onDuplicate = CRM_IMPORT_PARSER_DUPLICATE_SKIP) { switch ($contactType) { case CRM_IMPORT_PARSER_CONTACT_INDIVIDUAL: $this->_contactType = 'Individual'; break; case CRM_IMPORT_PARSER_CONTACT_HOUSEHOLD: $this->_contactType = 'Household'; break; case CRM_IMPORT_PARSER_CONTACT_ORGANIZATION: $this->_contactType = 'Organization'; } $this->init(); $this->_seperator = $seperator; $fd = fopen($fileName, "r"); if (!$fd) { return false; } $this->_lineCount = $this->_warningCount = 0; $this->_invalidRowCount = $this->_validCount = 0; $this->_totalCount = $this->_conflictCount = 0; $this->_errors = array(); $this->_warnings = array(); $this->_conflicts = array(); $this->_fileSize = number_format(filesize($fileName) / 1024.0, 2); if ($mode == CRM_IMPORT_PARSER_MODE_MAPFIELD) { $this->_rows = array(); } else { $this->_activeFieldCount = count($this->_activeFields); } if ($mode == CRM_IMPORT_PARSER_MODE_IMPORT) { //get the key of email field foreach ($mapper as $key => $value) { if (strtolower($value) == 'email') { $emailKey = $key; break; } } } while (!feof($fd)) { $this->_lineCount++; $values = fgetcsv($fd, 8192, $seperator); if (!$values) { continue; } CRM_Import_Parser::encloseScrub($values); // skip column header if we're not in mapfield mode if ($mode != CRM_IMPORT_PARSER_MODE_MAPFIELD && $skipColumnHeader) { $skipColumnHeader = false; continue; } /* trim whitespace around the values */ $empty = true; foreach ($values as $k => $v) { $values[$k] = trim($v, " .\t\r\n"); } if (CRM_Utils_System::isNull($values)) { continue; } $this->_totalCount++; if ($mode == CRM_IMPORT_PARSER_MODE_MAPFIELD) { $returnCode = $this->mapField($values); } else { if ($mode == CRM_IMPORT_PARSER_MODE_PREVIEW) { $returnCode = $this->preview($values); } else { if ($mode == CRM_IMPORT_PARSER_MODE_SUMMARY) { $returnCode = $this->summary($values); } else { if ($mode == CRM_IMPORT_PARSER_MODE_IMPORT) { $returnCode = $this->import($onDuplicate, $values); } else { $returnCode = CRM_IMPORT_PARSER_ERROR; } } } } // note that a line could be valid but still produce a warning if ($returnCode & CRM_IMPORT_PARSER_VALID) { $this->_validCount++; if ($mode == CRM_IMPORT_PARSER_MODE_MAPFIELD) { $this->_rows[] = $values; $this->_activeFieldCount = max($this->_activeFieldCount, count($values)); } } if ($returnCode & CRM_IMPORT_PARSER_WARNING) { $this->_warningCount++; if ($this->_warningCount < $this->_maxWarningCount) { $this->_warningCount[] = $line; } } if ($returnCode & CRM_IMPORT_PARSER_ERROR) { $this->_invalidRowCount++; if ($this->_invalidRowCount < $this->_maxErrorCount) { array_unshift($values, $this->_lineCount); $this->_errors[] = $values; } } if ($returnCode & CRM_IMPORT_PARSER_CONFLICT) { $this->_conflictCount++; array_unshift($values, $this->_lineCount); $this->_conflicts[] = $values; } if ($returnCode & CRM_IMPORT_PARSER_NO_MATCH) { $this->_unMatchCount++; array_unshift($values, $this->_lineCount); $this->_unMatch[] = $values; } if ($returnCode & CRM_IMPORT_PARSER_DUPLICATE) { if ($returnCode & CRM_IMPORT_PARSER_MULTIPLE_DUPE) { /* TODO: multi-dupes should be counted apart from singles * on non-skip action */ } $this->_duplicateCount++; array_unshift($values, $this->_lineCount); $this->_duplicates[] = $values; if ($onDuplicate != CRM_IMPORT_PARSER_DUPLICATE_SKIP) { $this->_validCount++; } } // we give the derived class a way of aborting the process // note that the return code could be multiple code or'ed together if ($returnCode & CRM_IMPORT_PARSER_STOP) { break; } // if we are done processing the maxNumber of lines, break if ($this->_maxLinesToProcess > 0 && $this->_validCount >= $this->_maxLinesToProcess) { break; } } fclose($fd); if ($mode == CRM_IMPORT_PARSER_MODE_PREVIEW || $mode == CRM_IMPORT_PARSER_MODE_IMPORT) { $customHeaders = $mapper; $customfields =& CRM_Core_BAO_CustomField::getFields($this->_contactType); foreach ($customHeaders as $key => $value) { if ($id = CRM_Core_BAO_CustomField::getKeyID($value)) { $customHeaders[$key] = $customfields[$id][0]; } } if ($this->_invalidRowCount) { // removed view url for invlaid contacts $headers = array_merge(array(ts('Record Number'), ts('Reason')), $customHeaders); $this->_errorFileName = $fileName . '.errors'; CRM_Import_Parser::exportCSV($this->_errorFileName, $headers, $this->_errors); } if ($this->_conflictCount) { $headers = array_merge(array(ts('Record Number'), ts('Reason')), $customHeaders); $this->_conflictFileName = $fileName . '.conflicts'; CRM_Import_Parser::exportCSV($this->_conflictFileName, $headers, $this->_conflicts); } if ($this->_duplicateCount) { $headers = array_merge(array(ts('Record Number'), ts('View Contact URL')), $customHeaders); $this->_duplicateFileName = $fileName . '.duplicates'; CRM_Import_Parser::exportCSV($this->_duplicateFileName, $headers, $this->_duplicates); } if ($this->_unMatchCount) { $headers = array_merge(array(ts('Record Number'), ts('Reason')), $customHeaders); $this->_misMatchFilemName = $fileName . '.mismatch'; CRM_Import_Parser::exportCSV($this->_misMatchFilemName, $headers, $this->_unMatch); } } //echo "$this->_totalCount,$this->_invalidRowCount,$this->_conflictCount,$this->_duplicateCount"; return $this->fini(); }