Esempio n. 1
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPresentationObjectPropertyValues()
 {
     return $this->hasMany(PresentationObjectPropertyValues::className(), ['id' => 'property_value_id']);
 }
 protected function savePresentationObjectProperties($model, $user, $service, $model_object_properties)
 {
     if ($model and $user and $service and $model_object_properties) {
         $model->imageFiles = UploadedFile::getInstances($model, 'imageFiles');
         if ($model->save()) {
             // Presentation Object Properties
             if ($model_object_properties) {
                 if ($model->provider_presentation_object_properties && $model->provider_presentation_object_properties != '') {
                     $existPres = $this->findModel($model->provider_presentation_object_properties);
                     if ($existPresentationObjectProperties = $existPres->presentationObjectProperties) {
                         foreach ($existPresentationObjectProperties as $existPresentationObjectProperty) {
                             $model_object_property = new PresentationObjectProperties();
                             $model_object_property->presentation_id = $model->id;
                             $model_object_property->spec_id = $existPresentationObjectProperty->spec_id;
                             $model_object_property->value = $existPresentationObjectProperty->value;
                             $model_object_property->value_max = $existPresentationObjectProperty->value_max;
                             $model_object_property->value_operator = $existPresentationObjectProperty->value_operator;
                             $model_object_property->multiple_values = $existPresentationObjectProperty->multiple_values;
                             $model_object_property->read_only = $existPresentationObjectProperty->read_only;
                             $model_object_property->save();
                             if ($existPresentationObjectPropertyValues = $existPresentationObjectProperty->presentationObjectPropertyValues) {
                                 foreach ($existPresentationObjectPropertyValues as $key => $existPresentationObjectPropertyValue) {
                                     $model_object_property_value[$key] = new PresentationObjectPropertyValues();
                                     $model_object_property_value[$key]->presentation_object_property_id = $model_object_property->id;
                                     $model_object_property_value[$key]->property_value_id = $existPresentationObjectPropertyValue->property_value_id;
                                     $model_object_property_value[$key]->save();
                                 }
                             }
                         }
                     }
                 } else {
                     if (Model::loadMultiple($model_object_properties, Yii::$app->request->post())) {
                         foreach ($model_object_properties as $model_object_property) {
                             $model_object_property->presentation_id = $model->id;
                             $model_object_property->multiple_values = $model_object_property['objectPropertyValues'] != null ? 1 : 0;
                             if ($model_object_property->save()) {
                                 if ($model_object_property['objectPropertyValues'] != null) {
                                     if (is_array($model_object_property['objectPropertyValues'])) {
                                         foreach ($model_object_property['objectPropertyValues'] as $key => $spec_model) {
                                             $model_object_property_value[$key] = new PresentationObjectPropertyValues();
                                             $model_object_property_value[$key]->presentation_object_property_id = $model_object_property->id;
                                             $model_object_property_value[$key]->property_value_id = $spec_model;
                                             $model_object_property_value[$key]->save();
                                         }
                                     } else {
                                         $model_object_property_value = new PresentationObjectPropertyValues();
                                         $model_object_property_value->presentation_object_property_id = $model_object_property->id;
                                         $model_object_property_value->property_value_id = $model_object_property['objectPropertyValues'];
                                         $model_object_property_value->save();
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             // Presentation Files
             if ($model->provider_presentation_pics && $model->provider_presentation_pics != '') {
                 $existPres = $this->findModel($model->provider_presentation_pics);
                 if ($existPresImages = $existPres->images) {
                     foreach ($existPresImages as $existPresImage) {
                         $new_image = new PresentationFiles();
                         $new_image->presentation_id = $model->id;
                         $new_image->file_id = $existPresImage->file_id;
                         $new_image->save();
                     }
                 }
             } else {
                 if ($model->imageFiles) {
                     $model->upload();
                 }
             }
             // Presentation Issues
             if ($model->issues) {
                 foreach ($model->issues as $issue) {
                     $model_issue = new PresentationIssues();
                     $model_issue->presentation_id = $model->id;
                     $model_issue->issue = $issue;
                     $model_issue->save();
                 }
             }
             return true;
         } else {
             echo '<pre>';
             print_r($model);
             die;
         }
     }
     return false;
 }
Esempio n. 3
0
 public function getPresentationObjectPropertyValues()
 {
     return $this->hasMany(PresentationObjectPropertyValues::className(), ['presentation_object_property_id' => 'id'])->viaTable('presentation_object_properties', ['presentation_id' => 'id']);
 }