/** * Creates a new MeetingPlace model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($meeting_id) { $mtg = new Meeting(); $title = $mtg->getMeetingTitle($meeting_id); $model = new MeetingPlace(); $model->meeting_id = $meeting_id; $model->suggested_by = Yii::$app->user->getId(); $model->status = MeetingPlace::STATUS_SUGGESTED; $posted_form = Yii::$app->request->post(); if ($model->load($posted_form)) { // check if both are chosen and return an error if ($model->place_id != '' and $posted_form['MeetingPlace']['google_place_id'] != '') { $model->addErrors(['place_id' => Yii::t('frontend', 'Please choose one or the other')]); return $this->render('create', ['model' => $model, 'title' => $title]); } if ($posted_form['MeetingPlace']['google_place_id'] != '') { // a google place is selected // is google place already in the Place database? // or, can we create a new place for this Google Place $model->place_id = Place::googlePlaceSuggested($posted_form['MeetingPlace']); } // validate the form against model rules if ($model->validate()) { // all inputs are valid $model->save(); return $this->redirect(['/meeting/view', 'id' => $meeting_id]); } else { // validation failed return $this->render('create', ['model' => $model, 'title' => $title]); } } else { return $this->render('create', ['model' => $model, 'title' => $title]); } }