| Current Path : /var/www/html/persada/backend/modules/feedback/models/ |
| Current File : /var/www/html/persada/backend/modules/feedback/models/FeedbackMainSearch.php |
<?php
namespace backend\modules\feedback\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\modules\feedback\models\FeedbackMain;
/**
* FeedbackMainSearch represents the model behind the search form of `backend\modules\feedback\models\FeedbackMain`.
*/
class FeedbackMainSearch extends FeedbackMain {
public $unread;
/**
* {@inheritdoc}
*/
public function rules() {
return [
[['created_by', 'type', 'cat', 'feedback', 'status', 'created_at', 'created_user_type', 'updated_at', 'updated_user_type', 'ticket_no', 'unread'], '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 = FeedbackMain::find()->leftJoin('frontend_user', 'frontend_user.id=feedback_main.created_by');
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => ['defaultOrder' => ['id' => SORT_DESC]],
'pagination' => ['pageSize' => 10],
]);
$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', 'type', $this->type])
->andFilterWhere(['like', 'cat', $this->cat])
->andFilterWhere(['like', 'feedback', $this->feedback])
->andFilterWhere(['like', 'feedback_main.status', $this->status])
->andFilterWhere(['like', 'ticket_no', $this->ticket_no]);
$query->andFilterWhere(['like', 'frontend_user.fullname', $this->created_by]);
if (!empty($this->unread) && $this->unread == 1) {
$query->innerJoin('feedback_messages', 'feedback_main.id=feedback_messages.feedback_id');
$query->andWhere(['=', 'feedback_messages.read_status', 0]);
$query->andWhere(['=', 'feedback_messages.send_to', 'backend_user']);
}
return $dataProvider;
}
}