class CRM_Export_BAO_Export

This class contains the functions for Component export

Constants

EXPORT_ROW_COUNT

Methods

static string
getQueryMode(int $exportMode)

Get Querymode based on ExportMode

static string
defaultReturnProperty(int $exportMode)

Get default return property for export based on mode

static string
exportComponent(int $exportMode)

Get Export component

static string
getGroupBy(int $exportMode, string $queryMode, array $returnProperties, object $query)

Get Query Group By Clause

static array
defineExtraProperties(string $queryMode)

Define extra properties for the export based on query mode

static 
exportComponents(int $selectAll, array $ids, array $params, string $order = NULL, array $fields = NULL, array $moreReturnProperties = NULL, int $exportMode = CRM_Export_Form_Select::CONTACT_EXPORT, string $componentClause = NULL, string $componentTable = NULL, bool $mergeSameAddress = FALSE, bool $mergeSameHousehold = FALSE, array $exportParams = array(), string $queryOperator = 'AND')

Get the list the export fields.

static string
getExportFileName(string $output = 'csv', int $mode = CRM_Export_Form_Select::CONTACT_EXPORT)

Name of the export file based on mode.

static 
invoke()

Handle import error file creation.

static 
exportCustom($customSearchClass, $formValues, $order)

No description

static 
sqlColumnDefn($query, $sqlColumns, $field)

No description

static 
writeDetailsToTable(string $tableName, $details, $sqlColumns)

No description

static string
createTempTable($sqlColumns)

No description

static 
mergeSameAddress(string $tableName, $headerRows, $sqlColumns, array $exportParams)

No description

static array
_replaceMergeTokens(int $contactId, array $exportParams)

No description

static mixed
_trimNonTokens(string $parsedString, string $defaultGreeting, bool $addressMergeGreetings, string $greetingType = 'postal_greeting')

The function unsets static part of the string, if token is the dynamic part.

static array
_buildMasterCopyArray($sql, array $exportParams, bool $sharedAddress = FALSE)

No description

static 
mergeSameHousehold(string $exportTempTable, array $headerRows, array $sqlColumns, string $prefix)

Merge household record into the individual record if exists

static 
writeCSVFromTable($exportTempTable, $headerRows, $sqlColumns, $exportMode, null $saveFile = NULL, string $batchItems = '')

No description

static 
manipulateHeaderRows($headerRows, $contactRelationshipTypes)

Manipulate header rows for relationship fields.

static 
postalMailingFormat($exportTempTable, $headerRows, $sqlColumns, $exportParams)

Exclude contacts who are deceased, have "Do not mail" privacy setting, or have no street address

static 
componentPaymentFields()

Build componentPayment fields.

static array
setHeaderRows(string $field, array $headerRows, array $sqlColumns, CRM_Contact_BAO_Query $query, array|string $value, array $phoneTypes, array $imProviders, array $contactRelationshipTypes, string $relationQuery, array $selectedPaymentFields)

Set the definition for the header rows and sql columns based on the field to output.

static array
getExportStructureArrays(array $returnProperties, CRM_Contact_BAO_Contact $query, array $phoneTypes, array $imProviders, array $contactRelationshipTypes, string $relationQuery, array $selectedPaymentFields)

Get the various arrays that we use to structure our output.

Details

at line 55
static string getQueryMode(int $exportMode)

Get Querymode based on ExportMode

Parameters

int $exportMode Export mode.

Return Value

string $Querymode Query Mode

at line 99
static string defaultReturnProperty(int $exportMode)

Get default return property for export based on mode

Parameters

int $exportMode Export mode.

Return Value

string $property Default Return property

at line 135
static string exportComponent(int $exportMode)

Get Export component

Parameters

int $exportMode Export mode.

Return Value

string $component CiviCRM Export Component

at line 174
static string getGroupBy(int $exportMode, string $queryMode, array $returnProperties, object $query)

Get Query Group By Clause

Parameters

int $exportMode Export Mode
string $queryMode Query Mode
array $returnProperties Return Properties
object $query CRM_Contact_BAO_Query

Return Value

string $groupBy Group By Clause

at line 221
static array defineExtraProperties(string $queryMode)

Define extra properties for the export based on query mode

Parameters

string $queryMode Query Mode

Return Value

array $extraProperties Extra Properties

at line 290
static exportComponents(int $selectAll, array $ids, array $params, string $order = NULL, array $fields = NULL, array $moreReturnProperties = NULL, int $exportMode = CRM_Export_Form_Select::CONTACT_EXPORT, string $componentClause = NULL, string $componentTable = NULL, bool $mergeSameAddress = FALSE, bool $mergeSameHousehold = FALSE, array $exportParams = array(), string $queryOperator = 'AND')

Get the list the export fields.

Parameters

int $selectAll User preference while export.
array $ids Contact ids.
array $params Associated array of fields.
string $order Order by clause.
array $fields Associated array of fields.
array $moreReturnProperties Additional return fields.
int $exportMode Export mode.
string $componentClause Component clause.
string $componentTable Component table.
bool $mergeSameAddress Merge records if they have same address.
bool $mergeSameHousehold Merge records if they belong to the same household.
array $exportParams
string $queryOperator

at line 1132
static string getExportFileName(string $output = 'csv', int $mode = CRM_Export_Form_Select::CONTACT_EXPORT)

Name of the export file based on mode.

Parameters

string $output Type of output.
int $mode Export mode.

Return Value

string name of the file

at line 1163
static invoke()

Handle import error file creation.

at line 1205
static exportCustom($customSearchClass, $formValues, $order)

Parameters

$customSearchClass
$formValues
$order

at line 1255
static sqlColumnDefn($query, $sqlColumns, $field)

Parameters

$query
$sqlColumns
$field

at line 1391
static writeDetailsToTable(string $tableName, $details, $sqlColumns)

Parameters

string $tableName
$details
$sqlColumns

at line 1439
static string createTempTable($sqlColumns)

Parameters

$sqlColumns

Return Value

string

at line 1485
static mergeSameAddress(string $tableName, $headerRows, $sqlColumns, array $exportParams)

Parameters

string $tableName
$headerRows
$sqlColumns
array $exportParams

at line 1594
static array _replaceMergeTokens(int $contactId, array $exportParams)

Parameters

int $contactId
array $exportParams

Return Value

array

at line 1638
static mixed _trimNonTokens(string $parsedString, string $defaultGreeting, bool $addressMergeGreetings, string $greetingType = 'postal_greeting')

The function unsets static part of the string, if token is the dynamic part.

Example: 'Hello {contact.first_name}' => converted to => '{contact.first_name}' i.e 'Hello Alan' => converted to => 'Alan'

Parameters

string $parsedString
string $defaultGreeting
bool $addressMergeGreetings
string $greetingType

Return Value

mixed

at line 1665
static array _buildMasterCopyArray($sql, array $exportParams, bool $sharedAddress = FALSE)

Parameters

$sql
array $exportParams
bool $sharedAddress

Return Value

array

at line 1774
static mergeSameHousehold(string $exportTempTable, array $headerRows, array $sqlColumns, string $prefix)

Merge household record into the individual record if exists

Parameters

string $exportTempTable Temporary temp table that stores the records.
array $headerRows Array of headers for the export file.
array $sqlColumns Array of names of the table columns of the temp table.
string $prefix Name of the relationship type that is prefixed to the table columns.

at line 1855
static writeCSVFromTable($exportTempTable, $headerRows, $sqlColumns, $exportMode, null $saveFile = NULL, string $batchItems = '')

Parameters

$exportTempTable
$headerRows
$sqlColumns
$exportMode
null $saveFile
string $batchItems

at line 1909
static manipulateHeaderRows($headerRows, $contactRelationshipTypes)

Manipulate header rows for relationship fields.

Parameters

$headerRows
$contactRelationshipTypes

at line 1927
static postalMailingFormat($exportTempTable, $headerRows, $sqlColumns, $exportParams)

Exclude contacts who are deceased, have "Do not mail" privacy setting, or have no street address

Parameters

$exportTempTable
$headerRows
$sqlColumns
$exportParams

at line 1979
static componentPaymentFields()

Build componentPayment fields.

at line 2009
static array setHeaderRows(string $field, array $headerRows, array $sqlColumns, CRM_Contact_BAO_Query $query, array|string $value, array $phoneTypes, array $imProviders, array $contactRelationshipTypes, string $relationQuery, array $selectedPaymentFields)

Set the definition for the header rows and sql columns based on the field to output.

Parameters

string $field
array $headerRows
array $sqlColumns Columns to go in the temp table.
CRM_Contact_BAO_Query $query
array|string $value
array $phoneTypes
array $imProviders
array $contactRelationshipTypes
string $relationQuery
array $selectedPaymentFields

Return Value

array

at line 2139
static array getExportStructureArrays(array $returnProperties, CRM_Contact_BAO_Contact $query, array $phoneTypes, array $imProviders, array $contactRelationshipTypes, string $relationQuery, array $selectedPaymentFields)

Get the various arrays that we use to structure our output.

The extraction of these has been moved to a separate function for clarity and so that tests can be added - in particular on the $outputHeaders array.

However it still feels a bit like something that I'm too polite to write down and this should be seen as a step on the refactoring path rather than how it should be.

Parameters

array $returnProperties
CRM_Contact_BAO_Contact $query
array $phoneTypes
array $imProviders
array $contactRelationshipTypes
string $relationQuery
array $selectedPaymentFields

Return Value

array
  • outputColumns Array of columns to be exported. The values don't matter but the key must match the alias for the field generated by BAO_Query object.
    • headerRows Array of the column header strings to put in the csv header - non-associative.
    • sqlColumns Array of column names for the temp table. Not too sure why outputColumns can't be used here.
    • metadata Array of fields with specific parameters to pass to the translate function or another hacky nasty solution I'm too embarassed to discuss here. The keys need
    • to match the outputColumns keys (yes, the fact we ignore the output columns values & then pass another array with values we could use does suggest further refactors. However, you future improver, do remember that every check you do in the main DAO loop is done once per row & that coule be 100,000 times.) Finally a pop quiz: We need the translate context because we use a function other than ts() - is this because
    • a) the function used is more efficient or
    • b) this code is old & outdated. Submit your answers to circular bin or better yet find a way to comment them for posterity.