/**
  * Updates an existing EventPost 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);
     $event = Event::findOne($model->event_id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     } else {
         return $this->render('update', ['model' => $model, 'event' => $event]);
     }
 }
Example #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Event::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'start_date' => $this->start_date, 'end_date' => $this->end_date, 'visibility' => $this->visibility, 'region_id' => $this->region_id, 'genre_id' => $this->genre_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'location', $this->location])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'notes', $this->notes])->andFilterWhere(['like', 'image', $this->image]);
     return $dataProvider;
 }
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getEvents()
 {
     return $this->hasMany(Event::className(), ['region_id' => 'id']);
 }
Example #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getEvent()
 {
     return $this->hasOne(Event::className(), ['id' => 'event_id']);
 }
Example #5
0
 public function actionGetEventDetail()
 {
     $event = Event::findOne(Yii::$app->request->post('id'));
     if ($event) {
         return json_encode(['success' => true, 'data' => ['user' => $event->user->attributes, 'location' => $event->location, 'title' => $event->title, 'start_date' => $event->start_date, 'end_date' => $event->end_date, 'url' => $event->url, 'notes' => $event->notes, 'image' => $event->image, 'region' => $event->region->name, 'genre' => $event->genre->name]]);
     } else {
         return json_encode(['success' => false, 'data' => 'Event not found.']);
     }
 }
 /**
  * Finds the Event model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Event the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Event::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }