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) { $modelClassName = get_class($this->model); $attributeName = $attributeForm->attributeName; $attributeLabels = $attributeForm->attributeLabels; $elementType = $attributeForm->getAttributeTypeName(); $isRequired = (bool) $attributeForm->isRequired; $isAudited = (bool) $attributeForm->isAudited; $contactStatesData = $attributeForm->contactStatesData; $contactStatesLabels = $attributeForm->contactStatesLabels; $startingStateOrder = (int) $attributeForm->startingStateOrder; $contactStatesDataExistingValues = $attributeForm->contactStatesDataExistingValues; if ($contactStatesDataExistingValues == null) { $contactStatesDataExistingValues = array(); } if ($attributeForm instanceof ContactStateAttributeForm) { //update order on existing states. //delete removed states $states = ContactState::getAll('order'); $stateNames = array(); foreach ($states as $state) { if (in_array($state->name, $contactStatesDataExistingValues)) { //todo: just don't match up the swap $order = array_search($state->name, $contactStatesDataExistingValues); $state->name = $contactStatesData[$order]; $state->order = $order; $state->serializedLabels = $this->makeSerializedLabelsByLabelsAndOrder($contactStatesLabels, (int) $state->order); $saved = $state->save(); assert('$saved'); $stateNames[] = $state->name; } elseif (in_array($state->name, $contactStatesData)) { $stateNames[] = $state->name; $state->order = array_search($state->name, $contactStatesData); $state->serializedLabels = $this->makeSerializedLabelsByLabelsAndOrder($contactStatesLabels, (int) $state->order); $saved = $state->save(); assert('$saved'); } else { $stateNames[] = $state->name; $state->delete(); } } //add new states with correct order. foreach ($contactStatesData as $order => $name) { if (!in_array($name, $stateNames)) { $state = new ContactState(); $state->name = $name; $state->order = $order; $state->serializedLabels = $this->makeSerializedLabelsByLabelsAndOrder($contactStatesLabels, (int) $order); $saved = $state->save(); assert('$saved'); } } //Set starting state by order. ContactsUtil::setStartingStateByOrder($startingStateOrder); ModelMetadataUtil::addOrUpdateRelation($modelClassName, $attributeName, $attributeLabels, $elementType, $isRequired, $isAudited, 'ContactState'); } else { throw new NotSupportedException(); } }
public function setAttributeMetadataFromForm(AttributeForm $attributeForm) { assert('$attributeForm instanceof CurrencyValueAttributeForm'); $modelClassName = get_class($this->model); $attributeName = $attributeForm->attributeName; $attributeLabels = $attributeForm->attributeLabels; $elementType = $attributeForm->getAttributeTypeName(); $isRequired = (bool) $attributeForm->isRequired; $isAudited = (bool) $attributeForm->isAudited; ModelMetadataUtil::addOrUpdateRelation($modelClassName, $attributeName, $attributeLabels, $elementType, $isRequired, $isAudited, 'CurrencyValue'); $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) { assert('$attributeForm instanceof DropDownDependencyAttributeForm'); $modelClassName = get_class($this->model); $attributeName = $attributeForm->attributeName; $attributeLabels = $attributeForm->attributeLabels; $elementType = $attributeForm->getAttributeTypeName(); $mappingData = $attributeForm->mappingData; $id = $attributeForm->id; if ($id != null) { $metadata = DropDownDependencyDerivedAttributeMetadata::getById($id); $metadata->setScenario('nonAutoBuild'); } else { $metadata = new DropDownDependencyDerivedAttributeMetadata(); $metadata->setScenario('nonAutoBuild'); } $metadata->name = $attributeName; $metadata->modelClassName = $modelClassName; $metadata->serializedMetadata = serialize(array('mappingData' => $mappingData, 'attributeLabels' => $attributeLabels)); $saved = $metadata->save(); if (!$saved) { throw new NotSupportedException(); } }
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(); } }