public function validateDoubleMedic($attribute, $params) { $validatequery = Trmaschedule::findOne(['Date' => $this->Date, 'MedicaladvID' => $this->MedicaladvID]); if ($validatequery && $validatequery->mascheduleID != $this->mascheduleID) { $this->addError($attribute, 'The Medical Advisor has another booking in the designated time.'); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Trmaschedule::find()->where(['status' => 1]); $query->joinWith(['patient', 'medicaladv']); $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]]; 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(['mascheduleID' => $this->mascheduleID, 'Date' => $this->Date])->andFilterWhere(['like', 'msmedicaladv.FirstName', $this->medicaladv])->andFilterWhere(['like', 'mspatient.FirstName', $this->patient]); return $dataProvider; }
/** * Finds the Trmaschedule model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Trmaschedule the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Trmaschedule::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }