|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Coyote\Http\Grids\Adm; |
|
4
|
|
|
|
|
5
|
|
|
use Boduch\Grid\Decorators\Ip; |
|
6
|
|
|
use Boduch\Grid\Filters\FilterOperator; |
|
7
|
|
|
use Boduch\Grid\Filters\Text; |
|
8
|
|
|
use Boduch\Grid\Row; |
|
9
|
|
|
use Carbon\Carbon; |
|
10
|
|
|
use Coyote\Services\Grid\Grid; |
|
11
|
|
|
use Boduch\Grid\Order; |
|
12
|
|
|
use Coyote\Session; |
|
13
|
|
|
use Jenssegers\Agent\Agent; |
|
14
|
|
|
|
|
15
|
|
|
class SessionsGrid extends Grid |
|
16
|
|
|
{ |
|
17
|
|
|
public function buildGrid() |
|
18
|
|
|
{ |
|
19
|
|
|
$this |
|
20
|
|
|
->setDefaultOrder(new Order('updated_at', 'desc')) |
|
21
|
|
|
->addColumn('name', [ |
|
22
|
|
|
'title' => 'Nazwa użytkownika', |
|
23
|
|
|
'sortable' => true, |
|
24
|
|
|
'clickable' => function (Session $session) { |
|
25
|
|
|
if ($session->userId) { |
|
|
|
|
|
|
26
|
|
|
return link_to_route('adm.users.save', $session->name, [$session->userId]); |
|
27
|
|
|
} else { |
|
28
|
|
|
return $session->robot ?: '--'; |
|
29
|
|
|
} |
|
30
|
|
|
}, |
|
31
|
|
|
'filter' => new Text(['operator' => FilterOperator::OPERATOR_ILIKE]) |
|
32
|
|
|
]) |
|
33
|
|
|
->addColumn('created_at', [ |
|
34
|
|
|
'title' => 'Data logowania', |
|
35
|
|
|
'sortable' => true, |
|
36
|
|
|
'render' => function (Session $session) { |
|
37
|
|
|
return Carbon::createFromTimestamp($session->createdAt); |
|
38
|
|
|
}, |
|
39
|
|
|
'decorator' => [$this->getDateTimeDecorator()] |
|
40
|
|
|
]) |
|
41
|
|
|
->addColumn('updated_at', [ |
|
42
|
|
|
'title' => 'Ostatnia aktywność', |
|
43
|
|
|
'sortable' => true, |
|
44
|
|
|
'render' => function (Session $session) { |
|
45
|
|
|
return Carbon::createFromTimestamp($session->updatedAt); |
|
46
|
|
|
}, |
|
47
|
|
|
'decorator' => [$this->getDateTimeDecorator()] |
|
48
|
|
|
]) |
|
49
|
|
|
->addColumn('ip', [ |
|
50
|
|
|
'title' => 'IP', |
|
51
|
|
|
'decorators' => [new Ip()], |
|
52
|
|
|
'filter' => new Text(['operator' => FilterOperator::OPERATOR_ILIKE, 'name' => 'sessions.ip']) |
|
53
|
|
|
]) |
|
54
|
|
|
->addColumn('path', [ |
|
55
|
|
|
'title' => 'Strona', |
|
56
|
|
|
'render' => function (Session $session) { |
|
57
|
|
|
return link_to($session->path); |
|
58
|
|
|
}, |
|
59
|
|
|
'filter' => new Text(['operator' => FilterOperator::OPERATOR_ILIKE]) |
|
60
|
|
|
]) |
|
61
|
|
|
->addColumn('browser', [ |
|
62
|
|
|
'title' => 'Przeglądarka' |
|
63
|
|
|
]) |
|
64
|
|
|
->addColumn('platform', [ |
|
65
|
|
|
'title' => 'System operacyjny' |
|
66
|
|
|
]) |
|
67
|
|
|
->addColumn('user_agent', [ |
|
68
|
|
|
'title' => 'User-agent', |
|
69
|
|
|
'filter' => new Text(['operator' => FilterOperator::OPERATOR_ILIKE, 'name' => 'sessions.browser']) |
|
70
|
|
|
]) |
|
71
|
|
|
->after(function (Row $row) { |
|
72
|
|
|
$agent = new Agent(); |
|
73
|
|
|
$agent->setUserAgent($row->raw('browser')); |
|
74
|
|
|
|
|
75
|
|
|
$row->get('platform')->setValue($agent->platform()); |
|
76
|
|
|
$row->get('browser')->setValue($agent->browser()); |
|
77
|
|
|
$row->get('user_agent')->setValue($row->raw('browser')); |
|
78
|
|
|
}); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: