Esempio n. 1
0
 public function testReIndexExtraColumnNamesByPostData()
 {
     $postData = array('column_0' => array('type' => 'importColumn'), 'column_1' => array('type' => 'importColumn'), 'column_2' => array('type' => 'importColumn'), 'column_5' => array('type' => 'extraColumn'), 'column_55' => array('type' => 'extraColumn'));
     $reIndexedPostData = ImportMappingUtil::reIndexExtraColumnNamesByPostData($postData);
     $compareData = array('column_0' => array('type' => 'importColumn'), 'column_1' => array('type' => 'importColumn'), 'column_2' => array('type' => 'importColumn'), 'column_3' => array('type' => 'extraColumn'), 'column_4' => array('type' => 'extraColumn'));
     $this->assertEquals($compareData, $reIndexedPostData);
 }
 /**
  * Step 4. Import mapping
  */
 public function actionStep4($id)
 {
     $import = Import::getById((int) $id);
     $importWizardForm = ImportWizardUtil::makeFormByImport($import);
     $importWizardForm->setScenario('saveMappingData');
     $importRulesClassName = ImportRulesUtil::getImportRulesClassNameByType($importWizardForm->importRulesType);
     if (isset($_POST[get_class($importWizardForm)])) {
         $reIndexedPostData = ImportMappingUtil::reIndexExtraColumnNamesByPostData($_POST[get_class($importWizardForm)]);
         $sanitizedPostData = ImportWizardFormPostUtil::sanitizePostByTypeForSavingMappingData($importWizardForm->importRulesType, $reIndexedPostData);
         ImportWizardUtil::setFormByPostForStep4($importWizardForm, $sanitizedPostData);
         $mappingDataMappingRuleFormsAndElementTypes = MappingRuleFormAndElementTypeUtil::makeFormsAndElementTypesByMappingDataAndImportRulesType($importWizardForm->mappingData, $importWizardForm->importRulesType);
         $validated = MappingRuleFormAndElementTypeUtil::validateMappingRuleForms($mappingDataMappingRuleFormsAndElementTypes);
         if ($validated) {
             //Still validate even if MappingRuleForms fails, so all errors are captured and returned.
             $this->attemptToValidateImportWizardFormAndSave($importWizardForm, $import, 'step5');
         } else {
             $importWizardForm->validate();
             $importWizardForm->addError('mappingData', Zurmo::t('ImportModule', 'There are errors with some of your mapping rules. Please fix.'));
         }
     } else {
         $mappingDataMappingRuleFormsAndElementTypes = MappingRuleFormAndElementTypeUtil::makeFormsAndElementTypesByMappingDataAndImportRulesType($importWizardForm->mappingData, $importWizardForm->importRulesType);
     }
     $dataProvider = $this->makeDataProviderForSampleRow($import, (bool) $importWizardForm->firstRowIsHeaderRow);
     if ($importWizardForm->firstRowIsHeaderRow) {
         $headerRow = ZurmoRedBean::$writer->getFirstRowByTableName($import->getTempTableName());
         assert('$headerRow != null');
     } else {
         $headerRow = null;
     }
     $sampleData = $dataProvider->getData();
     assert('count($sampleData) == 1');
     $sample = current($sampleData);
     $pagerUrl = Yii::app()->createUrl('import/default/sampleRow', array('id' => $import->id));
     $pagerContent = ImportDataProviderPagerUtil::renderPagerAndHeaderTextContent($dataProvider, $pagerUrl);
     $mappingDataMetadata = ImportWizardMappingViewUtil::resolveMappingDataForView($importWizardForm->mappingData, $sample, $headerRow);
     $mappableAttributeIndicesAndDerivedTypes = $importRulesClassName::getMappableAttributeIndicesAndDerivedTypes();
     $title = Zurmo::t('ImportModule', 'Import Wizard - Map Fields');
     $importRulesClassName = ImportRulesUtil::getImportRulesClassNameByType($importWizardForm->importRulesType);
     $stepToUse = ImportStepsAndProgressBarForWizardView::resolveAfterUploadStepByImportClassName(3, $importRulesClassName);
     $progressBarAndStepsView = new ImportStepsAndProgressBarForWizardView($importRulesClassName, $stepToUse);
     $importView = new ImportWizardMappingView($this->getId(), $this->getModule()->getId(), $importWizardForm, $pagerContent, $mappingDataMetadata, $mappingDataMappingRuleFormsAndElementTypes, $mappableAttributeIndicesAndDerivedTypes, $importRulesClassName::getRequiredAttributesLabelsData(), $title);
     echo $this->getImportPageView($progressBarAndStepsView, $importView)->render();
 }