/** * @param $params * @return ActiveDataProvider */ public function search($params) { $query = Tweet::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 20], 'sort' => ['defaultOrder' => ['order' => SORT_ASC, 'updated_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; }
/** * 伪删除 * @param $id * @return \yii\web\Response * @throws NotFoundHttpException */ public function actionDelete($id) { $model = Tweet::findTweet($id); if (!$model->isCurrent()) { throw new NotFoundHttpException(); } if ($model->comment_count) { $this->flash("已有评论,属于共有财产,不能删除", 'warning'); } else { TweetService::delete($model); $this->flash("删除成功。 ", 'success'); } return $this->redirect(['index']); }
public function getTweet() { return $this->hasOne(Tweet::className(), ['id' => 'target_id']); }
public function userDoAction($id, $action) { $topic = Tweet::findTweet($id); $user = \Yii::$app->user->getIdentity(); return UserService::TopicActionB($user, $topic, $action); }