|
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\Query; |
|
13
|
|
|
|
|
14
|
|
|
use Da\User\Traits\ModuleAwareTrait; |
|
15
|
|
|
use yii\db\ActiveQuery; |
|
16
|
|
|
use Yii; |
|
17
|
|
|
|
|
18
|
|
|
class SessionHistoryQuery extends ActiveQuery |
|
19
|
|
|
{ |
|
20
|
|
|
use ModuleAwareTrait; |
|
21
|
|
|
|
|
22
|
|
|
public function whereUserId($userId) |
|
23
|
|
|
{ |
|
24
|
|
|
return $this->andWhere($this->getCondition()->byUser($userId)); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function whereActive() |
|
28
|
|
|
{ |
|
29
|
|
|
return $this->andWhere(['IS NOT', 'session_id', null]); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function whereInActive($userId) |
|
33
|
|
|
{ |
|
34
|
|
|
return $this->andWhere($this->getCondition()->inactive($userId)); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
public function whereExpired($userId) |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->andWhere($this->getCondition()->expired($userId)); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function whereExpiredInActive($userId) |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->andWhere($this->getCondition()->expiredInactive($userId)); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function selectSessionId() |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->select(['session_id']); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function whereUserSession($userId, $sessionId) |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->andWhere($this->getCondition()->byUserSession( |
|
56
|
|
|
$userId, |
|
57
|
|
|
$sessionId |
|
58
|
|
|
)); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function whereCurrentUser() |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->andWhere($this->getCondition()->currentUserCondition()); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function oldestUpdatedTimeActiveSession($userId) |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->whereExpiredInActive($userId) |
|
69
|
|
|
->select(['updated_at']) |
|
70
|
|
|
->limit(1) |
|
71
|
|
|
->offset($this->getModule()->numberSessionHistory) |
|
|
|
|
|
|
72
|
|
|
->orderBy(['updated_at' => SORT_DESC])->scalar(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @return SessionHistoryCondition |
|
77
|
|
|
*/ |
|
78
|
|
|
protected function getCondition() |
|
79
|
|
|
{ |
|
80
|
|
|
return Yii::$container->get(SessionHistoryCondition::class); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.