|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @link http://www.writesdown.com/ |
|
4
|
|
|
* @copyright Copyright (c) 2015 WritesDown |
|
5
|
|
|
* @license http://www.writesdown.com/license/ |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace common\models\search; |
|
9
|
|
|
|
|
10
|
|
|
use common\models\PostType as PostTypeModel; |
|
11
|
|
|
use Yii; |
|
12
|
|
|
use yii\base\Model; |
|
13
|
|
|
use yii\data\ActiveDataProvider; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* PostType represents the model behind the search form about `common\models\PostType`. |
|
17
|
|
|
* |
|
18
|
|
|
* @author Agiel K. Saputra <[email protected]> |
|
19
|
|
|
* @since 0.1.0 |
|
20
|
|
|
*/ |
|
21
|
|
|
class PostType extends PostTypeModel |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @inheritdoc |
|
25
|
|
|
*/ |
|
26
|
|
|
public function rules() |
|
27
|
|
|
{ |
|
28
|
|
|
return [ |
|
29
|
|
|
[['id', 'menu_builder'], 'integer'], |
|
30
|
|
|
[['name', 'slug', 'description', 'icon', 'singular_name', 'plural_name', 'permission'], 'safe'], |
|
31
|
|
|
]; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @inheritdoc |
|
36
|
|
|
*/ |
|
37
|
|
|
public function scenarios() |
|
38
|
|
|
{ |
|
39
|
|
|
// bypass scenarios() implementation in the parent class |
|
40
|
|
|
return Model::scenarios(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Creates data provider instance with search query applied |
|
45
|
|
|
* |
|
46
|
|
|
* @param array $params |
|
47
|
|
|
* @return ActiveDataProvider |
|
48
|
|
|
*/ |
|
49
|
|
|
public function search($params) |
|
50
|
|
|
{ |
|
51
|
|
|
$query = PostTypeModel::find(); |
|
52
|
|
|
|
|
53
|
|
|
$dataProvider = new ActiveDataProvider([ |
|
54
|
|
|
'query' => $query, |
|
55
|
|
|
'sort' => ['defaultOrder' => ['id' => SORT_DESC]], |
|
56
|
|
|
]); |
|
57
|
|
|
|
|
58
|
|
|
$this->load($params); |
|
59
|
|
|
|
|
60
|
|
|
if (!$this->validate()) { |
|
61
|
|
|
return $dataProvider; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$query->andFilterWhere([ |
|
65
|
|
|
'id' => $this->id, |
|
66
|
|
|
'menu_builder' => $this->menu_builder, |
|
67
|
|
|
]); |
|
68
|
|
|
|
|
69
|
|
|
$query->andFilterWhere(['like', 'name', $this->name]) |
|
70
|
|
|
->andFilterWhere(['like', 'slug', $this->slug]) |
|
71
|
|
|
->andFilterWhere(['like', 'description', $this->description]) |
|
72
|
|
|
->andFilterWhere(['like', 'icon', $this->icon]) |
|
73
|
|
|
->andFilterWhere(['like', 'singular_name', $this->singular_name]) |
|
74
|
|
|
->andFilterWhere(['like', 'plural_name', $this->plural_name]) |
|
75
|
|
|
->andFilterWhere(['like', 'permission', $this->permission]); |
|
76
|
|
|
|
|
77
|
|
|
return $dataProvider; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|