From: Eileen McNaughton Date: Fri, 8 Apr 2022 00:40:07 +0000 (+1200) Subject: Centralise skipColumnHeader to one function X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=9d7974eb12dd2a7d164cffb713b4759ee6229acc;p=civicrm-core.git Centralise skipColumnHeader to one function --- diff --git a/CRM/Activity/Import/Form/Preview.php b/CRM/Activity/Import/Form/Preview.php index b12ffef366..0526eb4338 100644 --- a/CRM/Activity/Import/Form/Preview.php +++ b/CRM/Activity/Import/Form/Preview.php @@ -24,8 +24,7 @@ class CRM_Activity_Import_Form_Preview extends CRM_Import_Form_Preview { * Set variables up before form is built. */ public function preProcess() { - $skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader'); - + parent::preProcess(); // Get the data from the session. $dataValues = $this->get('dataValues'); $mapper = $this->get('mapper'); @@ -42,14 +41,6 @@ class CRM_Activity_Import_Form_Preview extends CRM_Import_Form_Preview { } $this->assign('savedMappingName', $mappingId ? $mapDAO->name : NULL); - if ($skipColumnHeader) { - $this->assign('skipColumnHeader', $skipColumnHeader); - $this->assign('rowDisplayCount', 3); - } - else { - $this->assign('rowDisplayCount', 2); - } - if ($invalidRowCount) { $urlParams = 'type=' . CRM_Import_Parser::ERROR . '&parser=CRM_Activity_Import_Parser'; $this->set('downloadErrorRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams)); @@ -92,7 +83,6 @@ class CRM_Activity_Import_Form_Preview extends CRM_Import_Form_Preview { public function postProcess() { $fileName = $this->controller->exportValue('DataSource', 'uploadFile'); $separator = $this->controller->exportValue('DataSource', 'fieldSeparator'); - $skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader'); $invalidRowCount = $this->get('invalidRowCount'); $conflictRowCount = $this->get('conflictRowCount'); $onDuplicate = $this->get('onDuplicate'); @@ -117,7 +107,7 @@ class CRM_Activity_Import_Form_Preview extends CRM_Import_Form_Preview { } $parser->run($fileName, $separator, $mapperFields, - $skipColumnHeader, + $this->getSubmittedValue('skipColumnHeader'), CRM_Import_Parser::MODE_IMPORT, $onDuplicate, $this->get('statusID'), diff --git a/CRM/Contact/Import/Form/Preview.php b/CRM/Contact/Import/Form/Preview.php index 2e8028a01e..e8d082b641 100644 --- a/CRM/Contact/Import/Form/Preview.php +++ b/CRM/Contact/Import/Form/Preview.php @@ -108,7 +108,7 @@ class CRM_Contact_Import_Form_Preview extends CRM_Import_Form_Preview { $showColNames = TRUE; if ('CRM_Import_DataSource_CSV' == $this->get('dataSource') && - !$this->get('skipColumnHeader') + !$this->getSubmittedValue('skipColumnHeader') ) { $showColNames = FALSE; } diff --git a/CRM/Contribute/Import/Form/Preview.php b/CRM/Contribute/Import/Form/Preview.php index a1849368a6..d71fccf323 100644 --- a/CRM/Contribute/Import/Form/Preview.php +++ b/CRM/Contribute/Import/Form/Preview.php @@ -24,8 +24,7 @@ class CRM_Contribute_Import_Form_Preview extends CRM_Import_Form_Preview { * Set variables up before form is built. */ public function preProcess() { - $skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader'); - + parent::preProcess(); //get the data from the session $dataValues = $this->get('dataValues'); $mapper = $this->get('mapper'); @@ -44,14 +43,6 @@ class CRM_Contribute_Import_Form_Preview extends CRM_Import_Form_Preview { } $this->assign('savedMappingName', $mappingId ? $mapDAO->name : NULL); - if ($skipColumnHeader) { - $this->assign('skipColumnHeader', $skipColumnHeader); - $this->assign('rowDisplayCount', 3); - } - else { - $this->assign('rowDisplayCount', 2); - } - if ($invalidRowCount) { $urlParams = 'type=' . CRM_Import_Parser::ERROR . '&parser=CRM_Contribute_Import_Parser_Contribution'; $this->set('downloadErrorRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams)); @@ -94,7 +85,6 @@ class CRM_Contribute_Import_Form_Preview extends CRM_Import_Form_Preview { public function postProcess() { $fileName = $this->controller->exportValue('DataSource', 'uploadFile'); $separator = $this->controller->exportValue('DataSource', 'fieldSeparator'); - $skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader'); $invalidRowCount = $this->get('invalidRowCount'); $conflictRowCount = $this->get('conflictRowCount'); $onDuplicate = $this->get('onDuplicate'); @@ -129,7 +119,7 @@ class CRM_Contribute_Import_Form_Preview extends CRM_Import_Form_Preview { } $parser->run($fileName, $separator, $mapperFields, - $skipColumnHeader, + $this->getSubmittedValue('skipColumnHeader'), CRM_Import_Parser::MODE_IMPORT, $this->get('contactType'), $onDuplicate, diff --git a/CRM/Custom/Import/Form/Preview.php b/CRM/Custom/Import/Form/Preview.php index 0abfd72195..cc77ef8a70 100644 --- a/CRM/Custom/Import/Form/Preview.php +++ b/CRM/Custom/Import/Form/Preview.php @@ -13,8 +13,7 @@ class CRM_Custom_Import_Form_Preview extends CRM_Import_Form_Preview { * @return void */ public function preProcess() { - $skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader'); - + parent::preProcess(); //get the data from the session $dataValues = $this->get('dataValues'); $mapper = $this->get('mapper'); @@ -32,14 +31,6 @@ class CRM_Custom_Import_Form_Preview extends CRM_Import_Form_Preview { } $this->assign('savedMappingName', $mappingId ? $mapDAO->name : NULL); - if ($skipColumnHeader) { - $this->assign('skipColumnHeader', $skipColumnHeader); - $this->assign('rowDisplayCount', 3); - } - else { - $this->assign('rowDisplayCount', 2); - } - if ($invalidRowCount) { $urlParams = 'type=' . CRM_Import_Parser::ERROR . $this->_importParserUrl; $this->set('downloadErrorRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams)); @@ -82,7 +73,6 @@ class CRM_Custom_Import_Form_Preview extends CRM_Import_Form_Preview { public function postProcess() { $fileName = $this->controller->exportValue('DataSource', 'uploadFile'); $separator = $this->controller->exportValue('DataSource', 'fieldSeparator'); - $skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader'); $invalidRowCount = $this->get('invalidRowCount'); $conflictRowCount = $this->get('conflictRowCount'); $onDuplicate = $this->get('onDuplicate'); @@ -109,7 +99,7 @@ class CRM_Custom_Import_Form_Preview extends CRM_Import_Form_Preview { } $parser->run($fileName, $separator, $mapperFields, - $skipColumnHeader, + $this->getSubmittedValue('skipColumnHeader'), CRM_Import_Parser::MODE_IMPORT, $this->get('contactType'), $onDuplicate diff --git a/CRM/Event/Import/Form/Preview.php b/CRM/Event/Import/Form/Preview.php index ccec35738a..e39652bbf2 100644 --- a/CRM/Event/Import/Form/Preview.php +++ b/CRM/Event/Import/Form/Preview.php @@ -27,7 +27,7 @@ class CRM_Event_Import_Form_Preview extends CRM_Import_Form_Preview { * @return void */ public function preProcess() { - $skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader'); + parent::preProcess(); //get the data from the session $dataValues = $this->get('dataValues'); @@ -45,14 +45,6 @@ class CRM_Event_Import_Form_Preview extends CRM_Import_Form_Preview { } $this->assign('savedMappingName', $mappingId ? $mapDAO->name : NULL); - if ($skipColumnHeader) { - $this->assign('skipColumnHeader', $skipColumnHeader); - $this->assign('rowDisplayCount', 3); - } - else { - $this->assign('rowDisplayCount', 2); - } - if ($invalidRowCount) { $urlParams = 'type=' . CRM_Import_Parser::ERROR . '&parser=CRM_Event_Import_Parser'; $this->set('downloadErrorRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams)); @@ -95,7 +87,6 @@ class CRM_Event_Import_Form_Preview extends CRM_Import_Form_Preview { public function postProcess() { $fileName = $this->controller->exportValue('DataSource', 'uploadFile'); $separator = $this->controller->exportValue('DataSource', 'fieldSeparator'); - $skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader'); $invalidRowCount = $this->get('invalidRowCount'); $conflictRowCount = $this->get('conflictRowCount'); $onDuplicate = $this->get('onDuplicate'); @@ -120,7 +111,7 @@ class CRM_Event_Import_Form_Preview extends CRM_Import_Form_Preview { } $parser->run($fileName, $separator, $mapperFields, - $skipColumnHeader, + $this->getSubmittedValue('skipColumnHeader'), CRM_Import_Parser::MODE_IMPORT, $this->get('contactType'), $onDuplicate diff --git a/CRM/Import/Form/Preview.php b/CRM/Import/Form/Preview.php index 5067a22c48..3ba704f339 100644 --- a/CRM/Import/Form/Preview.php +++ b/CRM/Import/Form/Preview.php @@ -21,7 +21,7 @@ * TODO: CRM-11254 - if preProcess and postProcess functions can be reconciled between the 5 child classes, * those classes can be removed entirely and this class will not need to be abstract */ -abstract class CRM_Import_Form_Preview extends CRM_Core_Form { +abstract class CRM_Import_Form_Preview extends CRM_Import_Forms { /** * Return a descriptive name for the page, used in wizard header. @@ -32,6 +32,14 @@ abstract class CRM_Import_Form_Preview extends CRM_Core_Form { return ts('Preview'); } + /** + * Assign common values to the template. + */ + public function preProcess() { + $this->assign('skipColumnHeader', $this->getSubmittedValue('skipColumnHeader')); + $this->assign('rowDisplayCount', $this->getSubmittedValue('skipColumnHeader') ? 3 : 2); + } + /** * Build the form object. */ diff --git a/CRM/Import/Forms.php b/CRM/Import/Forms.php new file mode 100644 index 0000000000..c1fcd9ed1e --- /dev/null +++ b/CRM/Import/Forms.php @@ -0,0 +1,40 @@ + 'DataSource', + ]; + if (array_key_exists($fieldName, $mappedValues)) { + return $this->controller->exportValue($mappedValues[$fieldName], $fieldName); + } + return parent::getSubmittedValue($fieldName); + + } + +} diff --git a/CRM/Member/Import/Form/Preview.php b/CRM/Member/Import/Form/Preview.php index dd84e13468..6502770d7a 100644 --- a/CRM/Member/Import/Form/Preview.php +++ b/CRM/Member/Import/Form/Preview.php @@ -27,8 +27,7 @@ class CRM_Member_Import_Form_Preview extends CRM_Import_Form_Preview { * @return void */ public function preProcess() { - $skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader'); - + parent::preProcess(); //get the data from the session $dataValues = $this->get('dataValues'); $mapper = $this->get('mapper'); @@ -45,14 +44,6 @@ class CRM_Member_Import_Form_Preview extends CRM_Import_Form_Preview { } $this->assign('savedMappingName', $mappingId ? $mapDAO->name : NULL); - if ($skipColumnHeader) { - $this->assign('skipColumnHeader', $skipColumnHeader); - $this->assign('rowDisplayCount', 3); - } - else { - $this->assign('rowDisplayCount', 2); - } - if ($invalidRowCount) { $urlParams = 'type=' . CRM_Import_Parser::ERROR . '&parser=CRM_Member_Import_Parser_Membership'; $this->set('downloadErrorRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams)); @@ -96,7 +87,6 @@ class CRM_Member_Import_Form_Preview extends CRM_Import_Form_Preview { public function postProcess() { $fileName = $this->controller->exportValue('DataSource', 'uploadFile'); $separator = $this->controller->exportValue('DataSource', 'fieldSeparator'); - $skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader'); $invalidRowCount = $this->get('invalidRowCount'); $conflictRowCount = $this->get('conflictRowCount'); $onDuplicate = $this->get('onDuplicate'); @@ -140,7 +130,7 @@ class CRM_Member_Import_Form_Preview extends CRM_Import_Form_Preview { } $parser->run($fileName, $separator, $mapperFields, - $skipColumnHeader, + $this->getSubmittedValue('skipColumnHeader'), CRM_Import_Parser::MODE_IMPORT, $this->get('contactType'), $onDuplicate,