/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Event::find(); // add conditions that should always apply here $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; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'calendar_id' => $this->calendar_id, 'project_id' => $this->project_id, 'sort_order' => $this->sort_order, 'status_id' => $this->status_id, 'old_id' => $this->old_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
public function actionCreateevent() { $request = \yii::$app->request; $bookingModel = new Booking(); $eventModel = new Event(); $eventEntryModel = new EventEntry(); $validate = false; $bookingModel->load($request->post()); if (yii::$app->CalendarComponent->canCreateEvents($bookingModel->calendar_id)) { $validate = true; } else { $bookingModel->addError('event_id', 'Cannot use this calendar. Double check the read only setting - '); } if ($validate && $bookingModel->validate()) { $eventModel->load(['Event' => $bookingModel->attributes]); if ($eventModel->validate()) { try { $transaction = \yii::$app->db->beginTransaction(); $eventModel->save(false); $eventEntryModel->load(['EventEntry' => $bookingModel->attributes]); $eventEntryModel->event_id = $eventModel->primaryKey; if ($eventEntryModel->validate()) { $eventEntryModel->save(false); yii::$app->AjaxResponse->error = false; } else { yii::$app->AjaxResponse->message = array_values($eventEntryModel->getErrors()); } $transaction->commit(); yii::$app->AjaxResponse->message = $bookingModel->jsObject; } catch (Exception $e) { $transaction->rollBack(); } } else { yii::$app->AjaxResponse->message = array_values($eventModel->getErrors()); } } else { yii::$app->AjaxResponse->message = array_values($bookingModel->getErrors()); } yii::$app->AjaxResponse->sendContent(); }
/** /** * @return \yii\db\ActiveQuery */ public function getEvents() { return $this->hasMany(Event::className(), ['calendar_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getEvent() { return $this->hasOne(Event::className(), ['id' => 'event_id']); }
/** * 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.'); } }