class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser

class to parse contact csv files

Constants

MAX_ERRORS

Settings

MAX_WARNINGS

Settings

DEFAULT_TIMEOUT

Settings

VALID

Return codes

WARNING

Return codes

ERROR

Return codes

CONFLICT

Return codes

STOP

Return codes

DUPLICATE

Return codes

MULTIPLE_DUPE

Return codes

NO_MATCH

Return codes

UNPARSED_ADDRESS_WARNING

Return codes

MODE_MAPFIELD

Parser modes

MODE_PREVIEW

Parser modes

MODE_SUMMARY

Parser modes

MODE_IMPORT

Parser modes

DUPLICATE_SKIP

Codes for duplicate record handling

DUPLICATE_REPLACE

Codes for duplicate record handling

DUPLICATE_UPDATE

Codes for duplicate record handling

DUPLICATE_FILL

Codes for duplicate record handling

DUPLICATE_NOCHECK

Codes for duplicate record handling

CONTACT_INDIVIDUAL

Contact types

CONTACT_HOUSEHOLD

Contact types

CONTACT_ORGANIZATION

Contact types

Properties

protected $_totalCount Total number of non empty lines from CRM_Import_Parser
protected $_validCount Running total number of valid lines from CRM_Import_Parser
protected $_invalidRowCount Running total number of invalid rows from CRM_Import_Parser
protected int $_maxLinesToProcess Maximum number of non-empty/comment lines to process from CRM_Import_Parser
protected $_maxErrorCount Maximum number of invalid rows to store from CRM_Import_Parser
protected $_errors Array of error lines, bounded by MAX_ERROR from CRM_Import_Parser
protected $_conflictCount Total number of conflict lines from CRM_Import_Parser
protected $_conflicts Array of conflict lines from CRM_Import_Parser
protected $_duplicateCount Total number of duplicate (from database) lines from CRM_Import_Parser
protected $_duplicates Array of duplicate lines from CRM_Import_Parser
protected $_warningCount Running total number of warnings from CRM_Import_Parser
protected $_maxWarningCount Maximum number of warnings to store from CRM_Import_Parser
protected $_warnings Array of warning lines, bounded by MAX_WARNING from CRM_Import_Parser
protected array $_fields Array of all the fields that could potentially be part of this import process from CRM_Import_Parser
protected array $_activeFields Array of the fields that are actually part of the import process the position in the array also dictates their position in the import file from CRM_Import_Parser
protected int $_activeFieldCount Cache the count of active fields from CRM_Import_Parser
protected array $_rows Cache of preview rows from CRM_Import_Parser
protected string $_errorFileName Filename of error data from CRM_Import_Parser
protected string $_conflictFileName Filename of conflict data from CRM_Import_Parser
protected string $_duplicateFileName Filename of duplicate data from CRM_Import_Parser
int $_contactType Contact type from CRM_Import_Parser
int $_contactSubType Contact sub-type from CRM_Import_Parser
protected $_tableName from CRM_Contact_Import_Parser
protected integer $_rowCount Total number of lines in file from CRM_Contact_Import_Parser
protected $_unMatchCount Running total number of un-matched Contacts. from CRM_Contact_Import_Parser
protected $_unMatch Array of unmatched lines from CRM_Contact_Import_Parser
protected $_unparsedAddressCount Total number of contacts with unparsed addresses from CRM_Contact_Import_Parser
protected string $_misMatchFilemName Filename of mismatch data from CRM_Contact_Import_Parser
protected $_primaryKeyName from CRM_Contact_Import_Parser
protected $_statusFieldName from CRM_Contact_Import_Parser
int $_onDuplicate On duplicate from CRM_Contact_Import_Parser
int $_dedupeRuleGroupID Dedupe rule group id to use if set from CRM_Contact_Import_Parser
protected $_mapperKeys
protected $_mapperLocType
protected $_mapperPhoneType
protected $_mapperImProvider
protected $_mapperWebsiteType
protected $_mapperRelated
protected $_mapperRelatedContactType
protected $_mapperRelatedContactDetails
protected $_mapperRelatedContactEmailType
protected $_mapperRelatedContactImProvider
protected $_mapperRelatedContactWebsiteType
protected $_relationships
protected $_emailIndex
protected $_firstNameIndex
protected $_lastNameIndex
protected $_householdNameIndex
protected $_organizationNameIndex
protected $_allEmails
protected $_phoneIndex
protected bool $_updateWithId Is update only permitted on an id match.
protected $_retCode
protected $_externalIdentifierIndex
protected $_allExternalIdentifiers
protected $_parseStreetAddress
protected $_newContacts Array of successfully imported contact id's
protected int $_lineCount Line count id.
protected $_newRelatedContacts Array of successfully imported related contact id's
protected array $_unparsedStreetAddressContacts Array of all the contacts whose street addresses are not parsed.

