/**
  * 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]);
     }
 }
 /**
  * Finds the TravellerDescription model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return TravellerDescription the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = TravellerDescription::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * 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]);
     }
 }