/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = PostReplay::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'Post_id' => $this->Post_id, 'Participant_id' => $this->Participant_id, 'datetime' => $this->datetime]); $query->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = PostReplay::find(); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $query->asArray()->all(); } $query->orFilterWhere(['like', 'content', $this->globalSearch])->orFilterWhere(['like', 'datetime', $this->globalSearch]); $raw = $query->asArray()->all(); $returnArr = []; foreach ($raw as $row) { $detail = substr($row['content'], 0, 200) . '...'; $arrayRow = ['type' => 'post', 'id' => $row['Post_id'], 'title' => 'Reply - ' . Post::getPostTileByPostId($row['Post_id']), 'detail' => $detail]; array_push($returnArr, $arrayRow); } return $returnArr; }
public function getLatestReplyDatetimeByPostId($id) { return PostReplay::find()->where(['Post_id' => $id])->select('datetime')->orderBy(['datetime' => SORT_DESC])->limit(1)->asArray()->all(); }