| @@ 21-77 (lines=57) @@ | ||
| 18 | * @author Agiel K. Saputra <[email protected]> |
|
| 19 | * @since 0.1.0 |
|
| 20 | */ |
|
| 21 | 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 | ||
| @@ 21-84 (lines=64) @@ | ||
| 18 | * @author Agiel K. Saputra <[email protected]> |
|
| 19 | * @since 0.1.0 |
|
| 20 | */ |
|
| 21 | class Term extends TermModel |
|
| 22 | { |
|
| 23 | /** |
|
| 24 | * @inheritdoc |
|
| 25 | */ |
|
| 26 | public function rules() |
|
| 27 | { |
|
| 28 | return [ |
|
| 29 | [['id', 'taxonomy_id', 'parent', 'count'], 'integer'], |
|
| 30 | [['name', 'slug', 'description'], '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 | * @param int $taxonomyId |
|
| 48 | * @return ActiveDataProvider |
|
| 49 | */ |
|
| 50 | public function search($params, $taxonomyId) |
|
| 51 | { |
|
| 52 | $query = TermModel::find(); |
|
| 53 | ||
| 54 | $query->andWhere(['taxonomy_id' => $taxonomyId]); |
|
| 55 | ||
| 56 | $dataProvider = new ActiveDataProvider([ |
|
| 57 | 'query' => $query, |
|
| 58 | 'sort' => [ |
|
| 59 | 'defaultOrder' => [ |
|
| 60 | 'id' => SORT_DESC, |
|
| 61 | ], |
|
| 62 | ], |
|
| 63 | ]); |
|
| 64 | ||
| 65 | $this->load($params); |
|
| 66 | ||
| 67 | if (!$this->validate()) { |
|
| 68 | return $dataProvider; |
|
| 69 | } |
|
| 70 | ||
| 71 | $query->andFilterWhere([ |
|
| 72 | 'id' => $this->id, |
|
| 73 | 'taxonomy_id' => $this->taxonomy_id, |
|
| 74 | 'parent' => $this->parent, |
|
| 75 | 'count' => $this->count, |
|
| 76 | ]); |
|
| 77 | ||
| 78 | $query->andFilterWhere(['like', 'name', $this->name]) |
|
| 79 | ->andFilterWhere(['like', 'slug', $this->slug]) |
|
| 80 | ->andFilterWhere(['like', 'description', $this->description]); |
|
| 81 | ||
| 82 | return $dataProvider; |
|
| 83 | } |
|
| 84 | } |
|
| 85 | ||