Methods

__construct(array $mapperKeys, int $mapperLocType = NULL, int $mapperPhoneType = NULL, int $mapperImProvider = NULL, int $mapperRelated = NULL, int $mapperRelatedContactType = NULL, array $mapperRelatedContactDetails = NULL, int $mapperRelatedContactLocType = NULL, int $mapperRelatedContactPhoneType = NULL, int $mapperRelatedContactImProvider = NULL, int $mapperWebsiteType = NULL, int $mapperRelatedContactWebsiteType = NULL)

Class constructor.

init()

The initializer code, called before processing.

mixed
fini()

The initializer code, called before the processing.

mixed
mapField(array $values)

Handle the values in mapField mode.

mixed
preview(array $values)

Handle the values in preview mode.

mixed
summary($values)

Handle the values in summary mode.

mixed
import($onDuplicate, $values, bool $doGeocodeAddress = FALSE)

Handle the values in import mode.

int
setActiveFieldValues(array $elements, $erroneousField)

Set and validate field values.

array
getActiveFieldParams()

Format the field values for input to the api.

array
getSelectValues()

No description

array
getSelectTypes()

No description

array
getHeaderPatterns()

No description

array
getDataPatterns()

No description

static void
encloseScrub(array $values, string $enclosure = "'")

Remove single-quote enclosures from a value array (row).

void
setMaxLinesToProcess(int $max)

Setter function.

static string
errorFileName($type)

Determines the file extension based on error code.

static string
saveFileName($type)

Determines the file name based on error code.

mixed
run(string $tableName, array $mapper, int $mode = self::MODE_PREVIEW, int $contactType = self::CONTACT_INDIVIDUAL, string $primaryKeyName = '_id', string $statusFieldName = '_status', int $onDuplicate = self::DUPLICATE_SKIP, int $statusID = NULL, int $totalRowCount = NULL, bool $doGeocodeAddress = FALSE, int $timeout = CRM_Contact_Import_Parser::DEFAULT_TIMEOUT, string $contactSubType = NULL, int $dedupeRuleGroupID = NULL)

Run import.

setActiveFields(array $fieldKeys)

Given a list of the importable field keys that the user has selected.

setActiveFieldLocationTypes($elements)

No description

setActiveFieldPhoneTypes($elements)

No description

setActiveFieldWebsiteTypes($elements)

No description

setActiveFieldImProviders(array $elements)

Set IM Service Provider type fields.

setActiveFieldRelated($elements)

No description

setActiveFieldRelatedContactPhoneType(array $elements)

Set active field for related contact's phone type.

setActiveFieldRelatedContactImProvider(array $elements)

Set IM Service Provider type fields for related contacts.

array
getColumnPatterns()

No description

addField(string $name, $title, int $type = CRM_Utils_Type::T_INT, string $headerPattern = '//', string $dataPattern = '//', bool $hasLocationType = FALSE)

No description

set(CRM_Core_Session $store, int $mode = self::MODE_SUMMARY)

Store parser values.

static 
exportCSV(string $fileName, array $header, array $data)

Export data to a CSV file.

updateImportRecord(int $id, array $params)

Update the record with PK $id in the import database table.

array
getImportedContacts()

Get the array of successfully imported contact id's

array
getRelatedImportedContacts()

Get the array of successfully imported related contact id's

static 
isErrorInCustomData(array $params, string $errorMessage, null $csType = NULL, null $relationships = NULL)

Check if an error in custom data.

bool
checkGender(string $gender)

Check if value present in all genders or.

isErrorInCoreData(array $params, string $errorMessage)

Check if an error in Core( non-custom fields ) field

static bool
in_value($value, $valueArray)

Ckeck a value present or not in a array.

static 
addToErrorMsg(string $errorName, string $errorMessage)

Build error-message containing error-fields

createContact(array $formatted, array $contactFields, int $onDuplicate, int $contactId = NULL, bool $requiredCheck = TRUE, int $dedupeRuleGroupID = NULL)

Method for creating contact.

formatParams(array $params, int $onDuplicate, int $cid)

Format params for update and fill mode.

static 
formatCustomDate(array $params, array $formatted, int $dateType, string $dateParam)

Convert any given date string to default date array.

formatCommonData(array $params, array $formatted, array $contactFields)

Format common params data to proper format to store.

int
processMessage(array $values, array $statusFieldName, $returnCode)

Generate status and error message for unparsed street address records.

bool
checkRelatedContactFields($relKey, array $params)

