ubn5/backend/modules/forum/models/ForumCommentSearch.php

79 lines
1.9 KiB
PHP
Raw Normal View History

2025-02-10 05:21:56 +00:00
<?php
namespace backend\modules\forum\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\ForumComment;
/**
* ForumCommentSearch represents the model behind the search form of `common\models\ForumComment`.
*/
class ForumCommentSearch extends ForumComment
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id', 'forum_thread_id',/*'status',*/ 'created_at', 'updated_at'], 'integer'],
[['forum_comment', 'comment_by'], 'safe'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = ForumComment::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => [
'defaultOrder' => [
'id' => SORT_DESC
]
]
]);
$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;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'forum_thread_id' => $this->forum_thread_id,
//'status' => $this->status,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
]);
$query->andFilterWhere(['like', 'forum_comment', $this->forum_comment])
->andFilterWhere(['like', 'comment_by', $this->comment_by]);
return $dataProvider;
}
}