Files
SmartHomePHP/models/HistorySearch.php
2016-11-13 04:11:04 +02:00

79 lines
1.8 KiB
PHP

<?php
namespace app\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\History;
/**
* HistorySearch represents the model behind the search form about `app\models\History`.
*/
class HistorySearch extends History
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'type', 'event_id', 'board_id', 'user_id', 'item_id', 'commited_at', 'value'], 'integer'],
];
}
/**
* @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 = History::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => [
'defaultOrder' => [
'commited_at' => 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,
'type' => $this->type,
'event_id' => $this->event_id,
'board_id' => $this->board_id,
'user_id' => $this->user_id,
'item_id' => $this->item_id,
'commited_at' => $this->commited_at,
'value' => $this->value,
]);
return $dataProvider;
}
}