public function setAttributeMetadataFromForm(AttributeForm $attributeForm) { assert('$attributeForm instanceof MultiSelectDropDownAttributeForm'); $modelClassName = get_class($this->model); $attributeName = $attributeForm->attributeName; $attributeLabels = $attributeForm->attributeLabels; $defaultValueOrder = $attributeForm->defaultValueOrder; $elementType = $attributeForm->getAttributeTypeName(); $partialTypeRule = $attributeForm->getModelAttributePartialRule(); $isRequired = (bool) $attributeForm->isRequired; $isAudited = (bool) $attributeForm->isAudited; $customFieldDataName = $attributeForm->customFieldDataName; if ($customFieldDataName == null) { $customFieldDataName = ucfirst(strtolower($attributeForm->attributeName)); //should we do something else instead? } $customFieldDataData = $attributeForm->customFieldDataData; $customFieldDataLabels = $attributeForm->customFieldDataLabels; $defaultValue = DropDownDefaultValueOrderUtil::getDefaultValueFromDefaultValueOrder($defaultValueOrder, $customFieldDataData); ModelMetadataUtil::addOrUpdateCustomFieldRelation($modelClassName, $attributeName, $attributeLabels, $defaultValue, $isRequired, $isAudited, $elementType, $customFieldDataName, $customFieldDataData, $customFieldDataLabels, 'OwnedMultipleValuesCustomField'); if ($attributeForm->getCustomFieldDataId() != null) { foreach ($attributeForm->customFieldDataData as $order => $newValue) { if (isset($attributeForm->customFieldDataDataExistingValues[$order]) && $attributeForm->customFieldDataDataExistingValues[$order] != $newValue) { MultipleValuesCustomField::updateValueByDataIdAndOldValueAndNewValue($attributeForm->getCustomFieldDataId(), $attributeForm->customFieldDataDataExistingValues[$order], $newValue); } } } $this->resolveDatabaseSchemaForModel($modelClassName); }
public function setAttributeMetadataFromForm(AttributeForm $attributeForm) { assert('$attributeForm instanceof DateTimeAttributeForm || $attributeForm instanceof DateAttributeForm'); $modelClassName = get_class($this->model); $attributeName = $attributeForm->attributeName; $attributeLabels = $attributeForm->attributeLabels; $elementType = $attributeForm->getAttributeTypeName(); $partialTypeRule = $attributeForm->getModelAttributePartialRule(); $defaultValueCalculationType = $attributeForm->defaultValueCalculationType; $isRequired = (bool) $attributeForm->isRequired; $isAudited = (bool) $attributeForm->isAudited; $mixedRule = array('dateTimeDefault', 'value' => $defaultValueCalculationType); ModelMetadataUtil::addOrUpdateMember($modelClassName, $attributeName, $attributeLabels, null, null, null, null, null, $isRequired, $isAudited, $elementType, $partialTypeRule, $mixedRule); $this->resolveDatabaseSchemaForModel($modelClassName); }
public function setAttributeMetadataFromForm(AttributeForm $attributeForm) { assert('$attributeForm instanceof DropDownAttributeForm'); $modelClassName = get_class($this->model); $attributeName = $attributeForm->attributeName; $attributeLabels = $attributeForm->attributeLabels; $defaultValueOrder = $attributeForm->defaultValueOrder; $elementType = $attributeForm->getAttributeTypeName(); $partialTypeRule = $attributeForm->getModelAttributePartialRule(); $isRequired = (bool) $attributeForm->isRequired; $isAudited = (bool) $attributeForm->isAudited; $customFieldDataName = $attributeForm->customFieldDataName; if ($customFieldDataName == null) { $customFieldDataName = ucfirst(strtolower($attributeForm->attributeName)); //should we do something else instead? } $customFieldDataData = $attributeForm->customFieldDataData; $customFieldDataLabels = $attributeForm->customFieldDataLabels; $defaultValue = DropDownDefaultValueOrderUtil::getDefaultValueFromDefaultValueOrder($defaultValueOrder, $customFieldDataData); ModelMetadataUtil::addOrUpdateCustomFieldRelation($modelClassName, $attributeName, $attributeLabels, $defaultValue, $isRequired, $isAudited, $elementType, $customFieldDataName, $customFieldDataData, $customFieldDataLabels); if ($attributeForm->getCustomFieldDataId() != null) { $oldAndNewValuePairs = array(); foreach ($attributeForm->customFieldDataData as $order => $newValue) { if (isset($attributeForm->customFieldDataDataExistingValues[$order]) && $attributeForm->customFieldDataDataExistingValues[$order] != $newValue) { CustomField::updateValueByDataIdAndOldValueAndNewValue($attributeForm->getCustomFieldDataId(), $attributeForm->customFieldDataDataExistingValues[$order], $newValue); $oldValue = $attributeForm->customFieldDataDataExistingValues[$order]; $oldAndNewValuePairs[$oldValue] = $newValue; } } if (count($oldAndNewValuePairs) > 0) { DropDownDependencyDerivedAttributeDesignerUtil::updateValueInMappingByOldAndNewValue($modelClassName, $attributeName, $oldAndNewValuePairs, $attributeForm->customFieldDataDataExistingValues[$order], $newValue); } DropDownDependencyDerivedAttributeDesignerUtil::resolveValuesInMappingWhenValueWasRemoved($modelClassName, $attributeName, $attributeForm->customFieldDataData); } $this->resolveDatabaseSchemaForModel($modelClassName); }
public function setAttributeMetadataFromForm(AttributeForm $attributeForm) { $modelClassName = get_class($this->model); $attributeName = $attributeForm->attributeName; $attributeLabels = $attributeForm->attributeLabels; $defaultValue = $attributeForm->defaultValue; $elementType = $attributeForm->getAttributeTypeName(); $partialTypeRule = $attributeForm->getModelAttributePartialRule(); //should we keep this here with (boolean)? $isRequired = (bool) $attributeForm->isRequired; $isAudited = (bool) $attributeForm->isAudited; if (!$attributeForm instanceof DropDownAttributeForm) { if ($defaultValue === '') { $defaultValue = null; } if ($attributeForm instanceof MaxLengthAttributeForm) { if ($attributeForm->maxLength != null) { $maxLength = (int) $attributeForm->maxLength; } else { $maxLength = null; } } else { $maxLength = null; } if ($attributeForm instanceof MinMaxValueAttributeForm) { if ($attributeForm->minValue != null) { $minValue = (int) $attributeForm->minValue; } else { $minValue = null; } if ($attributeForm->maxValue != null) { $maxValue = (int) $attributeForm->maxValue; } else { $maxValue = null; } } else { $minValue = null; $maxValue = null; } if ($attributeForm instanceof DecimalAttributeForm) { $precision = (int) $attributeForm->precisionLength; } else { $precision = null; } ModelMetadataUtil::addOrUpdateMember($modelClassName, $attributeName, $attributeLabels, $defaultValue, $maxLength, $minValue, $maxValue, $precision, $isRequired, $isAudited, $elementType, $partialTypeRule); $this->resolveDatabaseSchemaForModel($modelClassName); } else { throw new NotSupportedException(); } }