Completed
Push — master ( 1c44e2...18a7c0 )
by Antonio Carlos
01:46
created

Session::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace PragmaRX\Tracker\Vendor\Laravel\Models;
4
5
class Session extends Base
6
{
7
    protected $table = 'tracker_sessions';
8
9
    protected $fillable = [
10
        'uuid',
11
        'user_id',
12
        'device_id',
13
        'language_id',
14
        'agent_id',
15
        'client_ip',
16
        'cookie_id',
17
        'referer_id',
18
        'geoip_id',
19
        'is_robot',
20
    ];
21
22
    public function user()
23
    {
24
        return $this->belongsTo($this->getConfig()->get('user_model'));
25
    }
26
27
    public function device()
28
    {
29
        return $this->belongsTo($this->getConfig()->get('device_model'));
30
    }
31
32
    public function language()
33
    {
34
        return $this->belongsTo($this->getConfig()->get('language_model'));
35
    }
36
37
    public function agent()
38
    {
39
        return $this->belongsTo($this->getConfig()->get('agent_model'));
40
    }
41
42
    public function referer()
43
    {
44
        return $this->belongsTo($this->getConfig()->get('referer_model'));
45
    }
46
47
    public function geoIp()
48
    {
49
        return $this->belongsTo($this->getConfig()->get('geoip_model'), 'geoip_id');
50
    }
51
52
    public function cookie()
53
    {
54
        return $this->belongsTo($this->getConfig()->get('cookie_model'), 'cookie_id');
55
    }
56
57
    public function log()
58
    {
59
        return $this->hasMany($this->getConfig()->get('log_model'));
60
    }
61
62
    public function getPageViewsAttribute()
63
    {
64
        return $this->log()->count();
65
    }
66
67 View Code Duplication
    public function users($minutes, $result)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
    {
69
        $query = $this
70
            ->select(
71
                'user_id',
72
                $this->getConnection()->raw('max(updated_at) as updated_at')
73
            )
74
            ->groupBy('user_id')
75
            ->from('tracker_sessions')
76
            ->period($minutes)
77
            ->whereNotNull('user_id')
78
            ->orderBy($this->getConnection()->raw('max(updated_at)'), 'desc');
79
80
        if ($result) {
81
            return $query->get();
82
        }
83
84
        return $query;
85
    }
86
87 View Code Duplication
    public function userDevices($minutes, $result, $user_id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
88
    {
89
        $query = $this
90
            ->select(
91
                'user_id',
92
                $this->getConnection()->raw('max(updated_at) as updated_at')
93
            )
94
            ->groupBy('user_id')
95
            ->from('tracker_sessions')
96
            ->period($minutes)
97
            ->whereNotNull('user_id')
98
            ->orderBy($this->getConnection()->raw('max(updated_at)'), 'desc');
99
100
        if ($result) {
101
            return $query->get();
102
        }
103
104
        return $query;
105
    }
106
}
107