public function search($params)
{
$query = Post::find()->with('user', 'category');
// 如果有无人区节点 帖子列表过滤无人区节点的帖子
if (PostMeta::noManLandId() && (empty($params['PostSearch']['post_meta_id']) || $params['PostSearch']['post_meta_id'] != PostMeta::noManLandId())) {
$query->andWhere(['!=', 'post_meta_id', PostMeta::noManLandId()]);
}
$dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 20], 'sort' => ['defaultOrder' => ['order' => SORT_ASC, 'last_comment_time' => SORT_DESC, 'created_at' => SORT_DESC]]]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere(['id' => $this->id, 'post_meta_id' => $this->post_meta_id, 'user_id' => $this->user_id, 'view_count' => $this->view_count, 'comment_count' => $this->comment_count, 'favorite_count' => $this->favorite_count, 'like_count' => $this->like_count, 'thanks_count' => $this->thanks_count, 'hate_count' => $this->hate_count, 'status' => $this->status, 'order' => $this->order, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
$query->andFilterWhere(['like', 'type', $this->type])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'excerpt', $this->excerpt])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'tags', $this->tags]);
return $dataProvider;
}