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);
 }
Пример #2
0
 /**
  * Override needed to translate defaultValue to the order.  Order corresponds to the keyed index of the
  * customFieldDataData array.  This is needed for the form to operate correctly in the user interface.
  * Otherwise if you select a default as a new pick list item, the user interface has no way of posting
  * the correct Id for the defaultValue since the new pick list item has not been created yet.
  * Also need override to properly adapt pick list items.
  */
 public function __construct(RedBeanModel $model = null, $attributeName = null)
 {
     parent::__construct($model, $attributeName);
     if ($model !== null) {
         $this->customFieldDataName = $model->{$attributeName}->data->name;
         $this->customFieldDataId = $model->{$attributeName}->data->id;
         $this->customFieldDataData = unserialize($model->{$attributeName}->data->serializedData);
         if ($model->{$attributeName}->data->serializedLabels !== null) {
             $this->customFieldDataLabels = unserialize($model->{$attributeName}->data->serializedLabels);
         }
         $this->defaultValueOrder = DropDownDefaultValueOrderUtil::getDefaultValueOrderFromDefaultValue($this->defaultValue, $this->customFieldDataData);
     }
 }
 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);
 }