*/
protected $userJob;
+ /**
+ * @var \CRM_Import_Parser
+ */
+ protected $parser;
+
/**
* Get User Job.
*
if ($fieldName === 'dataSource') {
// Hard-coded handling for DataSource as it affects the contents of
// getSubmittableFields and can cause a loop.
- return $this->controller->exportValue('DataSource', 'dataSource');
+ // Note that the non-contact imports are not currently sharing the DataSource.tpl
+ // that adds the CSV/SQL options & hence fall back on this hidden field.
+ // - todo - switch to the same DataSource.tpl for all.
+ return $this->controller->exportValue('DataSource', 'dataSource') ?? $this->controller->exportValue('DataSource', 'hidden_dataSource');
}
$mappedValues = $this->getSubmittableFields();
if (array_key_exists($fieldName, $mappedValues)) {
$id = UserJob::create(FALSE)
->setValues([
'created_id' => CRM_Core_Session::getLoggedInContactID(),
- 'type_id:name' => 'contact_import',
+ 'type_id:name' => $this->getUserJobType(),
'status_id:name' => 'draft',
// This suggests the data could be cleaned up after this.
'expires_date' => '+ 1 week',
* @return array|int
* One or more of the statues available - e.g
* CRM_Import_Parser::VALID
- * or [CRM_Import_Parser::ERROR, CRM_Import_Parser::CONFLICT]
+ * or [CRM_Import_Parser::ERROR, CRM_Import_Parser::VALID]
*
* @throws \CRM_Core_Exception
* @throws \API_Exception
$message = array_pop($record);
// Also pop off the status - but we are not going to use this at this stage.
array_pop($record);
+ // Related entities
+ array_pop($record);
+ // Entity_id
+ array_pop($record);
array_unshift($record, $message);
array_unshift($record, $rowNumber);
return $record;
* @throws \API_Exception
*/
protected function getAvailableFields(): array {
- $parser = new CRM_Contact_Import_Parser_Contact();
- $parser->setUserJobID($this->getUserJobID());
- return $parser->getAvailableFields();
+ return $this->getParser()->getAvailableFields();
+ }
+
+ /**
+ * Get an instance of the parser class.
+ *
+ * @return \CRM_Contact_Import_Parser_Contact|\CRM_Contribute_Import_Parser_Contribution
+ */
+ protected function getParser() {
+ return NULL;
+ }
+
+ /**
+ * Get the mapped fields as an array of labels.
+ *
+ * e.g
+ * ['First Name', 'Employee Of - First Name', 'Home - Street Address']
+ *
+ * @return array
+ * @throws \API_Exception
+ * @throws \CRM_Core_Exception
+ */
+ protected function getMappedFieldLabels(): array {
+ $mapper = [];
+ $parser = $this->getParser();
+ foreach ($this->getSubmittedValue('mapper') as $columnNumber => $mappedField) {
+ $mapper[$columnNumber] = $parser->getMappedFieldLabel($parser->getMappingFieldFromMapperInput($mappedField, 0, $columnNumber));
+ }
+ return $mapper;
+ }
+
+ /**
+ * Assign variables required for the MapField form.
+ *
+ * @throws \API_Exception
+ * @throws \CRM_Core_Exception
+ */
+ protected function assignMapFieldVariables(): void {
+ $this->addExpectedSmartyVariable('highlightedRelFields');
+ $this->_columnCount = $this->getNumberOfColumns();
+ $this->_columnNames = $this->getColumnHeaders();
+ $this->_dataValues = array_values($this->getDataRows([], 2));
+ $this->assign('columnNames', $this->getColumnHeaders());
+ $this->assign('highlightedFields', $this->getHighlightedFields());
+ $this->assign('columnCount', $this->_columnCount);
+ $this->assign('dataValues', $this->_dataValues);
+ }
+
+ /**
+ * Get the fields to be highlighted in the UI.
+ *
+ * The highlighted fields are those used to match
+ * to an existing entity.
+ *
+ * @return array
+ *
+ * @throws \CRM_Core_Exception
+ */
+ protected function getHighlightedFields(): array {
+ return [];
+ }
+
+ /**
+ * Get the data patterns to pattern match the incoming data.
+ *
+ * @return array
+ */
+ public function getDataPatterns(): array {
+ return $this->getParser()->getDataPatterns();
+ }
+
+ /**
+ * Get the data patterns to pattern match the incoming data.
+ *
+ * @return array
+ */
+ public function getHeaderPatterns(): array {
+ return $this->getParser()->getHeaderPatterns();
}
}