public function handle(CreateBehaviorDO $do)
 {
     \DB::transaction(function () use($do) {
         $entity = new Model();
         $entity->attributeSet()->associate($this->loadAttributeSetById($do->attribute_set_id));
         $entity->representation()->associate($this->loadRepresentationEntity($do->representation_id));
         $entity->name = $do->name;
         $entity->label = $do->label;
         $entity->default_value = $do->default_value;
         $entity->max_values_count = $do->max_values_count;
         $entity->required_create = $do->required_create;
         $entity->required_order = $do->required_order;
         $entity->save();
         if (count($do->options)) {
             foreach ($do->options as $optionDO) {
                 $optionEntity = $this->optionEntity($optionDO);
                 $entity->options()->save($optionEntity);
                 foreach ($optionDO->values as $valueDO) {
                     $valueEntity = $this->valueEntity(AttributeOptionModel::OBJECT_TYPE, $valueDO);
                     $optionEntity->values()->save($valueEntity);
                 }
             }
             $entity->options()->save($optionEntity);
         }
         if (count($do->values)) {
             foreach ($do->values as $valueDO) {
                 $entity->objectValues()->save($this->valueEntity(Model::OBJECT_TYPE, $valueDO));
             }
         }
     });
 }
Beispiel #2
0
 public function build(Model $entity = null)
 {
     $do = new DataObject();
     if ($entity) {
         $entityData = $entity->toArray();
         $entityData['representation'] = $this->representationBuilder->build($entity->representation);
         $entityData['representation_id'] = $entityData['attribute_representation_id'];
         $entityData['edit_url'] = $this->generateEntityUrl($entity);
         if (count($entity->values)) {
             $entityData['values'] = $this->objectValueBuilder->buildThem($entity->values);
         }
         if (count($entity->options)) {
             $entityData['options'] = $this->attributeOptionBuilder->buildThem($entity->options);
         }
         $do->update($entityData);
     }
     return $do;
 }