/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = TrainUsers::find();
     $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;
     }
     $query->andFilterWhere(['id' => $this->id, 'train_id' => $this->train_id, 'user_id' => $this->user_id, 'status' => $this->status, 'practice_score' => $this->practice_score, 'theory_score' => $this->theory_score, 'rule_score' => $this->rule_score, 'create_time' => $this->create_time, 'update_time' => $this->update_time]);
     $query->andFilterWhere(['like', 'score_appraise', $this->score_appraise])->andFilterWhere(['like', 'attendance_appraise', $this->attendance_appraise])->andFilterWhere(['like', 'practice_comment', $this->practice_comment])->andFilterWhere(['like', 'theory_comment', $this->theory_comment])->andFilterWhere(['like', 'rule_comment', $this->rule_comment])->andFilterWhere(['like', 'total_comment', $this->total_comment])->andFilterWhere(['like', 'result_comment', $this->result_comment])->andFilterWhere(['like', 'create_user', $this->create_user])->andFilterWhere(['like', 'update_user', $this->update_user])->andFilterWhere(['<>', 'status', TrainUsers::CANCEL]);
     $query->orderBy(' id desc ');
     return $dataProvider;
 }
Exemplo n.º 2
0
 public function actionIndex()
 {
     $levelId = \Yii::$app->request->get('levelId') ? \Yii::$app->request->get('levelId') : 2;
     $orderBy = \Yii::$app->request->get('order_by') ? \Yii::$app->request->get('order_by') : '`begin_time` desc';
     $query = Train::find()->where(['level_id' => $levelId]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => '10']);
     $models = $query->offset($pages->offset)->limit($pages->limit)->orderBy($orderBy)->all();
     if (!empty($models)) {
         foreach ($models as $key => $val) {
             $val->begin_time = date('Y-m-d', strtotime($val->begin_time));
             //录取人数
             $countResult = \app\models\TrainUsers::find()->where(['train_id' => $val->id, 'status' => [TrainUsers::ENROLL, TrainUsers::DOING, TrainUsers::END, TrainUsers::PASS, TrainUsers::NO_PASS]]);
             $val->already_recruit_count = $countResult->count();
         }
     }
     return $this->render('index', ['models' => $models, 'pages' => $pages, 'levelId' => $levelId, 'orderBy' => $orderBy]);
 }