| Current Path : /var/www/html/chatbot/backend/models/ |
| Current File : /var/www/html/chatbot/backend/models/LogSearch.php |
<?php
namespace backend\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
/**
* LogSearch represents the model behind the search form about `app\models\Log`.
*/
class LogSearch extends Log
{
/**
* @inheritdoc
*/
public $start_date;
public $end_date;
public $staff_name;
public function rules() {
return [
[['id'], 'integer'],
[['log_dt', 'start_date', 'end_date', 'usr_id', 'staff_name', 'module', 'details'], '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) {
$start_date = '';
$end_date = '';
$query = Log::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => ['defaultOrder' => ['log_dt' => 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(!empty($this->start_date) && !empty($this->end_date)) {
$start_date = date('Y-m-d',strtotime($this->start_date));
$end_date = date('Y-m-d', strtotime($this->end_date));
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
]);
$query->andFilterWhere(['between', 'DATE(log_dt)', $start_date, $end_date]);
$query->andFilterWhere(['like', 'module', $this->module])
->andFilterWhere(['like', 'details', $this->details]);
if (!empty($this->staff_name)) {
$query->joinWith(['user' => function ($q) {
$q->where('hr_staff_info.staff_name LIKE "%' . $this->staff_name . '%"');
}]);
}
return $dataProvider;
}
}