/** * Given an import rules type and an attribute index or derived type string, make an AttributeImportRules object. * @param $importRulesType * @param string $attributeIndexOrDerivedType * @param null || string $penultimateModelClassName * @param null || ExplicitReadWriteModelPermissions $explicitReadWriteModelPermissions * @return object AttributeImportRules * @throws NotSupportedException */ public static function makeByImportRulesTypeAndAttributeIndexOrDerivedType($importRulesType, $attributeIndexOrDerivedType, $penultimateModelClassName = null, $explicitReadWriteModelPermissions = null) { assert('is_string($importRulesType)'); assert('is_string($attributeIndexOrDerivedType)'); assert('($penultimateModelClassName === null) || is_string($penultimateModelClassName)'); assert('($explicitReadWriteModelPermissions === null) || $explicitReadWriteModelPermissions instanceof ExplicitReadWriteModelPermissions'); $importRulesTypeClassName = ImportRulesUtil::getImportRulesClassNameByType($importRulesType); $attributeImportRulesType = $importRulesTypeClassName::getAttributeImportRulesType($attributeIndexOrDerivedType); $modelClassName = $importRulesTypeClassName::getModelClassNameByAttributeIndexOrDerivedType($attributeIndexOrDerivedType); $attributeName = self::resolveModelClassNameAndAttributeNameByAttributeIndexOrDerivedType($modelClassName, $attributeIndexOrDerivedType); if (isset(self::$modelsByClassName[$modelClassName])) { $model = self::$modelsByClassName[$modelClassName]; } else { $model = new $modelClassName(false); self::$modelsByClassName[$modelClassName] = $model; } assert('$attributeImportRulesType !== null'); $attributeImportRulesClassName = $attributeImportRulesType . 'AttributeImportRules'; if (is_subclass_of($attributeImportRulesClassName, 'DerivedAttributeImportRules')) { return new $attributeImportRulesClassName($model, $explicitReadWriteModelPermissions); } if (is_subclass_of($attributeImportRulesClassName, 'NonDerivedAttributeImportRules')) { $attributeImportRules = new $attributeImportRulesClassName($model, $attributeName, $explicitReadWriteModelPermissions); $attributeImportRules->setPenultimateModelClassName($penultimateModelClassName); $penultimateAttributeName = AttributeImportRulesFactory::getAttributeNameFromAttributeNameByAttributeIndexOrDerivedType($attributeIndexOrDerivedType); $attributeImportRules->setPenultimateAttributeName($penultimateAttributeName); return $attributeImportRules; } return new $attributeImportRulesClassName($model, $attributeName, $explicitReadWriteModelPermissions); }
public function testResolveModelClassNameAndAttributeNameByAttributeIndexOrDerivedType() { $modelClassName = 'ImportModelTestItem'; $attributeName = AttributeImportRulesFactory::resolveModelClassNameAndAttributeNameByAttributeIndexOrDerivedType($modelClassName, 'primaryAddress__city'); $this->assertEquals('Address', $modelClassName); $this->assertEquals('city', $attributeName); $modelClassName = 'ImportModelTestItem'; $attributeName = AttributeImportRulesFactory::resolveModelClassNameAndAttributeNameByAttributeIndexOrDerivedType($modelClassName, 'string'); $this->assertEquals('ImportModelTestItem', $modelClassName); $this->assertEquals('string', $attributeName); $modelClassName = 'ImportModelTestItem'; $attributeName = AttributeImportRulesFactory::resolveModelClassNameAndAttributeNameByAttributeIndexOrDerivedType($modelClassName, 'FullName'); $this->assertEquals('ImportModelTestItem', $modelClassName); $this->assertEquals('FullName', $attributeName); }
/** * Based on the column type, filter down (sanitize) the array of $mappableAttributeIndicesAndDerivedTypes * based on which attribute indices and derived types are available. * @param array $mappableAttributeIndicesAndDerivedTypes * @param string $columnType * @return a sanitized array of $mappableAttributeIndicesAndDerivedTypes for the column type. */ protected static function resolveMappableAttributeIndicesAndDerivedTypesByColumnType($mappableAttributeIndicesAndDerivedTypes, $columnType, $importRulesType) { assert('is_array($mappableAttributeIndicesAndDerivedTypes)'); assert('$columnType == "importColumn" || $columnType == "extraColumn"'); assert('is_string($importRulesType)'); if ($columnType == 'importColumn') { return $mappableAttributeIndicesAndDerivedTypes; } $attributeImportRules = AttributeImportRulesFactory::makeCollection($importRulesType, array_keys($mappableAttributeIndicesAndDerivedTypes)); $sanitizedMappableAttributeIndicesAndDerivedTypes = array(); foreach ($mappableAttributeIndicesAndDerivedTypes as $attributeIndicesAndDerivedType => $label) { if ($attributeImportRules[$attributeIndicesAndDerivedType]->getExtraColumnUsableCountOfModelAttributeMappingRuleFormTypesAndElementTypes() > 0) { $sanitizedMappableAttributeIndicesAndDerivedTypes[$attributeIndicesAndDerivedType] = $label; } } return $sanitizedMappableAttributeIndicesAndDerivedTypes; }
public function testParentAccountHasCorrectAttributeImportType() { $attributeImportRules = AttributeImportRulesFactory::makeByImportRulesTypeAndAttributeIndexOrDerivedType('Accounts', 'account'); $this->assertTrue($attributeImportRules instanceof AccountAttributeImportRules); }
/** * Get attribute import rules * @param ImportRules $importRules * @param array $columnMappingData * @return object containing attribute import rules * @throws NotSupportedException */ protected static function getAttributeImportRules(ImportRules $importRules, $columnMappingData) { $attributeImportRules = AttributeImportRulesFactory::makeByImportRulesTypeAndAttributeIndexOrDerivedType($importRules::getType(), $columnMappingData['attributeIndexOrDerivedType'], self::getPenultimateModelClassNameByImportRules($importRules)); if ($attributeImportRules->getModelClassName() == null) { throw new NotSupportedException(); } return $attributeImportRules; }
/** * Make a mapping rule form object. * @param string $importRulesType * @param string $attributeIndexOrDerivedType * @param string $mappingRuleFormClassName */ public static function makeForm($importRulesType, $attributeIndexOrDerivedType, $mappingRuleFormClassName) { assert('is_string($importRulesType)'); assert('is_string($attributeIndexOrDerivedType)'); assert('is_string($mappingRuleFormClassName)'); $importRulesTypeClassName = ImportRulesUtil::getImportRulesClassNameByType($importRulesType); $modelClassName = $importRulesTypeClassName::getModelClassNameByAttributeIndexOrDerivedType($attributeIndexOrDerivedType); $attributeName = AttributeImportRulesFactory::resolveModelClassNameAndAttributeNameByAttributeIndexOrDerivedType($modelClassName, $attributeIndexOrDerivedType); $mappingRuleForm = new $mappingRuleFormClassName($modelClassName, $attributeName); return $mappingRuleForm; }
/** * Validation used in the saveMappingData scenario to make sure the mapping data is correct based on * user input. Runs several different validations on the data. This does not validate the validity of the * mapping rules data itself. That is done seperately. * @see MappingRuleFormAndElementTypeUtil::validateMappingRuleForms * @param string $attribute * @param array $params */ public function validateMappingData($attribute, $params) { assert('$this->importRulesType != null'); assert('$this->mappingData != null'); $atLeastOneAttributeMappedOrHasRules = false; $attributeMappedOrHasRulesMoreThanOnce = false; $mappedAttributes = array(); $importRulesClassName = ImportRulesUtil::getImportRulesClassNameByType($this->importRulesType); foreach ($this->mappingData as $columnName => $data) { if ($data['attributeIndexOrDerivedType'] != null) { $atLeastOneAttributeMappedOrHasRules = true; if (in_array($data['attributeIndexOrDerivedType'], $mappedAttributes)) { $attributeMappedOrHasRulesMoreThanOnce = true; } else { $mappedAttributes[] = $data['attributeIndexOrDerivedType']; } } } if ($attributeMappedOrHasRulesMoreThanOnce) { $this->addError('mappingData', Zurmo::t('ImportModule', 'You can only map each field once.')); } if (!$atLeastOneAttributeMappedOrHasRules) { $this->addError('mappingData', Zurmo::t('ImportModule', 'You must map at least one of your import columns.')); } $mappedAttributeIndicesOrDerivedAttributeTypes = ImportMappingUtil::getMappedAttributeIndicesOrDerivedAttributeTypesByMappingData($this->mappingData); $requiredAttributeCollection = $importRulesClassName::getRequiredAttributesCollectionNotIncludingReadOnly(); $mappedAttributeImportRulesCollection = AttributeImportRulesFactory::makeCollection($this->importRulesType, $mappedAttributeIndicesOrDerivedAttributeTypes); if (!ImportRulesUtil::areAllRequiredAttributesMappedOrHaveRules($requiredAttributeCollection, $mappedAttributeImportRulesCollection)) { $attributesLabelContent = null; foreach ($requiredAttributeCollection as $noteUsed => $attributeData) { if ($attributesLabelContent != null) { $attributesLabelContent .= ', '; } $attributesLabelContent .= $attributeData['attributeLabel']; } $this->addError('mappingData', Zurmo::t('ImportModule', 'All required fields must be mapped or added: {attributesLabelContent}', array('{attributesLabelContent}' => $attributesLabelContent))); } try { ImportRulesUtil::checkIfAnyAttributesAreDoubleMapped($mappedAttributeImportRulesCollection); } catch (ImportAttributeMappedMoreThanOnceException $e) { $this->addError('mappingData', Zurmo::t('ImportModule', 'The following field is mapped more than once. {message}', array('{message}' => $e->getMessage()))); } }
protected static function resolveModelForAttributeIndexWithMultipleNonDerivedAttributes(RedBeanModel $model, AttributeImportRules $attributeImportRules, $valueReadyToSanitize, $columnName, $columnMappingData, ImportSanitizeResultsUtil $importSanitizeResultsUtil) { assert('is_string($columnName)'); assert('is_array($columnMappingData)'); if ($attributeImportRules->getModelClassName() == null) { throw new NotSupportedException(); } $attributeValueData = $attributeImportRules->resolveValueForImport($valueReadyToSanitize, $columnName, $columnMappingData, $importSanitizeResultsUtil); $attributeName = AttributeImportRulesFactory::getAttributeNameFromAttributeNameByAttributeIndexOrDerivedType($columnMappingData['attributeIndexOrDerivedType']); $relationModelClassName = $attributeImportRules->getModelClassName(); if ($model->{$attributeName} == null) { $model->{$attributeName} = new $relationModelClassName(); } elseif (!$model->{$attributeName} instanceof $relationModelClassName) { throw new NotSupportedException(); } foreach ($attributeValueData as $relationAttributeName => $value) { assert('$model->$attributeName->isAttribute($relationAttributeName)'); static::resolveReadOnlyAndSetValueToAttribute($model->{$attributeName}, $relationAttributeName, $value); } }
public function testGetExtraColumnUsableCountOfModelAttributeMappingRuleFormTypesAndElementTypes() { $attributeImportRules = AttributeImportRulesFactory::makeByImportRulesTypeAndAttributeIndexOrDerivedType('ImportModelTestItem', 'modifiedByUser'); $count = $attributeImportRules->getExtraColumnUsableCountOfModelAttributeMappingRuleFormTypesAndElementTypes(); $this->assertEquals(0, $count); $attributeImportRules = AttributeImportRulesFactory::makeByImportRulesTypeAndAttributeIndexOrDerivedType('ImportModelTestItem', 'dropDown'); $count = $attributeImportRules->getExtraColumnUsableCountOfModelAttributeMappingRuleFormTypesAndElementTypes(); $this->assertEquals(1, $count); }
/** * @param string $columnName * @param string $attributeIndexOrDerivedType * @param string $importRulesType * @param string $columnType * @param array $mappingRuleFormsAndElementTypes * @return string */ public function renderMappingRulesElements($columnName, $attributeIndexOrDerivedType, $importRulesType, $columnType, $mappingRuleFormsAndElementTypes) { assert('is_string($columnName)'); assert('is_string($attributeIndexOrDerivedType) || $attributeIndexOrDerivedType == null'); assert('is_string($importRulesType)'); assert('$columnType == "importColumn" || $columnType == "extraColumn"'); assert('is_array($mappingRuleFormsAndElementTypes) || $mappingRuleFormsAndElementTypes == null'); $content = null; $multipleMappingRulesCssClass = null; if ($attributeIndexOrDerivedType != null) { if ($mappingRuleFormsAndElementTypes == null) { $attributeImportRules = AttributeImportRulesFactory::makeByImportRulesTypeAndAttributeIndexOrDerivedType($importRulesType, $attributeIndexOrDerivedType); $mappingRuleFormsAndElementTypes = MappingRuleFormAndElementTypeUtil::makeCollectionByAttributeImportRules($attributeImportRules, $attributeIndexOrDerivedType, $columnType); } if (count($mappingRuleFormsAndElementTypes) > 0) { $title = Zurmo::t('ImportModule', 'Rules'); } else { $title = null; } $content .= ZurmoHtml::tag('h4', array(), $title); foreach ($mappingRuleFormsAndElementTypes as $notUsed => $ruleFormAndElementType) { $mappingRuleForm = $ruleFormAndElementType['mappingRuleForm']; $elementClassName = $ruleFormAndElementType['elementType'] . 'Element'; $classToEvaluate = new ReflectionClass($elementClassName); if ($classToEvaluate->implementsInterface('DerivedElementInterface')) { $attributeName = 'null'; } else { $attributeName = $mappingRuleForm::getAttributeName(); } $params = array(); $params['inputPrefix'] = array($this->mappingFormModelClassName, $columnName, 'mappingRulesData', get_class($mappingRuleForm)); $element = new $elementClassName($mappingRuleForm, $attributeName, $this->form, $params); $element->editableTemplate = '<div>{label}{content}{error}</div>'; $content .= $element->render(); } } $subDivsCssClass = 'has' . count($mappingRuleFormsAndElementTypes); $content = ZurmoHtml::tag('div', array('id' => self::getMappingRulesDivIdByColumnName($columnName), 'class' => 'mapping-rules ' . $subDivsCssClass), $content); // Not Coding Standard return $content; }
public function testCheckIfAnyAttributesAreDoubleMappedWhenTheyAreDobuleMapped() { Yii::app()->user->userModel = User::getByUsername('super'); $mappedAttributeImportRulesCollection = AttributeImportRulesFactory::makeCollection('ImportModelTestItem', array('boolean', 'string', 'FullName')); ImportRulesUtil::checkIfAnyAttributesAreDoubleMapped($mappedAttributeImportRulesCollection); //Now it should fail, because lastName is mapped both as a non-derived and within FullName $mappedAttributeImportRulesCollection = AttributeImportRulesFactory::makeCollection('ImportModelTestItem', array('boolean', 'lastName', 'FullName')); try { ImportRulesUtil::checkIfAnyAttributesAreDoubleMapped($mappedAttributeImportRulesCollection); $this->fail(); } catch (ImportAttributeMappedMoreThanOnceException $e) { } //This should not fail because $mappedAttributeImportRulesCollection = AttributeImportRulesFactory::makeCollection('ImportModelTestItem', array('primaryEmail__emailAddress', 'secondaryEmail__emailAddress')); ImportRulesUtil::checkIfAnyAttributesAreDoubleMapped($mappedAttributeImportRulesCollection); }
/** * Given a column name and column mapping data, perform data analysis on the column based on the mapped * attribute index or derived type. The attribute index or derived type will correspond with an attribute * import rules which will have information on what sanitizers to use. Based on this, the correct sanitizers * will be called and their appropriate analyzers will be used. * NOTE - Analysis is only performed on mapped import columns and not extra columns with mapping rules. * @param string $columnName * @param array $columnMappingData */ public function analyzeByColumnNameAndColumnMappingData($columnName, $columnMappingData) { assert('is_string($columnMappingData["attributeIndexOrDerivedType"]) || $columnMappingData["attributeIndexOrDerivedType"] == null'); assert('$columnMappingData["type"] == "importColumn" || $columnMappingData["type"] == "extraColumn"'); if ($columnMappingData['attributeIndexOrDerivedType'] == null) { return; } //Currently does not support data analysis on extra columns. if ($columnMappingData['type'] == 'extraColumn') { return; } $attributeImportRules = AttributeImportRulesFactory::makeByImportRulesTypeAndAttributeIndexOrDerivedType($this->importRules->getType(), $columnMappingData['attributeIndexOrDerivedType']); $modelClassName = $attributeImportRules->getModelClassName(); $attributeNames = $attributeImportRules->getRealModelAttributeNames(); if (count($attributeNames) > 1 || $attributeNames == null) { $dataAnalyzerAttributeName = null; } else { $dataAnalyzerAttributeName = $attributeNames[0]; } if (null != ($attributeValueSanitizerUtilTypes = $attributeImportRules->getSanitizerUtilTypesInProcessingOrder())) { assert('is_array($attributeValueSanitizerUtilTypes)'); foreach ($attributeValueSanitizerUtilTypes as $attributeValueSanitizerUtilType) { $attributeValueSanitizerUtilClassName = $attributeValueSanitizerUtilType . 'SanitizerUtil'; if ($attributeValueSanitizerUtilClassName::supportsSqlAttributeValuesDataAnalysis()) { $sanitizerUtilType = $attributeValueSanitizerUtilClassName::getType(); $sqlAttributeValuesDataAnalyzer = $attributeValueSanitizerUtilClassName::makeSqlAttributeValueDataAnalyzer($modelClassName, $dataAnalyzerAttributeName); assert('$sqlAttributeValuesDataAnalyzer != null'); $this->resolveRun($columnName, $columnMappingData, $attributeValueSanitizerUtilClassName, $sqlAttributeValuesDataAnalyzer); $messages = $sqlAttributeValuesDataAnalyzer->getMessages(); if ($messages != null) { foreach ($messages as $message) { $moreAvailable = $sqlAttributeValuesDataAnalyzer::supportsAdditionalResultInformation(); $this->addMessageDataByColumnName($columnName, $message, $sanitizerUtilType, $moreAvailable); } } $instructionsData = $sqlAttributeValuesDataAnalyzer->getInstructionsData(); if (!empty($instructionsData)) { $this->addInstructionDataByColumnName($columnName, $instructionsData, $sanitizerUtilType); } } elseif ($attributeValueSanitizerUtilClassName::supportsBatchAttributeValuesDataAnalysis()) { $sanitizerUtilType = $attributeValueSanitizerUtilClassName::getType(); $batchAttributeValuesDataAnalyzer = $attributeValueSanitizerUtilClassName::makeBatchAttributeValueDataAnalyzer($modelClassName, $dataAnalyzerAttributeName); assert('$batchAttributeValuesDataAnalyzer != null'); $this->resolveRun($columnName, $columnMappingData, $attributeValueSanitizerUtilClassName, $batchAttributeValuesDataAnalyzer); $messages = $batchAttributeValuesDataAnalyzer->getMessages(); if ($messages != null) { foreach ($messages as $message) { $moreAvailable = $batchAttributeValuesDataAnalyzer::supportsAdditionalResultInformation(); $this->addMessageDataByColumnName($columnName, $message, $sanitizerUtilType, $moreAvailable); } } $instructionsData = $batchAttributeValuesDataAnalyzer->getInstructionsData(); if (!empty($instructionsData)) { $this->addInstructionDataByColumnName($columnName, $instructionsData, $sanitizerUtilType); } } } } }
protected function processColumns($params) { $completionPosition = 1; if (!isset($params["columnNameToProcess"])) { $params["columnNameToProcess"] = $this->getNextMappedColumnName($this->mappingData); } else { assert('is_string($params["columnNameToProcess"])'); } $completionPosition = array_search($params["columnNameToProcess"], $this->sanitizableColumnNames) + 1; if ($completionPosition != count($this->sanitizableColumnNames)) { $completionPosition++; } $this->subSequenceCompletionPercentage = $completionPosition / count($this->sanitizableColumnNames) * 100; //Run data analyzer if ($this->mappingData[$params["columnNameToProcess"]]['attributeIndexOrDerivedType'] == null) { throw new NotSupportedException(); } $importDataAnalyzer = new ImportDataAnalyzer($this->importRules, $this->dataProvider); $importDataAnalyzer->analyzeByColumnNameAndColumnMappingData($params["columnNameToProcess"], $this->mappingData[$params["columnNameToProcess"]]); $messagesData = $importDataAnalyzer->getMessagesData(); $importInstructionsData = $importDataAnalyzer->getImportInstructionsData(); $unserializedData = unserialize($this->import->serializedData); $unserializedData['mappingData'] = ImportMappingUtil::resolveImportInstructionsDataIntoMappingData($this->mappingData, $importInstructionsData); $this->import->serializedData = serialize($unserializedData); ImportUtil::setDataAnalyzerMessagesDataToImport($this->import, $messagesData, true); $saved = $this->import->save(); if (!$saved) { throw new FailedToSaveModelException(); } $nextColumnName = $this->getNextMappedColumnName($this->mappingData, $params['columnNameToProcess']); if ($nextColumnName == null) { $this->nextStep = null; $this->nextMessage = null; $this->complete = true; return null; } else { $params['columnNameToProcess'] = $nextColumnName; $this->nextStep = 'processColumns'; $this->setNextMessageByStep($this->nextStep); $attributeImportRules = AttributeImportRulesFactory::makeByImportRulesTypeAndAttributeIndexOrDerivedType($this->importRules->getType(), $this->mappingData[$params["columnNameToProcess"]]['attributeIndexOrDerivedType']); $this->nextMessage .= ' ' . $attributeImportRules->getDisplayLabel(); return $params; } }
/** * * Make an array of index/values that are the column names and their respective labels. * @param array $mappingData * @param array $importRulesType */ public static function makeColumnNamesAndAttributeIndexOrDerivedTypeLabels($mappingData, $importRulesType) { assert('is_array($mappingData)'); assert('is_string($importRulesType)'); $columnNamesAndAttributeIndexOrDerivedTypeLabels = array(); foreach ($mappingData as $columnName => $columnData) { if ($columnData['attributeIndexOrDerivedType'] != null) { $attributeImportRules = AttributeImportRulesFactory::makeByImportRulesTypeAndAttributeIndexOrDerivedType($importRulesType, $columnData['attributeIndexOrDerivedType']); $columnNamesAndAttributeIndexOrDerivedTypeLabels[$columnName] = $attributeImportRules->getDisplayLabel(); } else { $columnNamesAndAttributeIndexOrDerivedTypeLabels[$columnName] = null; } } return $columnNamesAndAttributeIndexOrDerivedTypeLabels; }
/** * @param string $columnName * @param string $attributeIndexOrDerivedType * @param string $importRulesType * @param string $columnType * @param array $mappingRuleFormsAndElementTypes * @return string */ public function renderMappingRulesElements($columnName, $attributeIndexOrDerivedType, $importRulesType, $columnType, $mappingRuleFormsAndElementTypes) { assert('is_string($columnName)'); assert('is_string($attributeIndexOrDerivedType) || $attributeIndexOrDerivedType == null'); assert('is_string($importRulesType)'); assert('$columnType == "importColumn" || $columnType == "extraColumn"'); assert('is_array($mappingRuleFormsAndElementTypes) || $mappingRuleFormsAndElementTypes == null'); $content = null; $multipleMappingRulesCssClass = null; if ($attributeIndexOrDerivedType != null) { if ($mappingRuleFormsAndElementTypes == null) { $attributeImportRules = AttributeImportRulesFactory::makeByImportRulesTypeAndAttributeIndexOrDerivedType($importRulesType, $attributeIndexOrDerivedType); $mappingRuleFormsAndElementTypes = MappingRuleFormAndElementTypeUtil::makeCollectionByAttributeImportRules($attributeImportRules, $attributeIndexOrDerivedType, $columnType); } if (count($mappingRuleFormsAndElementTypes) > 0) { $title = Zurmo::t('ImportModule', 'Rules'); } else { $title = null; } $content .= ZurmoHtml::tag('h4', array(), $title); foreach ($mappingRuleFormsAndElementTypes as $notUsed => $ruleFormAndElementType) { $mappingRuleForm = $ruleFormAndElementType['mappingRuleForm']; $elementClassName = $ruleFormAndElementType['elementType'] . 'Element'; $classToEvaluate = new ReflectionClass($elementClassName); if ($classToEvaluate->implementsInterface('DerivedElementInterface')) { $attributeName = 'null'; } else { $attributeName = $mappingRuleForm::getAttributeName(); } $params = array(); $params['inputPrefix'] = array($this->mappingFormModelClassName, $columnName, 'mappingRulesData', get_class($mappingRuleForm)); $element = new $elementClassName($mappingRuleForm, $attributeName, $this->form, $params); $element->editableTemplate = '<div>{label}{content}{error}</div>'; // In case of TagCloud or MultiSelectDropbox inform user that in cas of updating existing model, original values will be overwritten. // Prepend this text before content, so it will appear before "Rules" title if ($element instanceof ImportMappingRuleDefaultMultiSelectDropDownFormElement) { $content = $this->resolveTextAboutOverwritingMultiselectOrTagCloudValues($columnName . $attributeIndexOrDerivedType) . $content; } $content .= $element->render(); } } $subDivsCssClass = 'has' . count($mappingRuleFormsAndElementTypes); $content = ZurmoHtml::tag('div', array('id' => self::getMappingRulesDivIdByColumnName($columnName), 'class' => 'mapping-rules ' . $subDivsCssClass), $content); // Not Coding Standard return $content; }
protected function resolveHeaderColumnContent($columnName, $label) { $content = static::resolveHeaderLabelByColumnNameAndLabel($columnName, $label); if ($this->mappingData[$columnName]['attributeIndexOrDerivedType'] != null) { $attributeIndexOrDerivedType = $this->mappingData[$columnName]['attributeIndexOrDerivedType']; $attributeImportRules = AttributeImportRulesFactory::makeByImportRulesTypeAndAttributeIndexOrDerivedType($this->importRulesType, $attributeIndexOrDerivedType); $content .= ZurmoHtml::tag('span', array('class' => 'icon-import-mapping'), '↓'); $content .= $attributeImportRules->getDisplayLabel(); } return $content; }
public function analyzePage() { $data = $this->dataProvider->getData(true); foreach ($data as $rowBean) { assert('$rowBean->id != null'); $columnMessages = array(); $shouldSkipRow = false; foreach ($this->sanitizableColumnNames as $columnName) { $attributeIndexOrDerivedType = $this->mappingData[$columnName]['attributeIndexOrDerivedType']; $attributeImportRules = AttributeImportRulesFactory::makeByImportRulesTypeAndAttributeIndexOrDerivedType($this->importRules->getType(), $attributeIndexOrDerivedType); $modelClassName = $attributeImportRules->getModelClassName(); $attributeName = static::resolveAttributeNameByRules($attributeImportRules); if (null != ($attributeValueSanitizerUtilTypes = $attributeImportRules->getSanitizerUtilTypesInProcessingOrder())) { assert('is_array($attributeValueSanitizerUtilTypes)'); foreach ($attributeValueSanitizerUtilTypes as $attributeValueSanitizerUtilType) { $sanitizer = ImportSanitizerUtilFactory::make($attributeValueSanitizerUtilType, $modelClassName, $attributeName, $columnName, $this->mappingData[$columnName]); $sanitizer->analyzeByRow($rowBean); if ($sanitizer->getShouldSkipRow()) { $shouldSkipRow = true; } foreach ($sanitizer->getAnalysisMessages() as $message) { $columnMessages[$columnName][] = $message; } $classToEvaluate = new ReflectionClass($sanitizer); if ($classToEvaluate->implementsInterface('ImportSanitizerHasCustomFieldValuesInterface')) { $missingCustomFieldValues = $sanitizer->getMissingCustomFieldValues(); $this->getCustomFieldsInstructionData()->addMissingValuesByColumnName($missingCustomFieldValues, $columnName); } } } } if (!empty($columnMessages)) { $rowBean->serializedAnalysisMessages = serialize($columnMessages); if ($shouldSkipRow) { $rowBean->analysisStatus = static::STATUS_SKIP; } else { $rowBean->analysisStatus = static::STATUS_WARN; } } else { $rowBean->serializedAnalysisMessages = null; $rowBean->analysisStatus = static::STATUS_CLEAN; } R::store($rowBean); } }
public function renderMappingRulesElements($columnName, $attributeIndexOrDerivedType, $importRulesType, $columnType, $mappingRuleFormsAndElementTypes) { assert('is_string($columnName)'); assert('is_string($attributeIndexOrDerivedType) || $attributeIndexOrDerivedType == null'); assert('is_string($importRulesType)'); assert('$columnType == "importColumn" || $columnType == "extraColumn"'); assert('is_array($mappingRuleFormsAndElementTypes) || $mappingRuleFormsAndElementTypes == null'); $content = '<div id="' . self::getMappingRulesDivIdByColumnName($columnName) . '" class="mapping-rules">'; if ($attributeIndexOrDerivedType != null) { if ($mappingRuleFormsAndElementTypes == null) { $attributeImportRules = AttributeImportRulesFactory::makeByImportRulesTypeAndAttributeIndexOrDerivedType($importRulesType, $attributeIndexOrDerivedType); $mappingRuleFormsAndElementTypes = MappingRuleFormAndElementTypeUtil::makeCollectionByAttributeImportRules($attributeImportRules, $attributeIndexOrDerivedType, $columnType); } foreach ($mappingRuleFormsAndElementTypes as $notUsed => $ruleFormAndElementType) { $mappingRuleForm = $ruleFormAndElementType['mappingRuleForm']; $elementClassName = $ruleFormAndElementType['elementType'] . 'Element'; $classToEvaluate = new ReflectionClass($elementClassName); if ($classToEvaluate->implementsInterface('DerivedElementInterface')) { $attributeName = 'null'; } else { $attributeName = $mappingRuleForm::getAttributeName(); } $params = array(); $params['inputPrefix'] = array($this->mappingFormModelClassName, $columnName, 'mappingRulesData', get_class($mappingRuleForm)); $element = new $elementClassName($mappingRuleForm, $attributeName, $this->form, $params); $content .= '<table><tbody><tr>'; $content .= $element->render(); $content .= '</tr></tbody></table>'; } } $content .= '</div>'; return $content; }