56 lines
1.3 KiB
PHP
56 lines
1.3 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace common\components\schema\models\search;
|
||
|
|
||
|
use yii\data\ActiveDataProvider;
|
||
|
use common\components\schema\models\Schema;
|
||
|
|
||
|
class SchemaSearch extends Schema
|
||
|
{
|
||
|
public function scenarios(): array
|
||
|
{
|
||
|
return Schema::scenarios();
|
||
|
}
|
||
|
|
||
|
public function rules(): array
|
||
|
{
|
||
|
return [
|
||
|
[['name', 'created_at'], 'string'],
|
||
|
[['name'], 'string', 'max' => 255],
|
||
|
];
|
||
|
}
|
||
|
|
||
|
public function search($params): ?ActiveDataProvider
|
||
|
{
|
||
|
$query = Schema::find();
|
||
|
|
||
|
$dataProvider = new ActiveDataProvider([
|
||
|
'query' => $query,
|
||
|
'sort' => [
|
||
|
'defaultOrder' => [
|
||
|
'created_at' => SORT_DESC,
|
||
|
'id' => SORT_DESC,
|
||
|
],
|
||
|
],
|
||
|
]);
|
||
|
|
||
|
$this->load($params);
|
||
|
|
||
|
if (!$this->validate()) {
|
||
|
return $dataProvider;
|
||
|
}
|
||
|
|
||
|
$query->andFilterWhere([
|
||
|
'like', 'name', $this->name,
|
||
|
]);
|
||
|
|
||
|
if ($this->created_at) {
|
||
|
$query->andFilterWhere([
|
||
|
'between', 'created_at', strtotime(date('d.m.Y', strtotime($this->created_at))), strtotime(date('d.m.Y', strtotime($this->created_at))) + 86400, // +1 days
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
return $dataProvider;
|
||
|
}
|
||
|
}
|