public function excel($params) { $query = Mon1str::find()->joinWith('monitoring1.user.profile.region'); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => array('pageSize' => 10000)]); $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([Monitoring1::tableName() . '.date' => $this->date, Region::tableName() . '.id' => $this->region]); return $dataProvider; }
/** * Finds the Mon1str model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Mon1str the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Mon1str::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function getMon1str() { return $this->hasMany(Mon1str::className(), ['monitoring1_id' => 'id']); }
public function actionDelete($id) { $model = $this->findModel($id); Mon1str::deleteAll(['monitoring1_id' => $id]); if (!Yii::$app->user->can('admin')) { if ($model->user_id != Yii::$app->user->id) { $this->redirect(['index']); } } if (Yii::$app->user->can('admin') || $model->status == 0) { $model->delete(); } return $this->redirect(['index']); }