// retrieve and highlight required custom fields
$formattedFieldNames = $this->formatCustomFieldName($this->_mapperFields);
- $this->assign('highlightedFields', $this->getHighlightedFields());
$this->_formattedFieldNames[$contactType] = $this->_mapperFields = array_merge($this->_mapperFields, $formattedFieldNames);
-
- $columnNames = $this->getColumnHeaders();
-
- $this->_columnCount = $this->getNumberOfColumns();
- $this->_columnNames = $columnNames;
- $this->assign('columnNames', $this->getColumnHeaders());
- $this->assign('columnCount', $this->_columnCount);
- $this->_dataValues = array_values($this->getDataRows([], 2));
- $this->assign('dataValues', $this->_dataValues);
+ $this->assignMapFieldVariables();
}
/**
*
* @throws \CRM_Core_Exception
*/
- private function getHighlightedFields(): array {
+ protected function getHighlightedFields(): array {
$entityFields = [
'Individual' => ['first_name', 'last_name'],
'Organization' => ['organization_name'],
* @throws \CRM_Core_Exception
*/
public function preProcess() {
- $columnNames = $this->getColumnHeaders();
+ parent::preProcess();
$this->_disableUSPS = $this->getSubmittedValue('disableUSPS');
- //assign column names
- $this->assign('columnNames', $columnNames);
-
- //get the mapping name displayed if the mappingId is set
- $mappingId = $this->get('loadMappingId');
- if ($mappingId) {
- $mapDAO = new CRM_Core_DAO_Mapping();
- $mapDAO->id = $mappingId;
- $mapDAO->find(TRUE);
- }
- $this->assign('savedMappingName', $mappingId ? $mapDAO->name : NULL);
-
- $this->assign('rowDisplayCount', 2);
-
$groups = CRM_Core_PseudoConstant::nestedGroup();
$this->set('groups', $groups);
$this->set('tag', $tag);
}
- $this->assign('downloadErrorRecordsUrl', $this->getDownloadURL(CRM_Import_Parser::ERROR));
- $this->assign('invalidRowCount', $this->getRowCount(CRM_Import_Parser::ERROR));
- $this->assign('validRowCount', $this->getRowCount(CRM_Import_Parser::VALID));
- $this->assign('totalRowCount', $this->getRowCount([]));
- $this->assign('mapper', $this->getMappedFieldLabels());
- $this->assign('dataValues', $this->getDataRows([], 2));
-
$this->setStatusUrl();
}
*
* @return array
*/
- public function getHeaderPatterns() {
+ public function getHeaderPatterns(): array {
return CRM_Utils_Array::collect('headerPattern', $this->getContactImportMetadata());
}
*
* @return array
*/
- public function getDataPatterns() {
+ public function getDataPatterns(): array {
return CRM_Utils_Array::collect('dataPattern', $this->getContactImportMetadata());
}
* Assign common values to the template.
*/
public function preProcess() {
- $this->assign('skipColumnHeader', $this->getSubmittedValue('skipColumnHeader'));
- $this->assign('rowDisplayCount', $this->getSubmittedValue('skipColumnHeader') ? 3 : 2);
+ $this->assignPreviewVariables();
}
/**
$this->assign('statusUrl', $statusUrl);
}
+ /**
+ * Assign smarty variables for the preview screen.
+ *
+ * @throws \API_Exception
+ * @throws \CRM_Core_Exception
+ */
+ protected function assignPreviewVariables(): void {
+ $this->assign('downloadErrorRecordsUrl', $this->getDownloadURL(CRM_Import_Parser::ERROR));
+ $this->assign('invalidRowCount', $this->getRowCount(CRM_Import_Parser::ERROR));
+ $this->assign('validRowCount', $this->getRowCount(CRM_Import_Parser::VALID));
+ $this->assign('totalRowCount', $this->getRowCount([]));
+ $this->assign('mapper', $this->getMappedFieldLabels());
+ $this->assign('dataValues', $this->getDataRows([], 2));
+ $this->assign('columnNames', $this->getColumnHeaders());
+ //get the mapping name displayed if the mappingId is set
+ $mappingId = $this->get('loadMappingId');
+ if ($mappingId) {
+ $mapDAO = new CRM_Core_DAO_Mapping();
+ $mapDAO->id = $mappingId;
+ $mapDAO->find(TRUE);
+ }
+ $this->assign('savedMappingName', $mappingId ? $mapDAO->name : NULL);
+ $this->assign('skipColumnHeader', $this->getSubmittedValue('skipColumnHeader'));
+ // rowDisplayCount is deprecated - it used to be used with {section} but we have nearly gotten rid of it.
+ $this->assign('rowDisplayCount', $this->getSubmittedValue('skipColumnHeader') ? 3 : 2);
+ }
+
}
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();
+ }
+
}
/**
* @return array
*/
- public function getHeaderPatterns() {
+ public function getHeaderPatterns(): array {
$values = [];
foreach ($this->_fields as $name => $field) {
if (isset($field->_headerPattern)) {
/**
* @return array
*/
- public function getDataPatterns() {
+ public function getDataPatterns():array {
$values = [];
foreach ($this->_fields as $name => $field) {
$values[$name] = $field->_dataPattern;