Ejemplo n.º 1
0
 /**
  * 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]);
     }
 }
Ejemplo n.º 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Place::find()->joinWith('user_place')->where(['user_id' => Yii::$app->user->getId()]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'place_type' => $this->place_type, 'status' => $this->status, 'created_by' => $this->created_by, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'google_place_id', $this->google_place_id])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'website', $this->website])->andFilterWhere(['like', 'full_address', $this->full_address])->andFilterWhere(['like', 'vicinity', $this->vicinity])->andFilterWhere(['like', 'notes', $this->notes]);
     return $dataProvider;
 }
Ejemplo n.º 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPlace()
 {
     return $this->hasOne(Place::className(), ['id' => 'place_id']);
 }
Ejemplo n.º 4
0
 public static function googlePlaceSuggested($form)
 {
     // check if this google place already exists
     if (Place::find()->where(['google_place_id' => $form['google_place_id']])->exists()) {
         $model = Place::find()->where(['google_place_id' => $form['google_place_id']])->one();
         return $model->id;
     } else {
         // otherwise register a new place
         $model = new Place();
         $model->name = $form['name'];
         $model->place_type = self::TYPE_OTHER;
         $model->google_place_id = $form['google_place_id'];
         $model->website = $form['website'];
         $model->vicinity = $form['vicinity'];
         $model->full_address = $form['full_address'];
         $model->created_by = Yii::$app->user->getId();
         if ($model->validate()) {
             // all inputs are valid
             $model->save();
             // add GPS entry in PlaceGeometry
             $model->addGeometry($model, $form['location']);
             return $model->id;
         } else {
             return false;
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Creates a new Place model via Geolocation
  */
 public function actionCreate_geo()
 {
     $model = new Place();
     if ($model->load(Yii::$app->request->post())) {
         $form = Yii::$app->request->post();
         $model->created_by = Yii::$app->user->getId();
         if (!is_numeric($model->place_type)) {
             $model->place_type = Place::TYPE_OTHER;
         }
         if ($model->validate()) {
             // all inputs are valid
             $model->save();
             // add GPS entry in PlaceGeometry
             $model->addGeometryByPoint($model, $form['Place']['lat'], $form['Place']['lng']);
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             // validation failed
             return $this->render('create_geo', ['model' => $model]);
         }
     } else {
         return $this->render('create_geo', ['model' => $model]);
     }
 }