$id = UserJob::create(FALSE)
->setValues([
'created_id' => CRM_Core_Session::getLoggedInContactID(),
- 'type_id:name' => $this->getUserJobType(),
+ 'job_type' => $this->getUserJobType(),
'status_id:name' => 'draft',
// This suggests the data could be cleaned up after this.
'expires_date' => '+ 1 week',
*/
protected function getOutputRows($statuses = [], int $limit = 0) {
$statuses = (array) $statuses;
- return $this->getDataSourceObject()->setLimit($limit)->setStatuses($statuses)
- ->setSelectFields(array_merge(['_id', '_status_message'], $this->getColumnHeaders()))
- ->setStatuses($statuses)->getRows();
+ $dataSource = $this->getDataSourceObject()->setLimit($limit)->setStatuses($statuses)->setStatuses($statuses);
+ $dataSource->setSelectFields(array_merge(['_id', '_status_message'], $dataSource->getDataFieldNames()));
+ return $dataSource->getRows();
}
/**
*/
public static function outputCSV(): void {
$userJobID = CRM_Utils_Request::retrieveValue('user_job_id', 'Integer', NULL, TRUE);
- $status = CRM_Utils_Request::retrieveValue('status', 'String', NULL, TRUE);
+ $status = (int) CRM_Utils_Request::retrieveValue('status', 'String', NULL, TRUE);
$saveFileName = CRM_Import_Parser::saveFileName($status);
$form = new CRM_Import_Forms();
$writer = Writer::createFromFileObject(new SplTempFileObject());
$headers = $form->getOutputColumnsHeaders();
$writer->insertOne($headers);
- // Note this might be more inefficient that iterating the result
+ // Note this might be more inefficient by iterating the result
// set & doing insertOne - possibly something to explore later.
$writer->insertAll($form->getOutputRows($status));
-
- CRM_Utils_System::setHttpHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
- CRM_Utils_System::setHttpHeader('Content-Description', 'File Transfer');
- CRM_Utils_System::setHttpHeader('Content-Type', 'text/csv; charset=UTF-8');
$writer->output($saveFileName);
CRM_Utils_System::civiExit();
}
]);
}
+ /**
+ * 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()['job_type']) {
+ $className = $jobType['class'];
+ $classObject = new $className();
+ $classObject->setUserJobID($this->getUserJobID());
+ return $classObject;
+ };
+ }
return NULL;
}