new-support.webeffector.ru/common/components/schema/models/search/SchemaSearch.php

56 lines
1.3 KiB
PHP
Raw Permalink Normal View History

2024-07-04 06:42:20 +03:00
<?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;
}
}