/** * 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(); }
public function testMakeFormsAndElementTypesByMappingDataAndImportRulesType() { $mappingData = array('column_0' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => 'date', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => '2012-01-12'))), 'column_1' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => 'dateTime', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => '2012-01-12 00:45'))), 'column_2' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => 'lastName', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => 'def'))), 'column_3' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => 'decimal', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => '1.45'))), 'column_4' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => 'integer', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => 1))), 'column_5' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => 'phone', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => '7844121541'))), 'column_6' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => 'textArea', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => 'testTextArea'))), 'column_7' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => 'url', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => 'http://www.test.com'))), 'column_8' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => 'string', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => 'testString'))), 'column_9' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => 'firstName', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => 'testfirstName')))); $data = MappingRuleFormAndElementTypeUtil::makeFormsAndElementTypesByMappingDataAndImportRulesType($mappingData, 'ImportModelTestItem'); $this->assertEquals(10, count($data)); $this->assertEquals('2012-01-12', $data['column_0'][0]['mappingRuleForm']->defaultValue); $this->assertEquals('Date', $data['column_0'][0]['elementType']); $this->assertEquals('2012-01-12 00:45', $data['column_1'][0]['mappingRuleForm']->defaultValue); $this->assertEquals('DateTime', $data['column_1'][0]['elementType']); $this->assertEquals('def', $data['column_2'][0]['mappingRuleForm']->defaultValue); $this->assertEquals('Text', $data['column_2'][0]['elementType']); $this->assertEquals('1.45', $data['column_3'][0]['mappingRuleForm']->defaultValue); $this->assertEquals('Decimal', $data['column_3'][0]['elementType']); $this->assertEquals(1, $data['column_4'][0]['mappingRuleForm']->defaultValue); $this->assertEquals('Integer', $data['column_4'][0]['elementType']); $this->assertEquals('7844121541', $data['column_5'][0]['mappingRuleForm']->defaultValue); $this->assertEquals('Phone', $data['column_5'][0]['elementType']); $this->assertEquals('testTextArea', $data['column_6'][0]['mappingRuleForm']->defaultValue); $this->assertEquals('TextArea', $data['column_6'][0]['elementType']); $this->assertEquals('http://www.test.com', $data['column_7'][0]['mappingRuleForm']->defaultValue); $this->assertEquals('Url', $data['column_7'][0]['elementType']); $this->assertEquals('testString', $data['column_8'][0]['mappingRuleForm']->defaultValue); $this->assertEquals('Text', $data['column_8'][0]['elementType']); $this->assertEquals('testfirstName', $data['column_9'][0]['mappingRuleForm']->defaultValue); $this->assertEquals('Text', $data['column_9'][0]['elementType']); }