/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Work::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, 'user_id' => $this->user_id, 'image1' => $this->image1, 'image2' => $this->image2, 'date_created' => $this->date_created, 'date_deleted' => $this->date_deleted]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
public function chamdiem($params) { $query = Work::find()->indexBy('id'); $query->joinWith(['timesheet', 'process', 'team', 'user']); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['timesheet.status' => SORT_ASC, 'timesheet.date' => SORT_DESC], 'attributes' => ['work_time', 'work_name', 'comment', 'timesheet.date' => ['asc' => ['timesheet.date' => SORT_ASC], 'desc' => ['timesheet.date' => SORT_DESC]], 'process.process_name' => ['asc' => ['process.process_name' => SORT_ASC], 'desc' => ['process.process_name' => SORT_DESC]], 'team.team_name' => ['asc' => ['team.team_name' => SORT_ASC], 'desc' => ['team.team_name' => SORT_DESC]], 'timesheet.point' => ['asc' => ['timesheet.point' => SORT_ASC], 'desc' => ['timesheet.point' => SORT_DESC]], 'timesheet.director_comment' => ['asc' => ['timesheet.director_comment' => SORT_ASC], 'desc' => ['timesheet.director_comment' => SORT_DESC]], 'timesheet.status' => ['asc' => ['timesheet.status' => SORT_ASC], 'desc' => ['timesheet.status' => SORT_DESC]], 'user.full_name' => ['asc' => ['user.full_name' => SORT_ASC], 'desc' => ['user.full_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(['id' => $this->id, 'timesheet_id' => $this->timesheet_id, 'team_id' => $this->team_id, 'process_id' => $this->process_id, 'work_time' => $this->work_time, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'process.process_name', $this->getAttribute('process.process_name')])->andFilterWhere(['like', 'team.team_name', $this->getAttribute('team.team_name')])->andFilterWhere(['like', 'timesheet.date', $this->getAttribute('timesheet.date')])->andFilterWhere(['like', 'timesheet.point', $this->getAttribute('timesheet.point')])->andFilterWhere(['like', 'user.full_name', $this->getAttribute('user.full_name')]); return $dataProvider; }
/** * Updates an existing Timesheet model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $query = Work::find()->where(['timesheet_id' => $model->id]); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => false]); if (Yii::$app->request->post()) { $works = Yii::$app->request->post('Work'); foreach ($works as $work) { $new_work = Work::findOne($work['id']); $new_work->attributes = $work; $new_work->updated_at = time(); if ($new_work->update() === false) { return $this->render('update', ['model' => $model, 'dataProvider' => $dataProvider]); } } Yii::$app->session->setFlash('updateOK'); return $this->redirect('index.php?r=timesheet/view&id=' . $model->id); } return $this->render('update', ['model' => $model, 'dataProvider' => $dataProvider]); }