Skip to content

Commit

Permalink
Merge pull request #23683 from eileenmcnaughton/import_cont
Browse files Browse the repository at this point in the history
[Import] [Contribution] Cleanup templates & form variables, following contact pattern
  • Loading branch information
colemanw authored Jun 4, 2022
2 parents b0f84c0 + 1c82489 commit 194e85b
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 284 deletions.
39 changes: 14 additions & 25 deletions CRM/Contribute/Import/Form/MapField.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,15 @@ protected static function checkRequiredFields($self, string $contactORContributi
* Set variables up before form is built.
*/
public function preProcess() {
parent::preProcess();
$this->_mapperFields = $this->getAvailableFields();
asort($this->_mapperFields);

$this->_columnCount = $this->get('columnCount');
$this->assign('columnCount', $this->_columnCount);
$this->_dataValues = $this->get('dataValues');
$this->assign('dataValues', $this->_dataValues);
$skipColumnHeader = $this->getSubmittedValue('skipColumnHeader');
$this->_onDuplicate = $this->getSubmittedValue('onDuplicate');
$this->assign('skipColumnHeader', $skipColumnHeader);

$skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader');
$this->_onDuplicate = $this->get('onDuplicate', $onDuplicate ?? "");

if ($skipColumnHeader) {
$this->assign('skipColumnHeader', $skipColumnHeader);
$this->assign('rowDisplayCount', 3);
// If we had a column header to skip, stash it for later

$this->_columnHeaders = $this->_dataValues[0];
}
else {
$this->assign('rowDisplayCount', 2);
}
$highlightedFields = ['financial_type_id', 'total_amount'];
//CRM-2219 removing other required fields since for updation only
//invoice id or trxn id or contribution id is required.
Expand Down Expand Up @@ -157,10 +145,11 @@ public function buildQuickForm() {

$defaults = [];
$mapperKeys = array_keys($this->_mapperFields);
$hasHeaders = !empty($this->_columnHeaders);
$headerPatterns = $this->get('headerPatterns');
$dataPatterns = $this->get('dataPatterns');
$mapperKeysValues = $this->controller->exportValue($this->_name, 'mapper');
$hasHeaders = $this->getSubmittedValue('skipColumnHeader');
$headerPatterns = $this->getHeaderPatterns();
$dataPatterns = $this->getDataPatterns();
$mapperKeysValues = $this->getSubmittedValue('mapper');
$columnHeaders = $this->getColumnHeaders();

/* Initialize all field usages to false */
foreach ($mapperKeys as $key) {
Expand Down Expand Up @@ -188,7 +177,7 @@ public function buildQuickForm() {
//used to warn for mismatch column count or mismatch mapping
$warning = 0;

for ($i = 0; $i < $this->_columnCount; $i++) {
foreach ($columnHeaders as $i => $columnHeader) {
$sel = &$this->addElement('hierselect', "mapper[$i]", ts('Mapper for Field %1', [1 => $i]), NULL);
$jsSet = FALSE;
if ($this->get('savedMapping')) {
Expand Down Expand Up @@ -228,7 +217,7 @@ public function buildQuickForm() {
$js .= "swapOptions($formName, 'mapper[$i]', 0, 3, 'hs_mapper_0_');\n";

if ($hasHeaders) {
$defaults["mapper[$i]"] = [$this->defaultFromHeader($this->_columnHeaders[$i], $headerPatterns)];
$defaults["mapper[$i]"] = [$this->defaultFromHeader($columnHeader, $headerPatterns)];
}
else {
$defaults["mapper[$i]"] = [$this->defaultFromData($dataPatterns, $i)];
Expand All @@ -240,15 +229,15 @@ public function buildQuickForm() {
$js .= "swapOptions($formName, 'mapper[$i]', 0, 3, 'hs_mapper_0_');\n";
if ($hasHeaders) {
// do array search first to see if has mapped key
$columnKey = array_search($this->_columnHeaders[$i], $this->_mapperFields);
$columnKey = array_search($columnHeader, $this->_mapperFields);
if (isset($this->_fieldUsed[$columnKey])) {
$defaults["mapper[$i]"] = $columnKey;
$this->_fieldUsed[$key] = TRUE;
}
else {
// Infer the default from the column names if we have them
$defaults["mapper[$i]"] = [
$this->defaultFromHeader($this->_columnHeaders[$i], $headerPatterns),
$this->defaultFromHeader($columnHeader, $headerPatterns),
0,
];
}
Expand Down Expand Up @@ -433,7 +422,7 @@ public function postProcess() {
if (isset($mapperKeys[$i][0]) && $mapperKeys[$i][0] == 'soft_credit') {
$mapperSoftCredit[$i] = $mapperKeys[$i][1];
if (strpos($mapperSoftCredit[$i], '_') !== FALSE) {
list($first, $second) = explode('_', $mapperSoftCredit[$i]);
[$first, $second] = explode('_', $mapperSoftCredit[$i]);
$softCreditFields[$i] = ucwords($first . " " . $second);
}
else {
Expand Down
32 changes: 5 additions & 27 deletions CRM/Contribute/Import/Form/Preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,16 @@ class CRM_Contribute_Import_Form_Preview extends CRM_Import_Form_Preview {
*/
public function preProcess() {
parent::preProcess();
//get the data from the session
$dataValues = $this->get('dataValues');
$invalidRowCount = $this->get('invalidRowCount');

//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);
$invalidRowCount = $this->getRowCount(CRM_Import_Parser::VALID);

$downloadURL = '';
if ($invalidRowCount) {
$urlParams = 'type=' . CRM_Import_Parser::ERROR . '&parser=CRM_Contribute_Import_Parser_Contribution';
$this->set('downloadErrorRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
$downloadURL = CRM_Utils_System::url('civicrm/export', $urlParams);
}

$properties = [
'dataValues',
'columnCount',
'totalRowCount',
'validRowCount',
'invalidRowCount',
'downloadErrorRecordsUrl',
];
$this->setStatusUrl();
$this->assign('mapper', $this->getMappedFieldLabels());

foreach ($properties as $property) {
$this->assign($property, $this->get($property));
}
$this->assign('downloadErrorRecordsUrl', $downloadURL);
}

/**
Expand Down Expand Up @@ -105,7 +83,7 @@ public function postProcess() {
$mapperFields,
$this->getSubmittedValue('skipColumnHeader'),
CRM_Import_Parser::MODE_IMPORT,
$this->get('contactType'),
$this->getSubmittedValue('contactType'),
$onDuplicate,
$this->get('statusID'),
$this->get('totalRowCount')
Expand Down
Loading

0 comments on commit 194e85b

Please sign in to comment.