Article.php
3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
namespace backend\modules\calendar\models\search;
use Yii;
use yii\data\ActiveDataProvider;
use yii\base\Model;
//
use thread\app\base\models\query\ActiveQuery;
use thread\app\model\interfaces\search\BaseBackendSearchModel;
//
use backend\modules\calendar\Calendar as ParentModule;
use backend\modules\calendar\models\{
Article as ParentModel, ArticleLang as ParentLang
};
/**
* Class Article
*
* @package backend\modules\calendar\models\search
* @author FilamentV <vortex.filament@gmail.com>
* @copyright (c), Thread
*/
class Article extends ParentModel implements BaseBackendSearchModel
{
public $title, $date_from, $date_to;
/**
* @return array
*/
public function rules()
{
$getFormatDate = Yii::$app->getModule('calendar')->getFormatDate();
return [
[['alias', 'title'], 'string', 'max' => 255],
[['published'], 'in', 'range' => array_keys(self::statusKeyRange())],
[['group_id'], 'integer'],
[
['published_time'],
'date',
'format' => 'php:' . $getFormatDate,
'timestampAttribute' => 'published_time'
],
[
['date_from'],
'date',
'format' => 'php:' . $getFormatDate,
'timestampAttribute' => 'date_from'
],
[
['date_to'],
'date',
'format' => 'php:' . $getFormatDate,
'timestampAttribute' => 'date_to'
],
];
}
/**
*
* @return array
*/
public function scenarios()
{
return Model::scenarios();
}
/**
* @param ActiveQuery $query
* @param array $params
* @return ActiveDataProvider
*/
public function baseSearch($query, $params)
{
/** @var ParentModule $module */
$module = Yii::$app->getModule('calendar');
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => $module->itemOnPage
],
'sort' => [
'defaultOrder' => [
'published_time' => SORT_DESC
]
]
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->with(['group', 'group.lang']);
$query->andFilterWhere(['like', 'alias', $this->alias])
->andFilterWhere(['=', 'published', $this->published])
->andFilterWhere(['=', 'published_time', $this->published_time])
->andFilterWhere(['=', 'group_id', $this->group_id]);
//
$query->andFilterWhere(['>=', 'published_time', $this->date_from]);
$query->andFilterWhere(['<=', 'published_time', $this->date_to]);
//
$query->andFilterWhere(['like', ParentLang::tableName() . '.title', $this->title]);
return $dataProvider;
}
/**
* @param array $params
* @return ActiveDataProvider
*/
public function search($params)
{
$query = ParentModel::find()->joinWith(['lang'])->undeleted();
return $this->baseSearch($query, $params);
}
/**
* @param array $params
* @return ActiveDataProvider
*/
public function trash($params)
{
$query = ParentModel::find()->joinWith(['lang'])->deleted();
return $this->baseSearch($query, $params);
}
}