| Current Path : /var/www/html/learn/backend/modules/chat/models/ |
| Current File : /var/www/html/learn/backend/modules/chat/models/ChatQuestionSearch.php |
<?php
namespace backend\modules\chat\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\modules\chat\models\ChatQuestion;
/**
* ChatQuestionSearch represents the model behind the search form of `backend\modules\chat\models\ChatQuestion`.
*/
class ChatQuestionSearch extends ChatQuestion {
public $user;
/**
* {@inheritdoc}
*/
public function rules() {
return [
[['question_id', 'question_review'], 'integer'],
[['question_description', 'question_language', 'create_dttm'], 'safe'],
[['user_id'], '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 = ChatQuestion::find();
$query->joinWith(['user']);
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10,]]);
$dataProvider->setSort(['defaultOrder' => ['question_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(['like', 'chat_user.user_name', $this->user_id]);
$query->andFilterWhere(['like', 'question_description', $this->question_description])
->andFilterWhere(['like', 'chat_question.create_dttm', $this->create_dttm]);
return $dataProvider;
}
public function searchIndividual($params) {
$query = ChatQuestion::find();
$query->joinWith(['user']);
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => [
'defaultOrder' => [
'create_dttm' => 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;
}
if (!$this->question_review) {
$this->question_review = 0;
}
// grid filtering conditions
$query->andFilterWhere([
'chat_question.user_id' => $this->user_id
]);
return $dataProvider;
}
}