예제 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Comment::find();
     $query->joinWith(['person']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->sort->attributes['nick'] = ['asc' => ['person.nick' => SORT_ASC], 'desc' => ['person.nick' => SORT_DESC]];
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'datetime' => $this->datetime, 'joke_id' => $this->joke_id, 'aprooved' => $this->aprooved, 'active' => $this->active]);
     $query->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'user_id', $this->user_id]);
     $query->andFilterWhere(['like', 'person.nick', $this->nick]);
     return $dataProvider;
 }
예제 #2
0
 public function findComment($id)
 {
     if ($model = Comment::find()->where(['joke_id' => $id])->all()) {
         return $model;
     } else {
         $model = [];
         return $model;
     }
 }