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\Taxonomy as TaxonomyModel; |
11
|
|
|
use Yii; |
12
|
|
|
use yii\base\Model; |
13
|
|
|
use yii\data\ActiveDataProvider; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Taxonomy represents the model behind the search form about `common\models\Taxonomy`. |
17
|
|
|
* |
18
|
|
|
* @author Agiel K. Saputra <[email protected]> |
19
|
|
|
* @since 0.1.0 |
20
|
|
|
*/ |
21
|
|
View Code Duplication |
class Taxonomy extends TaxonomyModel |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @inheritdoc |
25
|
|
|
*/ |
26
|
|
|
public function rules() |
27
|
|
|
{ |
28
|
|
|
return [ |
29
|
|
|
[['id', 'hierarchical', 'menu_builder'], 'integer'], |
30
|
|
|
[['name', 'slug', 'singular_name', 'plural_name'], '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 = TaxonomyModel::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
|
|
|
'hierarchical' => $this->hierarchical, |
67
|
|
|
'menu_builder' => $this->menu_builder, |
68
|
|
|
]); |
69
|
|
|
|
70
|
|
|
$query->andFilterWhere(['like', 'name', $this->name]) |
71
|
|
|
->andFilterWhere(['like', 'slug', $this->slug]) |
72
|
|
|
->andFilterWhere(['like', 'singular_name', $this->singular_name]) |
73
|
|
|
->andFilterWhere(['like', 'plural_name', $this->plural_name]); |
74
|
|
|
|
75
|
|
|
return $dataProvider; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.