Esempio n. 1
0
 public function testGetMappedAttributeIndicesOrDerivedAttributeTypesByMappingData()
 {
     $mappingData = array('column_0' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => 'a', 'mappingRulesData' => null), 'column_1' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => 'b', 'mappingRulesData' => null), 'column_2' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => 'c', 'mappingRulesData' => null));
     $data = ImportMappingUtil::getMappedAttributeIndicesOrDerivedAttributeTypesByMappingData($mappingData);
     $this->assertEquals(array('a', 'b', 'c'), $data);
     $mappingData = array('column_0' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => null, 'mappingRulesData' => null));
     $data = ImportMappingUtil::getMappedAttributeIndicesOrDerivedAttributeTypesByMappingData($mappingData);
     $this->assertNull($data);
 }
Esempio n. 2
0
 /**
  * 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())));
     }
 }