@@ 21-98 (lines=78) @@ | ||
18 | * @author Agiel K. Saputra <[email protected]> |
|
19 | * @since 0.1.0 |
|
20 | */ |
|
21 | class MediaComment extends MediaCommentModel |
|
22 | { |
|
23 | /** |
|
24 | * @inheritdoc |
|
25 | */ |
|
26 | public function rules() |
|
27 | { |
|
28 | return [ |
|
29 | [['id', 'media_id', 'parent', 'user_id'], 'integer'], |
|
30 | [['author', 'email', 'url', 'ip', 'date', 'content', 'status', 'agent', 'media_title'], '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|null $mediaId |
|
48 | * @return ActiveDataProvider |
|
49 | */ |
|
50 | public function search($params, $mediaId = null) |
|
51 | { |
|
52 | $query = MediaCommentModel::find(); |
|
53 | $query->innerJoinWith([ |
|
54 | 'commentMedia' => function ($query) { |
|
55 | /* @var $query \yii\db\ActiveQuery */ |
|
56 | return $query->from(['media' => Media::tableName()]); |
|
57 | }, |
|
58 | ])->from(['mediaComment' => static::tableName()]); |
|
59 | ||
60 | if ($mediaId) { |
|
61 | $query->andWhere(['media.id' => $mediaId]); |
|
62 | } |
|
63 | ||
64 | $dataProvider = new ActiveDataProvider([ |
|
65 | 'query' => $query, |
|
66 | 'sort' => [ |
|
67 | 'defaultOrder' => [ |
|
68 | 'id' => SORT_DESC, |
|
69 | ], |
|
70 | ], |
|
71 | ]); |
|
72 | ||
73 | $this->load($params); |
|
74 | ||
75 | if (!$this->validate()) { |
|
76 | return $dataProvider; |
|
77 | } |
|
78 | ||
79 | $query->andFilterWhere([ |
|
80 | 'id' => $this->id, |
|
81 | 'media_id' => $this->media_id, |
|
82 | 'parent' => $this->parent, |
|
83 | 'user_id' => $this->user_id, |
|
84 | ]); |
|
85 | ||
86 | $query->andFilterWhere(['like', 'mediaComment.author', $this->author]) |
|
87 | ->andFilterWhere(['like', 'email', $this->email]) |
|
88 | ->andFilterWhere(['like', 'url', $this->url]) |
|
89 | ->andFilterWhere(['like', 'ip', $this->ip]) |
|
90 | ->andFilterWhere(['like', 'mediaComment.content', $this->content]) |
|
91 | ->andFilterWhere(['like', 'status', $this->status]) |
|
92 | ->andFilterWhere(['like', 'agent', $this->agent]) |
|
93 | ->andFilterWhere(['like', 'mediaComment.date', $this->date]) |
|
94 | ->andFilterWhere(['like', 'media.title', $this->media_title]); |
|
95 | ||
96 | return $dataProvider; |
|
97 | } |
|
98 | } |
|
99 |
@@ 21-103 (lines=83) @@ | ||
18 | * @author Agiel K. Saputra <[email protected]> |
|
19 | * @since 0.1.0 |
|
20 | */ |
|
21 | class PostComment extends PostCommentModel |
|
22 | { |
|
23 | /** |
|
24 | * @inheritdoc |
|
25 | */ |
|
26 | public function rules() |
|
27 | { |
|
28 | return [ |
|
29 | [['id', 'post_id', 'parent', 'user_id'], 'integer'], |
|
30 | [['author', 'email', 'url', 'ip', 'date', 'content', 'status', 'agent', 'post_title'], '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 | * |
|
48 | * @param int $posttype Post type ID |
|
49 | * @param int|null $post Post ID |
|
50 | * @return ActiveDataProvider |
|
51 | */ |
|
52 | public function search($params, $posttype, $post = null) |
|
53 | { |
|
54 | $query = PostCommentModel::find(); |
|
55 | ||
56 | $query->innerJoinWith([ |
|
57 | 'commentPost' => function ($query) { |
|
58 | /* @var $query \yii\db\ActiveQuery */ |
|
59 | return $query->from(['post' => Post::tableName()]); |
|
60 | }, |
|
61 | ])->from(['postComment' => PostComment::tableName()]); |
|
62 | ||
63 | $query->andWhere(['post.type' => $posttype]); |
|
64 | ||
65 | if ($post) { |
|
66 | $query->andWhere(['post.id' => $post]); |
|
67 | } |
|
68 | ||
69 | $dataProvider = new ActiveDataProvider([ |
|
70 | 'query' => $query, |
|
71 | 'sort' => [ |
|
72 | 'defaultOrder' => [ |
|
73 | 'id' => SORT_DESC, |
|
74 | ], |
|
75 | ], |
|
76 | ]); |
|
77 | ||
78 | $this->load($params); |
|
79 | ||
80 | if (!$this->validate()) { |
|
81 | return $dataProvider; |
|
82 | } |
|
83 | ||
84 | $query->andFilterWhere([ |
|
85 | 'id' => $this->id, |
|
86 | 'post_id' => $this->post_id, |
|
87 | 'parent' => $this->parent, |
|
88 | 'user_id' => $this->user_id, |
|
89 | ]); |
|
90 | ||
91 | $query->andFilterWhere(['like', 'postComment.author', $this->author]) |
|
92 | ->andFilterWhere(['like', 'email', $this->email]) |
|
93 | ->andFilterWhere(['like', 'url', $this->url]) |
|
94 | ->andFilterWhere(['like', 'ip', $this->ip]) |
|
95 | ->andFilterWhere(['like', 'postComment.content', $this->content]) |
|
96 | ->andFilterWhere(['like', 'postComment.status', $this->status]) |
|
97 | ->andFilterWhere(['like', 'agent', $this->agent]) |
|
98 | ->andFilterWhere(['like', 'postComment.date', $this->date]) |
|
99 | ->andFilterWhere(['like', 'post.title', $this->post_title]); |
|
100 | ||
101 | return $dataProvider; |
|
102 | } |
|
103 | } |
|
104 |