You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.7 KiB

6 years ago
<?php
/**
* Created by Error202
* Date: 04.06.2018
*/
namespace backend\forms;
use core\entities\Settings;
use yii\base\Model;
use yii\data\ActiveDataProvider;
class SettingsSearch extends Settings
{
3 years ago
public ?int $id = null;
public ?int $type = null;
public ?string $section = null;
public ?string $key = null;
public ?string $value = null;
public ?int $active = null;
3 years ago
public function rules(): array
{
return [
[['id'], 'integer'],
[['active'], 'boolean'],
[['type', 'section', 'key', 'value'], 'safe'],
];
}
/**
* @return array
*/
3 years ago
public function scenarios(): array
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
6 years ago
/**
* @param $params
*
* @return ActiveDataProvider
*/
3 years ago
public function search($params): ActiveDataProvider
{
$query = Settings::find();
$dataProvider = new ActiveDataProvider(
[
'query' => $query,
]
);
if (!($this->load($params) && $this->validate())) {
$query->andFilterWhere(
[
'section' => $this->section,
]
);
return $dataProvider;
}
$query->andFilterWhere(
[
'id' => $this->id,
'active' => $this->active,
'section' => $this->section,
]
);
$query->andFilterWhere(['like', 'key', $this->key])
->andFilterWhere(['like', 'value', $this->value]);
6 years ago
return $dataProvider;
}
}