public function validateDoubleRoom($attribute, $params) { $validatequery = Trroomschedule::findOne(['date' => $this->date, 'RoomID' => $this->RoomID]); if ($validatequery) { $this->addError($attribute, 'This Room is already booked'); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Trroomschedule::find(); $query->joinWith(['patient', 'medicaladv', 'room']); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->sort->attributes['patient'] = ['asc' => ['mspatient.FirstName' => SORT_ASC], 'desc' => ['mspatient.FirstName' => SORT_DESC]]; $dataProvider->sort->attributes['medicaladv'] = ['asc' => ['msmedicaladv.FirstName' => SORT_ASC], 'desc' => ['msmedicaladv.FirstName' => SORT_DESC]]; $dataProvider->sort->attributes['room'] = ['asc' => ['msroom.RoomName' => SORT_ASC], 'desc' => ['msroom.RoomName' => SORT_DESC]]; if (!($this->load($params) && $this->validate())) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); $query->orderBy(['date' => SORT_DESC]); return $dataProvider; } $query->andFilterWhere(['RoomscheduleID' => $this->RoomscheduleID, 'date' => $this->date])->andFilterWhere(['like', 'msmedicaladv.FirstName', $this->medicaladv])->andFilterWhere(['like', 'mspatient.FirstName', $this->patient])->andFilterWhere(['like', 'msroom.RoomName', $this->room]); return $dataProvider; }
/** * Finds the Trroomschedule model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Trroomschedule the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Trroomschedule::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }