*/
public function getTrackingFields(): array {
return [
- 'related_contact_created' => 'INT COMMENT "Number of related contacts created"',
- 'related_contact_matched' => 'INT COMMENT "Number of related contacts found (& potentially updated)"',
+ 'related_contact_created' => [
+ 'name' => 'related_contact_created',
+ 'operation' => 'SUM',
+ 'type' => 'INT',
+ 'description' => ts('Number of related contacts created'),
+ ],
+ 'related_contact_matched' => [
+ 'name' => 'related_contact_matched',
+ 'operation' => 'SUM',
+ 'type' => 'INT',
+ 'description' => ts('Number of related contacts found (and potentially updated)'),
+ ],
];
}
*/
private $selectFields;
+ /**
+ * Fields to select as aggregates.
+ *
+ * @var array
+ */
+ private $aggregateFields;
+
/**
* The name of the import table.
*
return $this;
}
+ /**
+ * @param array $fields
+ *
+ * @return CRM_Import_DataSource
+ */
+ public function setAggregateFields(array $fields): CRM_Import_DataSource {
+ $this->aggregateFields = $fields;
+ return $this;
+ }
+
+ /**
+ * @return array|null
+ */
+ public function getAggregateFields(): ?array {
+ return $this->aggregateFields;
+ }
+
/**
* Current row.
*
$sql = '';
$fields = $this->getParser()->getTrackingFields();
foreach ($fields as $fieldName => $spec) {
- $sql .= 'ADD COLUMN _' . $fieldName . ' ' . $spec . ',';
+ $sql .= 'ADD COLUMN _' . $fieldName . ' ' . $spec['type'] . ',';
}
return $sql;
}
* @return string
*/
private function getSelectClause(): string {
+ if ($this->getAggregateFields()) {
+ $fields = [];
+ foreach ($this->getAggregateFields() as $field) {
+ $fields[] = $field['operation'] . '(_' . $field['name'] . ') as ' . $field['name'];
+ }
+ return implode(',', $fields);
+ }
return $this->getSelectFields() ? '`' . implode('`, `', $this->getSelectFields()) . '`' : '*';
}
$this->assign('downloadAddressRecordsUrl', $this->getDownloadURL(CRM_Import_Parser::UNPARSED_ADDRESS_WARNING));
$this->assign('downloadPledgePaymentErrorRecordsUrl', $this->getDownloadURL(CRM_Contribute_Import_Parser_Contribution::PLEDGE_PAYMENT_ERROR));
$this->assign('downloadSoftCreditErrorRecordsUrl', $this->getDownloadURL(CRM_Contribute_Import_Parser_Contribution::SOFT_CREDIT_ERROR));
+ $this->assign('trackingSummary', $this->getTrackingSummary());
+
$userJobID = CRM_Utils_Request::retrieve('user_job_id', 'String', $this, TRUE);
$userJob = UserJob::get(TRUE)
->addWhere('id', '=', $userJobID)
]);
}
+ /**
+ * Get the url to download the relevant csv file.
+ * @param string $status
+ *
+ * @return string
+ */
+
+ /**
+ *
+ * @return array
+ */
+ public function getTrackingSummary(): array {
+ $summary = [];
+ $fields = $this->getParser()->getTrackingFields();
+ $row = $this->getDataSourceObject()->setAggregateFields($fields)->getRow();
+ foreach ($fields as $fieldName => $field) {
+ $summary[] = [
+ 'field_name' => $fieldName,
+ 'description' => $field['description'],
+ 'value' => $row[$fieldName],
+ ];
+ }
+
+ return $summary;
+ }
+
/**
* Get the fields available for import selection.
*
* @return \CRM_Contact_Import_Parser_Contact|\CRM_Contribute_Import_Parser_Contribution
*/
protected function getParser() {
+ foreach (CRM_Core_BAO_UserJob::getTypes() as $jobType) {
+ if ($jobType['id'] === $this->getUserJob()['type_id']) {
+ $className = $jobType['class'];
+ $classObject = new $className();
+ $classObject->setUserJobID($this->getUserJobID());
+ return $classObject;
+ };
+ }
return NULL;
}
{/if}
<tr>
- <td class="label crm-grid-cell">{ts}Total Contacts{/ts}</td>
+ <td class="label crm-grid-cell">{ts}Total Rows Imported{/ts}</td>
<td class="data">{$validRowCount}</td>
- <td class="explanation">{ts}Total number of contact records created or modified during the import.{/ts}</td>
+ <td class="explanation">{ts}Total number of primary records created or modified during the import.{/ts}</td>
</tr>
+ {foreach from=$trackingSummary item="summaryRow"}
+ <tr>
+ <td class="label crm-grid-cell"></td>
+ <td class="data">{$summaryRow.value}</td>
+ <td class="explanation">{$summaryRow.description}</td>
+ </tr>
+ {/foreach}
{if $groupAdditions}
<tr><td class="label crm-grid-cell">{ts}Import to Groups{/ts}</td>