/**
  * Updates an existing TravellerHelp model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $descriptionmodel = TravellerDescription::find()->where(['traveller_id' => $model->traveller_id])->one();
     $profilemodel = TravellersProfile::find()->where(['traveller_id' => $model->traveller_id])->one();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         if (count($profilemodel) > 0) {
             return $this->redirect(['travellersprofile/update', 'id' => $profilemodel->id]);
         } else {
             return $this->redirect(['travellersprofile/create', 'traveller_id' => $model->traveller_id]);
         }
     } else {
         return $this->render('update', ['model' => $model, 'traveller_id' => $model->traveller_id, 'descriptionmodel' => $descriptionmodel, 'profilemodel' => $profilemodel]);
     }
 }
 /**
  * Lists all TravellerDescription models.
  * @return mixed
  */
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => TravellerDescription::find()]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }
 /**
  * Updates an existing TravellerPhoto model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $modelAttachments = Attachments::findOne($model->attachment_id);
     $uploadModel = new UploadImagesForm();
     $traveller_id = $model->traveller_id;
     $traveldescription = TravellerDescription::find()->where(['traveller_id' => $traveller_id])->one();
     if ($uploadModel->load(Yii::$app->request->post()) && $model->load(Yii::$app->request->post())) {
         $traveller = Travellers::findOne($traveller_id);
         if (isset($uploadModel->uploadFiles)) {
             $uploadImagePath = Yii::$app->basePath . "/../profiles/travellers/";
             $img = str_replace(' ', '+', str_replace('data:image/png;base64,', '', $uploadModel->uploadFiles));
             $data = base64_decode($img);
             $filename = uniqid() . '.png';
             $file = $uploadImagePath . $filename;
             if (!is_dir($uploadImagePath)) {
                 mkdir($uploadImagePath);
             }
             $success = file_put_contents($file, $data);
             if ($success) {
                 $orignalname = $filename;
                 $manupolated_name = md5(uniqid()) . '.png';
                 $modelAttachments = new Attachments();
                 $modelAttachments->user_id = $traveller->user_id;
                 $modelAttachments->orignal_name = $orignalname;
                 $modelAttachments->manupulated_name = $manupolated_name;
                 if ($modelAttachments->save()) {
                     $model->attachment_id = $modelAttachments->id;
                 }
             }
         }
         if ($model->save(false)) {
             if (count($traveldescription) > 0) {
                 return $this->redirect(['travellerdescription/update', 'id' => $traveldescription->id]);
             } else {
                 return $this->redirect(['travellerdescription/create', 'traveller_id' => $model->traveller_id]);
             }
         }
     } else {
         return $this->render('update', ['model' => $model, 'uploadModel' => $uploadModel, 'traveller_id' => $traveller_id, 'traveldescription' => $traveldescription, 'modelAttachments' => $modelAttachments]);
     }
 }