public function search($params)
{
$tableName = $this->tableName();
$activeDataProvider = new ActiveDataProvider(['query' => static::find()]);
if (!$this->load($params)) {
return $activeDataProvider;
}
/**
* @var $query ActiveQuery
*/
$query = $activeDataProvider->query;
//Standart
if ($columns = $this->getTableSchema()->columns) {
/**
* @var \yii\db\ColumnSchema $column
*/
foreach ($columns as $column) {
if ($column->phpType == "integer") {
$query->andFilterWhere([$this->tableName() . '.' . $column->name => $this->{$column->name}]);
} else {
if ($column->phpType == "string") {
$query->andFilterWhere(['like', $this->tableName() . '.' . $column->name, $this->{$column->name}]);
}
}
}
}
if ($this->created_at_from) {
$query->andFilterWhere(['>=', $this->tableName() . '.created_at', \Yii::$app->formatter->asTimestamp(strtotime($this->created_at_from))]);
}
if ($this->created_at_to) {
$query->andFilterWhere(['<=', $this->tableName() . '.created_at', \Yii::$app->formatter->asTimestamp(strtotime($this->created_at_to))]);
}
if ($this->updated_at_from) {
$query->andFilterWhere(['>=', $this->tableName() . '.updated_at', \Yii::$app->formatter->asTimestamp(strtotime($this->updated_at_from))]);
}
if ($this->updated_at_to) {
$query->andFilterWhere(['<=', $this->tableName() . '.created_at', \Yii::$app->formatter->asTimestamp(strtotime($this->updated_at_to))]);
}
if ($this->auth_at_from) {
$query->andFilterWhere(['>=', $this->tableName() . '.logged_at', \Yii::$app->formatter->asTimestamp(strtotime($this->auth_at_from))]);
}
if ($this->auth_at_to) {
$query->andFilterWhere(['<=', $this->tableName() . '.logged_at', \Yii::$app->formatter->asTimestamp(strtotime($this->auth_at_to))]);
}
if ($this->has_image) {
$query->andFilterWhere(['>', $this->tableName() . '.image_id', 0]);
}
if ($this->q) {
$query->andFilterWhere(['or', ['like', $this->tableName() . '.name', $this->q], ['like', $this->tableName() . '.email', $this->q], ['like', $this->tableName() . '.phone', $this->q], ['like', $this->tableName() . '.username', $this->q]]);
}
if ($this->role) {
$query->innerJoin('auth_assignment', 'auth_assignment.user_id = cms_user.id');
$query->andFilterWhere(['auth_assignment.item_name' => $this->role]);
}
return $activeDataProvider;
}