No description

static array
getSubtypes(string $contactType)

get subtypes given the contact type

array
getPossibleContactMatches(array $params)

Get the possible contact matches.

Details

at line 122
__construct(array $mapperKeys, int $mapperLocType = NULL, int $mapperPhoneType = NULL, int $mapperImProvider = NULL, int $mapperRelated = NULL, int $mapperRelatedContactType = NULL, array $mapperRelatedContactDetails = NULL, int $mapperRelatedContactLocType = NULL, int $mapperRelatedContactPhoneType = NULL, int $mapperRelatedContactImProvider = NULL, int $mapperWebsiteType = NULL, int $mapperRelatedContactWebsiteType = NULL)

Class constructor.

Parameters

array $mapperKeys
int $mapperLocType
int $mapperPhoneType
int $mapperImProvider
int $mapperRelated
int $mapperRelatedContactType
array $mapperRelatedContactDetails
int $mapperRelatedContactLocType
int $mapperRelatedContactPhoneType
int $mapperRelatedContactImProvider
int $mapperWebsiteType
int $mapperRelatedContactWebsiteType

at line 146
init()

The initializer code, called before processing.

at line 1108
mixed fini()

The initializer code, called before the processing.

Return Value

mixed

at line 270
mixed mapField(array $values)

Handle the values in mapField mode.

Parameters

array $values

Return Value

mixed

at line 283
mixed preview(array $values)

Handle the values in preview mode.

Parameters

array $values

Return Value

mixed

at line 296
mixed summary($values)

Handle the values in summary mode.

Parameters

$values

Return Value

mixed

at line 470
mixed import($onDuplicate, $values, bool $doGeocodeAddress = FALSE)

Handle the values in import mode.

Parameters

$onDuplicate
$values
bool $doGeocodeAddress

Return Value

mixed

in CRM_Import_Parser at line 251
int setActiveFieldValues(array $elements, $erroneousField)

Set and validate field values.

Parameters

array $elements array.
$erroneousField reference.

Return Value

int

array getActiveFieldParams()

Format the field values for input to the api.

Return Value

array (reference) associative array of name/value pairs

in CRM_Import_Parser at line 298
array getSelectValues()

Return Value

array

in CRM_Import_Parser at line 309
array getSelectTypes()

Return Value

array

in CRM_Import_Parser at line 322
array getHeaderPatterns()

Return Value

array

in CRM_Import_Parser at line 335
array getDataPatterns()

Return Value

array

in CRM_Import_Parser at line 351
static void encloseScrub(array $values, string $enclosure = "'")

Remove single-quote enclosures from a value array (row).

Parameters

array $values
string $enclosure

Return Value

void

in CRM_Import_Parser at line 368
void setMaxLinesToProcess(int $max)

Setter function.

Parameters

int $max

Return Value

void

in CRM_Import_Parser at line 378
static string errorFileName($type)

Determines the file extension based on error code.

Parameters

$type

Return Value

string

in CRM_Import_Parser at line 417
static string saveFileName($type)

Determines the file name based on error code.

Parameters

$type

Return Value

string

mixed run(string $tableName, array $mapper, int $mode = self::MODE_PREVIEW, int $contactType = self::CONTACT_INDIVIDUAL, string $primaryKeyName = '_id', string $statusFieldName = '_status', int $onDuplicate = self::DUPLICATE_SKIP, int $statusID = NULL, int $totalRowCount = NULL, bool $doGeocodeAddress = FALSE, int $timeout = CRM_Contact_Import_Parser::DEFAULT_TIMEOUT, string $contactSubType = NULL, int $dedupeRuleGroupID = NULL)

Run import.

Parameters

string $tableName
array $mapper
int $mode
int $contactType
string $primaryKeyName
string $statusFieldName
int $onDuplicate
int $statusID
int $totalRowCount
bool $doGeocodeAddress
int $timeout
string $contactSubType
int $dedupeRuleGroupID

Return Value

mixed

setActiveFields(array $fieldKeys)

Given a list of the importable field keys that the user has selected.

set the active fields array to this list

Parameters

array $fieldKeys Mapped array of values.

setActiveFieldLocationTypes($elements)

Parameters

$elements

setActiveFieldPhoneTypes($elements)

Parameters

$elements

setActiveFieldWebsiteTypes($elements)

Parameters

$elements

setActiveFieldImProviders(array $elements)

Set IM Service Provider type fields.

Parameters

array $elements IM service provider type ids.

setActiveFieldRelated($elements)

Parameters

$elements

setActiveFieldRelatedContactType($elements)

Parameters

$elements

setActiveFieldRelatedContactDetails($elements)

