/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Logbook::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' => Yii::$app->user->identity->id, 'create_date' => $this->create_date, 'create_time' => $this->create_time]); $query->andFilterWhere(['like', 'text', $this->text]); return $dataProvider; }
public function actionLogbooks() { $logbooks = null; if (isset($_POST['executer'])) { $executer = $_POST['executer']; $from = $_POST['from']; $to = $_POST['to']; // $logbooks = Logbook::find()->where([ // 'user_id' => $executer, // ]) // ->andWhere(['between', 'create_date', $from, $to]) // ->all(); $logbooks = Logbook::find()->where(['between', 'create_date', $from, $to]); if ($executer != '') { $logbooks = $logbooks->andWhere(['user_id' => $executer]); } $logbooks = $logbooks->all(); } else { $executer = ''; $from = date('Y-m-d', time()); $to = date('Y-m-d', time() + 86400); $logbooks = Logbook::find()->where(['create_date' => date('Y-m-d', time())])->all(); } return $this->render('logbooks', compact('logbooks', 'from', 'to', 'executer')); }