/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { if (Yii::$app->user->can('admin')) { $query = WeekMon1::find()->joinWith('user.profile.region'); } else { $query = WeekMon1::find()->joinWith('user.profile.region')->where([Monitoring1::tableName() . '.user_id' => Yii::$app->user->id]); } $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->sort->attributes['region'] = ['asc' => [Region::tableName() . '.name' => SORT_ASC], 'desc' => [Region::tableName() . '.name' => SORT_DESC]]; $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(['user_id' => $this->user_id, WeekMon1::tableName() . '.startDate' => $this->startDate, Region::tableName() . '.id' => $this->region, WeekMon1::tableName() . '.status' => $this->status]); // $query->andFilterWhere(['like', 'date', $this->date]); return $dataProvider; }
/** * Finds the WeekMon1 model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return WeekMon1 the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = WeekMon1::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function getWeekMon1() { return $this->hasMany(WeekMon1::className(), ['user_id' => 'id']); }