CRM_Export_BAO_ExportProcessor
class CRM_Export_BAO_ExportProcessor
Class CRM_Export_BAO_ExportProcessor
Class to handle logic of export.
Properties
protected int | $queryMode | ||
protected int | $exportMode | ||
protected array | $queryFields | Array of fields in the main query. | |
protected string | $queryOperator | Either AND or OR. | |
protected array|null | $requestedFields | Requested output fields. | |
protected bool | $isMergeSameHousehold | Is the contact being merged into a single household. | |
protected bool | $isMergeSameAddress | Should contacts with the same address be merged. | |
protected array | $additionalFieldsForSameAddressMerge | Fields that need to be retrieved for address merge purposes but should not be in output. | |
protected array | $contactGreetingFields | Fields used for merging same contacts. | |
protected array | $ids | An array of primary IDs of the entity being exported. | |
protected array | $additionalFieldsForPostalExport | Additional fields required to export postal fields. | |
protected bool | $isPostalableOnly | Only export contacts that can receive postal mail. | |
protected array | $relationshipTypes | Key representing the head of household in the relationship array. | |
protected array | $relationshipReturnProperties | Array of properties to retrieve for relationships. | |
protected array | $exportedHouseholds | IDs of households that have already been exported. | |
protected array | $householdsToSkip | Households to skip during export as they will be exported via their relationships anyway. | |
protected array | $additionalRequestedReturnProperties | Additional fields to return. | |
protected array | $relatedContactValues | Export values for related contacts. | |
protected array | $returnProperties | ||
protected array | $outputSpecification | ||
protected string | $componentTable | ||
protected string | $componentClause | Clause from component search. | |
protected string | $temporaryTable | Name of a temporary table created to hold the results. | |
protected | $postalGreetingTemplate | ||
protected | $addresseeGreetingTemplate |
Methods
Get additional non-visible fields for address merge purposes.
Set additional non-visible fields for address merge purposes.
Should contacts with the same address be merged.
Set same address is to be merged.
Get additional fields required to do a postal export.
Set additional fields required for a postal export.
Get additional return properties.
Set additional return properties.
Get return properties by relationship.
No description
Set the component table (if any).
No description
No description
No description
No description
No description
No description
No description
No description
CRM_Export_BAO_ExportProcessor constructor.
No description
No description
No description
No description
No description
No description
No description
No description
Set the value for a relationship type field.
Get the value for a relationship type field.
Get the id of the related household.
Has the household already been exported.
No description
No description
Return relationship types for household merge.
No description
No description
No description
No description
No description
No description
No description
No description
No description
Set the query mode based on the export mode.
No description
No description
Get the name for the export file.
Get the label for the header row based on the field to output.
No description
Add a row to the specification for how to output data.
Get the metadata for the given field.
No description
Mark a column as only required for calculations.
No description
No description
No description
Build the row for output.
If this row has a household whose details we should use get the relationship type key.
Mark the given household as already exported.
No description
Get array of fields to return, over & above those defined in the main contact exportable fields.
Should payment fields be appended to the export.
Has specific payment fields been requested (as opposed to via all fields).
Get the name of the id field in the table that connects contributions to the export entity.
Have component payment fields been requested.
Get fields that indicate payment fields have been requested for a component.
Get headers for payment fields.
Get the default properties when not specified.
Add the field to relationship return properties & return it.
Add the main return properties to the household merge properties if needed for merging.
Get the default location fields to request.
Get the sql column definition for the given field.
Get the munged field name.
In order to respect the history of this class we need to index kinda illogically.
Get the compiled label for the column.
Get the mysql field name key.
Get params for the where criteria.
No description
Is this contact a household that is already set to be exported by virtue of it's household members.
Get the various arrays that we use to structure our output.
Get default return property for export based on mode
Determine the required return properties from the input parameters.
No description
No description
Build array for merging same addresses.
Merge contacts with the same address.
The function unsets static part of the string, if token is the dynamic part.
Preview export output.
Set the template strings to be used when merging two contacts with the same address.
Create the temporary table for output.
Get the values of linked household contact.
Write to the csv from the temp table.
Set up the temp table.
No description
Details
at line 115
array
getAdditionalFieldsForSameAddressMerge()
Get additional non-visible fields for address merge purposes.
at line 122
setAdditionalFieldsForSameAddressMerge()
Set additional non-visible fields for address merge purposes.
at line 139
bool
isMergeSameAddress()
Should contacts with the same address be merged.
at line 148
setIsMergeSameAddress(bool $isMergeSameAddress)
Set same address is to be merged.
at line 164
array
getAdditionalFieldsForPostalExport()
Get additional fields required to do a postal export.
at line 171
setAdditionalFieldsForPostalExport()
Set additional fields required for a postal export.
at line 237
array
getAdditionalRequestedReturnProperties()
Get additional return properties.
at line 246
setAdditionalRequestedReturnProperties(array $value)
Set additional return properties.
at line 259
array
getRelationshipReturnProperties()
Get return properties by relationship.
at line 288
string
getComponentTable()
at line 297
setComponentTable(string $componentTable)
Set the component table (if any).
at line 311
string
getComponentClause()
at line 318
setComponentClause(string $componentClause)
at line 336
string
getTemporaryTable()
at line 343
setTemporaryTable(string $temporaryTable)
at line 352
mixed
getPostalGreetingTemplate()
at line 359
setPostalGreetingTemplate(mixed $postalGreetingTemplate)
at line 366
mixed
getAddresseeGreetingTemplate()
at line 373
setAddresseeGreetingTemplate(mixed $addresseeGreetingTemplate)
at line 395
__construct(int $exportMode, array|null $requestedFields, string $queryOperator, bool $isMergeSameHousehold = FALSE, bool $isPostalableOnly = FALSE, bool $isMergeSameAddress = FALSE, array $formValues = [])
CRM_Export_BAO_ExportProcessor constructor.
at line 414
bool
isPostalableOnly()
at line 421
setIsPostalableOnly(bool $isPostalableOnly)
at line 428
array|null
getRequestedFields()
at line 435
setRequestedFields(array|null $requestedFields)
at line 442
array
getReturnProperties()
at line 449
setReturnProperties(array $returnProperties)
at line 456
array
getRelationshipTypes()
at line 462
setRelationshipTypes()
at line 487
setRelationshipValue(string $relationshipType, int $contactID, string $field, string $value)
Set the value for a relationship type field.
In this case we are building up an array of properties for a related contact.
These may be used for direct exporting or for merge to household depending on the options selected.
at line 508
string
getRelationshipValue(string $relationshipType, int $contactID, string $field)
Get the value for a relationship type field.
In this case we are building up an array of properties for a related contact.
These may be used for direct exporting or for merge to household depending on the options selected.
at line 520
int
getRelatedHouseholdID(int $contactID, string $relationshipType)
Get the id of the related household.
at line 531
bool
isHouseholdExported(int $housholdContactID)
Has the household already been exported.
at line 539
bool
isMergeSameHousehold()
at line 546
setIsMergeSameHousehold(bool $isMergeSameHousehold)
at line 555
mixed
getHouseholdRelationshipTypes()
Return relationship types for household merge.
at line 569
bool
isRelationshipTypeKey($fieldName)
at line 577
bool
isHouseholdMergeRelationshipTypeKey($fieldName)
at line 584
string
getQueryOperator()
at line 591
setQueryOperator(string $queryOperator)
at line 598
array
getIds()
at line 605
setIds(array $ids)
at line 612
array
getQueryFields()
at line 622
setQueryFields(array $queryFields)
at line 636
int
getQueryMode()
at line 643
setQueryMode()
Set the query mode based on the export mode.
at line 682
int
getExportMode()
at line 689
setExportMode(int $exportMode)
at line 698
string
getExportFileName()
Get the name for the export file.
at line 739
string
getHeaderForRow(string $field)
Get the label for the header row based on the field to output.
at line 765
array
runQuery($params, $order)
at line 845
addOutputSpecification(string $key, string $relationshipType = NULL, string $locationType = NULL, int $entityTypeID = NULL)
Add a row to the specification for how to output data.
at line 878
array
getMetaDataForField($key)
Get the metadata for the given field.
at line 892
setSqlColumnDefn($key)
at line 903
setColumnAsCalculationOnly(string $column)
Mark a column as only required for calculations.
Do not include the row with headers.
at line 910
array
getHeaderRows()
at line 923
array
getSQLColumns()
at line 936
array
getMetadata()
at line 956
array|bool
buildRow(CRM_Contact_BAO_Query $query, CRM_Core_DAO $iterationDAO, array $outputColumns, $metadata, $paymentDetails, $addPaymentHeader)
Build the row for output.
at line 1048
bool
getHouseholdMergeTypeForRow($contactID)
If this row has a household whose details we should use get the relationship type key.
at line 1064
markHouseholdExported($householdID)
Mark the given household as already exported.
at line 1077
string
getTransformedFieldValue($field, $iterationDAO, $fieldValue, $metadata, $paymentDetails)
at line 1185
array
getAdditionalReturnProperties()
Get array of fields to return, over & above those defined in the main contact exportable fields.
These include export mode specific fields & some fields apparently required as 'exportableFields' but not returned by the function of the same name.
at line 1214
isExportPaymentFields()
Should payment fields be appended to the export.
(This is pretty hacky so hopefully this function won't last long - notice how obviously it should be part of the above function!).
at line 1236
bool
isExportSpecifiedPaymentFields()
Has specific payment fields been requested (as opposed to via all fields).
If specific fields have been requested then they get added at various points.
at line 1245
getPaymentTableID()
Get the name of the id field in the table that connects contributions to the export entity.
at line 1265
protected bool
hasRequestedComponentPaymentFields()
Have component payment fields been requested.
at line 1282
array
getComponentPaymentFields()
Get fields that indicate payment fields have been requested for a component.
Ideally this should be protected but making it temporarily public helps refactoring..
at line 1298
getPaymentHeaders()
Get headers for payment fields.
Returns an array of contribution fields when the entity supports payment fields and specific fields are not specified. This is a transitional function for refactoring legacy code.
at line 1315
array
getDefaultReturnProperties()
Get the default properties when not specified.
In the UI this appears as 'Primary fields only' but in practice it's most of the kitchen sink and the hallway closet thrown in.
Since CRM-952 custom fields are excluded, but no other form of mercy is shown.
at line 1344
array
setRelationshipReturnProperties(array $value, string $relationshipKey)
Add the field to relationship return properties & return it.
This function is doing both setting & getting which is yuck but it is an interim refactor.
at line 1374
setHouseholdMergeReturnProperties()
Add the main return properties to the household merge properties if needed for merging.
If we are using household merge we need to add these to the relationship properties to be retrieved.
at line 1389
array
getValidLocationFields()
Get the default location fields to request.
at line 1416
mixed
getSqlColumnDefinition(string $fieldName, string $columnName)
Get the sql column definition for the given field.
at line 1519
string
getMungedFieldName(string $field)
Get the munged field name.
at line 1541
protected string
getOutputSpecificationIndex(string $key, string $relationshipType, string $locationType, $entityLabel)
In order to respect the history of this class we need to index kinda illogically.
On the bright side - this stuff is tested within a nano-byte of it's life.
e.g '2-a-b_Home-City'
at line 1571
protected string
getOutputSpecificationLabel(string $key, string $relationshipType, string $locationType, string $entityLabel)
Get the compiled label for the column.
e.g 'Gender', 'Employee Of-Home-city'
at line 1594
protected string
getOutputSpecificationFieldKey(string $key, $relationshipType, $locationType, $entityLabel)
Get the mysql field name key.
This key is locked in by tests but the reasons for the specific conventions - ie. headings are used for keying fields in some cases, are likely accidental rather than deliberate.
This key is used for the output sql array.
at line 1618
mixed
getWhereParams()
Get params for the where criteria.
at line 1633
protected
buildRelationshipFieldsForRow($row, $contactID, $value, $field)
at line 1657
protected bool
isHouseholdToSkip(int $contactID)
Is this contact a household that is already set to be exported by virtue of it's household members.
at line 1686
array
getExportStructureArrays()
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.
at line 1739
string
defaultReturnProperty()
Get default return property for export based on mode
at line 1772
array
determineReturnProperties()
Determine the required return properties from the input parameters.
at line 1840
string
getGroupBy(object $query)
at line 1883
array
replaceMergeTokens(int $contactId)
at line 1922
array
buildMasterCopyArray($sql, bool $sharedAddress = FALSE)
Build array for merging same addresses.
at line 2008
mergeSameAddress()
Merge contacts with the same address.
at line 2115
mixed
trimNonTokensFromAddressString(string $parsedString, string $defaultGreeting, string $greetingLabel)
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'
at line 2138
array
getPreview(int $limit)
Preview export output.
at line 2163
protected mixed
setGreetingStringsForSameAddressMerge(array $formValues)
Set the template strings to be used when merging two contacts with the same address.
at line 2194
createTempTable()
Create the temporary table for output.
at line 2237
fetchRelationshipDetails(CRM_Core_DAO $relDAO, array $value, string $field, array $row)
Get the values of linked household contact.
at line 2350
writeCSVFromTable()
Write to the csv from the temp table.
at line 2410
protected
instantiateTempTable(array $headerRows)
Set up the temp table.