|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the 2amigos/yii2-usuario project. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2amigOS! <http://2amigos.us/> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view |
|
9
|
|
|
* the LICENSE file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Da\User\Search; |
|
13
|
|
|
|
|
14
|
|
|
use Da\User\Model\SessionHistory; |
|
15
|
|
|
use Da\User\Traits\ContainerAwareTrait; |
|
16
|
|
|
use yii\base\InvalidConfigException; |
|
17
|
|
|
use yii\base\InvalidParamException; |
|
18
|
|
|
use yii\data\ActiveDataProvider; |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
class SessionHistorySearch extends SessionHistory |
|
22
|
|
|
{ |
|
23
|
|
|
use ContainerAwareTrait; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
public function rules() |
|
29
|
|
|
{ |
|
30
|
|
|
return [ |
|
31
|
|
|
[['user_agent', 'ip'], 'safe'], |
|
32
|
|
|
]; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param array $params |
|
37
|
|
|
* |
|
38
|
|
|
* @throws InvalidConfigException |
|
39
|
|
|
* @throws InvalidParamException |
|
40
|
|
|
* |
|
41
|
|
|
* @return ActiveDataProvider |
|
42
|
|
|
*/ |
|
43
|
|
|
public function search($params) |
|
44
|
|
|
{ |
|
45
|
|
|
$query = SessionHistory::find()->andWhere([ |
|
46
|
|
|
'user_id' => $this->user_id, |
|
47
|
|
|
]); |
|
48
|
|
|
|
|
49
|
|
|
/** @var ActiveDataProvider $dataProvider */ |
|
50
|
|
|
$dataProvider = $this->make( |
|
51
|
|
|
ActiveDataProvider::class, |
|
52
|
|
|
[], |
|
53
|
|
|
[ |
|
54
|
|
|
'query' => $query, |
|
55
|
|
|
'sort' => [ |
|
56
|
|
|
'defaultOrder' => [ |
|
57
|
|
|
'updated_at' => SORT_DESC |
|
58
|
|
|
], |
|
59
|
|
|
] |
|
60
|
|
|
] |
|
61
|
|
|
); |
|
62
|
|
|
|
|
63
|
|
|
$this->load($params); |
|
64
|
|
|
|
|
65
|
|
|
if (!$this->validate()) { |
|
66
|
|
|
return $dataProvider; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$query->andFilterWhere(['like', 'user_agent', $this->user_agent]) |
|
70
|
|
|
->andFilterWhere(['like', 'ip', $this->ip]); |
|
71
|
|
|
|
|
72
|
|
|
return $dataProvider; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|