class CRM_Custom_Import_Parser_Api extends CRM_Custom_Import_Parser

Class CRM_Custom_Import_Parser_Api

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 $_fields
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 $_fileName from CRM_Custom_Import_Parser
protected $_fileSize Imported file size from CRM_Custom_Import_Parser
protected $_separator Separator being used from CRM_Custom_Import_Parser
protected $_lineCount Total number of lines in file from CRM_Custom_Import_Parser
protected boolean $_haveColumnHeader Whether the file has a column header or not from CRM_Custom_Import_Parser
protected $_entity
protected $_requiredFields
protected $_dateFields
protected $_multipleCustomData
protected array $_params Params for the current entity being prepared for the api.

Methods

__construct(array $mapperKeys, null $mapperLocType = NULL, null $mapperPhoneType = NULL)

Class constructor.

init()

The initializer code, called before the 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)

No description

mixed
import($onDuplicate, $values)

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 $fileName, string $separator = ',', array $mapper, bool $skipColumnHeader = FALSE, int $mode = self::MODE_PREVIEW, int $contactType = self::CONTACT_INDIVIDUAL, int $onDuplicate = self::DUPLICATE_SKIP)

No description

setActiveFields(array $fieldKeys)

Given a list of the importable field keys that the user has selected set the active fields array to this list

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.

setFields()

No description

formatDateParams()

Format Date params.

setEntity(string $entity)

Set import entity.

array
getGroupFieldsForImport(int $id)

Return the field ids and names (with groups) for import purpose.

Details

at line 27
__construct(array $mapperKeys, null $mapperLocType = NULL, null $mapperPhoneType = NULL)

Class constructor.

Parameters

array $mapperKeys
null $mapperLocType
null $mapperPhoneType

at line 47
init()

The initializer code, called before the processing

at line 227
mixed fini()

The initializer code, called before the processing

Return Value

mixed

at line 69
mixed mapField(array $values)

Handle the values in mapField mode.

Parameters

array $values

Return Value

mixed

at line 82
mixed preview(array $values)

Handle the values in preview mode.

Parameters

array $values

Return Value

mixed

at line 96
mixed summary($values)

Parameters

$values

Return Value

mixed

See also

CRM_Custom_Import_Parser_BaseClass::summary()

at line 147
mixed import($onDuplicate, $values)

Handle the values in import mode.

Parameters

$onDuplicate
$values

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 $fileName, string $separator = ',', array $mapper, bool $skipColumnHeader = FALSE, int $mode = self::MODE_PREVIEW, int $contactType = self::CONTACT_INDIVIDUAL, int $onDuplicate = self::DUPLICATE_SKIP)

Parameters

string $fileName
string $separator
array $mapper
bool $skipColumnHeader
int $mode
int $contactType
int $onDuplicate

Return Value

mixed

Exceptions

Exception

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 32
setFields()

at line 202
formatDateParams()

Format Date params.

Although the api will accept any strtotime valid string CiviCRM accepts at least one date format not supported by strtotime so we should run this through a conversion

at line 217
setEntity(string $entity)

Set import entity.

Parameters

string $entity

at line 239
array getGroupFieldsForImport(int $id)

Return the field ids and names (with groups) for import purpose.

Parameters

int $id Custom group ID.

Return Value

array