public function testGetAttributes() { $collection = array(); ModelAttributeImportMappingCollectionUtil::populateCollection($collection, 'abc', 'def', 'xyz', 'try', 'qqq', true); $compareData = array('abc' => array('attributeLabel' => 'def', 'attributeName' => 'xyz', 'relationAttributeName' => 'qqq', 'attributeImportRulesType' => 'try', 'isRequired' => true)); $this->assertEquals($compareData, $collection); }
/** * Returns HAS_ONE relation attributes * and non-relation attributes in an array * mapping attribute names to 'attributeLabel' to the * attribute label. Also returns 'isRequired' and 'isAudited' information. */ public function getAttributes() { $attributes = array(); ModelAttributeImportMappingCollectionUtil::populateCollection($attributes, 'id', $this->model->getAttributeLabel('id'), 'id', 'Id'); foreach ($this->model->getAttributes() as $attributeName => $notUsed) { if (!$this->model->isRelation($attributeName) || $this->isAttributeAnOwnedCustomFieldRelation($attributeName) || $this->isAttributeAnOwnedMultipleValuesCustomFieldRelation($attributeName) || $this->isAttributeAHasOneNotOwnedRelation($attributeName) || $this->isAttributeAHasOneOwnedRelationThatShouldBehaveAsNotOwnedRelation($attributeName)) { $type = ModelAttributeToMixedTypeUtil::getType($this->model, $attributeName); $resolvedType = static::resolveAttributeImportTypeByAttributeName($type, $attributeName); ModelAttributeImportMappingCollectionUtil::populateCollection($attributes, $attributeName, $this->model->getAttributeLabel($attributeName), $attributeName, $resolvedType, null, $this->model->isAttributeRequired($attributeName)); } elseif ($this->isAttributeAHasOneOwnedRelation($attributeName)) { foreach ($this->model->{$attributeName}->getAttributes() as $relationAttributeName => $notUsed) { if (!$this->model->{$attributeName}->isRelation($relationAttributeName)) { $attributeLabel = $this->model->getAttributeLabel($attributeName) . ' - ' . $this->model->{$attributeName}->getAttributeLabel($relationAttributeName); $type = ModelAttributeToMixedTypeUtil::getType($this->model->{$attributeName}, $relationAttributeName); $resolvedType = static::resolveAttributeImportTypeByAttributeName($type, $relationAttributeName); ModelAttributeImportMappingCollectionUtil::populateCollection($attributes, $attributeName . FormModelUtil::DELIMITER . $relationAttributeName, $attributeLabel, $attributeName, $resolvedType, $relationAttributeName, $this->model->{$attributeName}->isAttributeRequired($relationAttributeName)); } } } } return $attributes; }
/** * If there is any derived attribute with a real attribute required that is not yeat in * the attributesCollection, if populate the Collection with the date from the derived attribute * @param Array $attributesCollection */ protected static function resolveRequiredDerivedAttributesCollection(&$attributesCollection) { $modelClassName = static::getModelClassName(); $model = new $modelClassName(false); foreach (static::getDerivedAttributeTypes() as $derivedType) { $attributeImportRulesClassName = $derivedType . 'AttributeImportRules'; $attributeImportRules = new $attributeImportRulesClassName($model); assert('$attributeImportRules instanceof DerivedAttributeImportRules'); $displayLabel = $attributeImportRules->getDisplayLabel(); $realAttributes = $attributeImportRules->getRealModelAttributeNames(); foreach ($realAttributes as $realAttribute) { if (!in_array($realAttribute, array_keys($attributesCollection)) && $model->isAttributeRequired($realAttribute)) { ModelAttributeImportMappingCollectionUtil::populateCollection($attributesCollection, $realAttribute, $displayLabel, $realAttribute, $derivedType, null, true); } } } }