Item.php
2.5 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
<?php
namespace backend\modules\map\models\search;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use yii\db\ActiveQuery;
use thread\app\model\interfaces\search\BaseBackendSearchModel;
use backend\modules\map\Map as MainModule;
use backend\modules\map\models\{
Item as MainModel, ItemLang as MainLangModel
};
/**
* Class Item
* @package backend\modules\map\models\search
* @author Alla Kuzmenko
* @copyright (c), Thread
*/
class Item extends MainModel implements BaseBackendSearchModel
{
public $title;
public function rules()
{
return [
[['title', 'type'], 'string'],
[['type_id', 'area_id'], 'integer'],
];
}
/**
*
* @return array
*/
public function scenarios()
{
return Model::scenarios();
}
/**
* @param ActiveQuery $query
* @param array $params
* @return ActiveDataProvider
*/
public function baseSearch($query, $params)
{
/** @var MainModule $module */
$module = $this->getModule();
$dataProvider = new ActiveDataProvider(
[
'query' => $query,
'pagination' => [
'pageSize' => $module->itemOnPage
],
'sort' => [
'defaultOrder' => [
'id' => SORT_DESC
]
]
]
);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere(['=', 'published', $this->published])
->andFilterWhere(['=', 'deleted', $this->deleted])
->andFilterWhere(['=', 'type_id', $this->type_id])
->andFilterWhere(['=', 'area_id', $this->area_id]);
$query->andFilterWhere(['like', MainLangModel::tableName() . '.title', $this->title]);
$query->andFilterWhere(
[
'type' => $this->type,
]
);
return $dataProvider;
}
/**
* Search
*
* @param array $params
* @return ActiveDataProvider
*/
public function search($params)
{
$query = MainModel::find()->joinWith(['lang'])->undeleted();
return $this->baseSearch($query, $params);
}
/**
* @param array $params
* @return ActiveDataProvider
*/
public function trash($params)
{
$query = MainModel::find()->joinWith(['lang'])->deleted();
return $this->baseSearch($query, $params);
}
}