public function search($params, $query = null)
{
$query = $query ? $query : $this->find();
$dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
// load the search form data and validate
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
// adjust the query by adding the filters
$userId = $this->user_id;
if (strlen($this->user_id)) {
$userId = intval($this->user_id) ?: 0;
}
$query->andFilterWhere(['id' => $this->id]);
$query->andFilterWhere(['entry_id' => $this->entry_id]);
$query->andFilterWhere(['user_id' => $userId]);
$query->andFilterWhere(['action' => $this->action]);
$query->andFilterWhere(['like', 'model', $this->model]);
$query->andFilterWhere(['model_id' => $this->model_id]);
if (is_array($this->field)) {
$query->andFilterWhere(['in', 'field', $this->field]);
} else {
$query->andFilterWhere(['field' => $this->field]);
}
$query->andFilterWhere(['like', 'created', $this->created]);
return $dataProvider;
}