/**
  * Updates an existing TravellersCountries model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $traveller = \frontend\models\Travellers::findOne($id);
     $model = new TravellersCountries();
     $model->travelled_country = Yii::$app->commoncomponent->getCountriesArray($traveller->travelledCountries);
     $model->lived_country = Yii::$app->commoncomponent->getCountriesArray($traveller->livedCountries);
     $model->favourite_country = Yii::$app->commoncomponent->getCountriesArray($traveller->favouriteCountries);
     $Countries = Yii::$app->commoncomponent->getAllCountriesArray();
     $TravellersBestThing = TravellersBestThing::find()->where(['traveller_id' => $id])->one();
     if ($model->load(Yii::$app->request->post())) {
         Yii::$app->commoncomponent->deleteTravellerCountries($id);
         Yii::$app->commoncomponent->saveTravellerCountries($model->travelled_country, $id, 'travelled_country');
         Yii::$app->commoncomponent->saveTravellerCountries($model->lived_country, $id, 'lived_country');
         Yii::$app->commoncomponent->saveTravellerCountries($model->favourite_country, $id, 'favourite_country');
         return $this->redirect(['travellers/imagegallery', 'id' => $model->traveller_id]);
     } else {
         return $this->render('update', ['model' => $model, 'traveller_id' => $id, 'TravellersBestThing' => $TravellersBestThing, 'Countries' => $Countries]);
     }
 }
 /**
  * Updates an existing TravellersLanguages model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $traveller = \frontend\models\Travellers::findOne($id);
     $model = new TravellersLanguages();
     $model->mother_language = Yii::$app->commoncomponent->getLanguagesArray($traveller->motherLanguages);
     $model->fluent_language = Yii::$app->commoncomponent->getLanguagesArray($traveller->fluentLanguages);
     $model->learning_language = Yii::$app->commoncomponent->getLanguagesArray($traveller->learningLanguages);
     $Languages = Yii::$app->commoncomponent->getAllLanguagesArray();
     $travellerprofile = TravellersProfile::find()->where(['traveller_id' => $id])->one();
     $travellerfood = TravellersFood::find()->where(['traveller_id' => $id])->one();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->commoncomponent->deleteTravellerLanguages($id);
         Yii::$app->commoncomponent->saveTravellerLanguages($model->mother_language, $id, 'mother_language');
         Yii::$app->commoncomponent->saveTravellerLanguages($model->fluent_language, $id, 'fluent');
         Yii::$app->commoncomponent->saveTravellerLanguages($model->learning_language, $id, 'learning');
         if (count($travellerfood) > 0) {
             return $this->redirect(['travellersfood/update', 'id' => $travellerfood->id]);
         } else {
             return $this->redirect(['travellersfood/create', 'traveller_id' => $traveller_id]);
         }
     } else {
         return $this->render('update', ['model' => $model, 'traveller_id' => $id, 'travellerprofile' => $travellerprofile, 'Languages' => $Languages, 'travellerfood' => $travellerfood]);
     }
 }
 /**
  * Finds the Travellers model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Travellers the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Travellers::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]);
     }
 }