Visitor::hasReferer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 2
cp 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php namespace Arcanedev\LaravelTracker\Models;
2
3
use Arcanedev\LaravelTracker\Contracts\Models\Visitor as SessionContract;
4
use Arcanedev\LaravelTracker\Support\BindingManager;
5
6
/**
7
 * Class     Visitor
8
 *
9
 * @package  Arcanedev\LaravelTracker\Models
10
 * @author   ARCANEDEV <[email protected]>
11
 *
12
 * @property  int             id
13
 * @property  string          uuid
14
 * @property  int             user_id
15
 * @property  int             device_id
16
 * @property  int             agent_id
17
 * @property  string          client_ip
18
 * @property  int             referrer_id
19
 * @property  int             cookie_id
20
 * @property  int             geoip_id
21
 * @property  int             language_id
22
 * @property  bool            is_robot
23
 * @property  \Carbon\Carbon  created_at
24
 * @property  \Carbon\Carbon  updated_at
25
 *
26
 * @property  \Arcanedev\LaravelTracker\Models\User      user
27
 * @property  \Arcanedev\LaravelTracker\Models\Device    device
28
 * @property  \Arcanedev\LaravelTracker\Models\Agent     agent
29
 * @property  \Arcanedev\LaravelTracker\Models\Referer   referer
30
 * @property  \Arcanedev\LaravelTracker\Models\Cookie    cookie
31
 * @property  \Arcanedev\LaravelTracker\Models\GeoIp     geoip
32
 * @property  \Arcanedev\LaravelTracker\Models\Language  language
33
 */
34
class Visitor extends AbstractModel implements SessionContract
35
{
36
    /* -----------------------------------------------------------------
37
     |  Traits
38
     | -----------------------------------------------------------------
39
     */
40
41
    use Presenters\VisitorPresenter;
42
43
    /* -----------------------------------------------------------------
44
     |  Properties
45
     | -----------------------------------------------------------------
46
     */
47
48
    /**
49
     * The table associated with the model.
50
     *
51
     * @var string
52
     */
53
    protected $table = 'visitors';
54
55
    /**
56
     * The attributes that are mass assignable.
57
     *
58
     * @var array
59
     */
60
    protected $fillable = [
61
        'uuid',
62
        'user_id',
63
        'device_id',
64
        'language_id',
65
        'agent_id',
66
        'client_ip',
67
        'cookie_id',
68
        'referer_id',
69
        'geoip_id',
70
        'is_robot',
71
    ];
72
73
    /**
74
     * The attributes that should be cast to native types.
75
     *
76
     * @var array
77
     */
78
    protected $casts = [
79
        'user_id'     => 'integer',
80
        'device_id'   => 'integer',
81
        'language_id' => 'integer',
82
        'agent_id'    => 'integer',
83
        'cookie_id'   => 'integer',
84
        'referer_id'  => 'integer',
85
        'geoip_id'    => 'integer',
86
        'is_robot'    => 'boolean',
87
    ];
88
89
    /* -----------------------------------------------------------------
90
     |  Relationships
91
     | -----------------------------------------------------------------
92
     */
93
94
    /**
95
     * User relationship.
96
     *
97
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
98
     */
99
    public function user()
100
    {
101
        return $this->belongsTo(
102
            $this->getModelClass(BindingManager::MODEL_USER, User::class)
103
        );
104
    }
105
106
    /**
107
     * Device relationship.
108
     *
109
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
110
     */
111
    public function device()
112
    {
113
        return $this->belongsTo(
114
            $this->getModelClass(BindingManager::MODEL_DEVICE, Device::class)
115
        );
116
    }
117
118
    /**
119
     * Agent relationship.
120
     *
121
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
122
     */
123
    public function agent()
124
    {
125
        return $this->belongsTo(
126
            $this->getModelClass(BindingManager::MODEL_AGENT, Agent::class)
127
        );
128
    }
129
130
    /**
131
     * Referer relationship.
132
     *
133
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
134
     */
135
    public function referer()
136
    {
137
        return $this->belongsTo(
138
            $this->getModelClass(BindingManager::MODEL_REFERER, Referer::class)
139
        );
140
    }
141
142
    /**
143
     * Cookie relationship.
144
     *
145
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
146
     */
147
    public function cookie()
148
    {
149
        return $this->belongsTo(
150
            $this->getModelClass(BindingManager::MODEL_COOKIE, Cookie::class)
151
        );
152
    }
153
154
    /**
155
     * GeoIp relationship.
156
     *
157
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
158
     */
159
    public function geoip()
160
    {
161
        return $this->belongsTo(
162
            $this->getModelClass(BindingManager::MODEL_GEOIP, GeoIp::class), 'geoip_id'
163
        );
164
    }
165
166
    /**
167
     * Language relationship.
168
     *
169
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
170
     */
171
    public function language()
172
    {
173
        return $this->belongsTo(
174
            $this->getModelClass(BindingManager::MODEL_LANGUAGE, Language::class)
175
        );
176
    }
177
178
    /**
179
     * Visitor activities relationship.
180
     *
181
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
182
     */
183
    public function activities()
184
    {
185
        return $this->hasMany(
186
            $this->getModelClass(BindingManager::MODEL_VISITOR_ACTIVITY, VisitorActivity::class)
187
        );
188
    }
189
190
    /* -----------------------------------------------------------------
191
     |  Check Methods
192
     | -----------------------------------------------------------------
193
     */
194
195
    /**
196
     * Check if the user exists.
197
     *
198
     * @return bool
199
     */
200
    public function hasUser()
201
    {
202
        return ! is_null($this->user);
203
    }
204
205
    /**
206
     * Check if the geoip exists.
207
     *
208
     * @return bool
209
     */
210
    public function hasGeoip()
211
    {
212
        return ! is_null($this->geoip);
213
    }
214
215
    /**
216
     * Check if the user agent exists.
217
     *
218
     * @return bool
219
     */
220
    public function hasUserAgent()
221
    {
222
        return ! is_null($this->agent);
223
    }
224
225
    /**
226
     * Check if the device exists.
227
     *
228
     * @return bool
229
     */
230
    public function hasDevice()
231
    {
232
        return ! is_null($this->device);
233
    }
234
235
    /**
236
     * Check if the referer exists.
237
     *
238
     * @return bool
239
     */
240
    public function hasReferer()
241
    {
242
        return ! is_null($this->referer);
243
    }
244
245
    /**
246
     * Check if the cookie exists.
247
     *
248
     * @return bool
249
     */
250
    public function hasCookie()
251
    {
252
        return ! is_null($this->cookie);
253
    }
254
}
255