Parameters

$elements

setActiveFieldRelatedContactLocType($elements)

Parameters

$elements

setActiveFieldRelatedContactPhoneType(array $elements)

Set active field for related contact's phone type.

Parameters

array $elements

setActiveFieldRelatedContactWebsiteType($elements)

Parameters

$elements

setActiveFieldRelatedContactImProvider(array $elements)

Set IM Service Provider type fields for related contacts.

Parameters

array $elements IM service provider type ids of related contact.

array getColumnPatterns()

Return Value

array

addField(string $name, $title, int $type = CRM_Utils_Type::T_INT, string $headerPattern = '//', string $dataPattern = '//', bool $hasLocationType = FALSE)

Parameters

string $name
$title
int $type
string $headerPattern
string $dataPattern
bool $hasLocationType

set(CRM_Core_Session $store, int $mode = self::MODE_SUMMARY)

Store parser values.

Parameters

CRM_Core_Session $store
int $mode

static exportCSV(string $fileName, array $header, array $data)

Export data to a CSV file.

Parameters

string $fileName
array $header
array $data

updateImportRecord(int $id, array $params)

Update the record with PK $id in the import database table.

Parameters

int $id
array $params

at line 1092
array getImportedContacts()

Get the array of successfully imported contact id's

Return Value

array

at line 1101
array getRelatedImportedContacts()

Get the array of successfully imported related contact id's

Return Value

array

at line 1121
static isErrorInCustomData(array $params, string $errorMessage, null $csType = NULL, null $relationships = NULL)

Check if an error in custom data.

Parameters

array $params
string $errorMessage A string containing all the error-fields.
null $csType
null $relationships

at line 1324
bool checkGender(string $gender)

Check if value present in all genders or.

as a substring of any gender value, if yes than return corresponding gender. eg value might be m/M, ma/MA, mal/MAL, male return 'Male' but if value is 'maleabc' than return false

Parameters

string $gender Check this value across gender values.

retunr gender value / false

Return Value

bool

at line 1353
isErrorInCoreData(array $params, string $errorMessage)

Check if an error in Core( non-custom fields ) field

Parameters

array $params
string $errorMessage A string containing all the error-fields.

at line 1625
static bool in_value($value, $valueArray)

Ckeck a value present or not in a array.

Parameters

$value
$valueArray

Return Value

bool

at line 1644
static addToErrorMsg(string $errorName, string $errorMessage)

Build error-message containing error-fields

Parameters

string $errorName A string containing error-field name.
string $errorMessage A string containing all the error-fields, where the new errorName is concatenated.

at line 1665
array|bool|CRM_Contact_BAO_Contact|CRM_Core_Error|null createContact(array $formatted, array $contactFields, int $onDuplicate, int $contactId = NULL, bool $requiredCheck = TRUE, int $dedupeRuleGroupID = NULL)

Method for creating contact.

Parameters

array $formatted
array $contactFields
int $onDuplicate
int $contactId
bool $requiredCheck
int $dedupeRuleGroupID

Return Value

array|bool|CRM_Contact_BAO_Contact|CRM_Core_Error|null

at line 1731
formatParams(array $params, int $onDuplicate, int $cid)

Format params for update and fill mode.

Parameters

array $params reference to an array containing all the. values for import
int $onDuplicate
int $cid contact id.

at line 1843
static formatCustomDate(array $params, array $formatted, int $dateType, string $dateParam)

Convert any given date string to default date array.

Parameters

array $params Has given date-format.
array $formatted Store formatted date in this array.
int $dateType Type of date.
string $dateParam Index of params.

at line 1859
formatCommonData(array $params, array $formatted, array $contactFields)

Format common params data to proper format to store.

Parameters

array $params Contain record values.
array $formatted Array of formatted data.
array $contactFields Contact DAO fields.

at line 2091
int processMessage(array $values, array $statusFieldName, $returnCode)

Generate status and error message for unparsed street address records.

Parameters

array $values The array of values belonging to each row.
array $statusFieldName Store formatted date in this array.
$returnCode

Return Value

int

at line 2120
bool checkRelatedContactFields($relKey, array $params)

Parameters

$relKey
array $params

Return Value

bool

at line 2164
static array getSubtypes(string $contactType)

get subtypes given the contact type

Parameters

string $contactType

Return Value

array $subTypes

at line 2192
protected array getPossibleContactMatches(array $params)

Get the possible contact matches.

1) the chosen dedupe rule falling back to 2) a check for the external ID.

CRM-17275

Parameters

array $params

Return Value

array IDs of possible matches.

Exceptions

CRM_Core_Exception
CiviCRM_API3_Exception