Completed
Push — master ( c30100...d2035e )
by ARCANEDEV
16:12 queued 05:42
created

Visitor::hasReferer()   A

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
    use Presenters\VisitorPresenter;
41
42
    /* ------------------------------------------------------------------------------------------------
43
     |  Properties
44
     | ------------------------------------------------------------------------------------------------
45
     */
46
    /**
47
     * The table associated with the model.
48
     *
49
     * @var string
50
     */
51
    protected $table = 'visitors';
52
53
    /**
54
     * The attributes that are mass assignable.
55
     *
56
     * @var array
57
     */
58
    protected $fillable = [
59
        'uuid',
60
        'user_id',
61
        'device_id',
62
        'language_id',
63
        'agent_id',
64
        'client_ip',
65
        'cookie_id',
66
        'referer_id',
67
        'geoip_id',
68
        'is_robot',
69
    ];
70
71
    /**
72
     * The attributes that should be cast to native types.
73
     *
74
     * @var array
75
     */
76
    protected $casts = [
77
        'user_id'     => 'integer',
78
        'device_id'   => 'integer',
79
        'language_id' => 'integer',
80
        'agent_id'    => 'integer',
81
        'cookie_id'   => 'integer',
82
        'referer_id'  => 'integer',
83
        'geoip_id'    => 'integer',
84
        'is_robot'    => 'boolean',
85
    ];
86
87
    /* ------------------------------------------------------------------------------------------------
88
     |  Relationships
89
     | ------------------------------------------------------------------------------------------------
90
     */
91
    /**
92
     * User relationship.
93
     *
94
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
95
     */
96
    public function user()
97
    {
98
        return $this->belongsTo(
99
            $this->getModelClass(BindingManager::MODEL_USER, User::class)
100
        );
101
    }
102
103
    /**
104
     * Device relationship.
105
     *
106
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
107
     */
108
    public function device()
109
    {
110
        return $this->belongsTo(
111
            $this->getModelClass(BindingManager::MODEL_DEVICE, Device::class)
112
        );
113
    }
114
115
    /**
116
     * Agent relationship.
117
     *
118
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
119
     */
120
    public function agent()
121
    {
122
        return $this->belongsTo(
123
            $this->getModelClass(BindingManager::MODEL_AGENT, Agent::class)
124
        );
125
    }
126
127
    /**
128
     * Referer relationship.
129
     *
130
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
131
     */
132
    public function referer()
133
    {
134
        return $this->belongsTo(
135
            $this->getModelClass(BindingManager::MODEL_REFERER, Referer::class)
136
        );
137
    }
138
139
    /**
140
     * Cookie relationship.
141
     *
142
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
143
     */
144
    public function cookie()
145
    {
146
        return $this->belongsTo(
147
            $this->getModelClass(BindingManager::MODEL_COOKIE, Cookie::class)
148
        );
149
    }
150
151
    /**
152
     * GeoIp relationship.
153
     *
154
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
155
     */
156
    public function geoip()
157
    {
158
        return $this->belongsTo(
159
            $this->getModelClass(BindingManager::MODEL_GEOIP, GeoIp::class), 'geoip_id'
160
        );
161
    }
162
163
    /**
164
     * Language relationship.
165
     *
166
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
167
     */
168
    public function language()
169
    {
170
        return $this->belongsTo(
171
            $this->getModelClass(BindingManager::MODEL_LANGUAGE, Language::class)
172
        );
173
    }
174
175
    /**
176
     * Visitor activities relationship.
177
     *
178
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
179
     */
180
    public function activities()
181
    {
182
        return $this->hasMany(
183
            $this->getModelClass(BindingManager::MODEL_VISITOR_ACTIVITY, VisitorActivity::class)
184
        );
185
    }
186
187
    /* ------------------------------------------------------------------------------------------------
188
     |  Check Functions
189
     | ------------------------------------------------------------------------------------------------
190
     */
191
    /**
192
     * Check if the user exists.
193
     *
194
     * @return bool
195
     */
196
    public function hasUser()
197
    {
198
        return ! is_null($this->user);
199
    }
200
201
    /**
202
     * Check if the geoip exists.
203
     *
204
     * @return bool
205
     */
206
    public function hasGeoip()
207
    {
208
        return ! is_null($this->geoip);
209
    }
210
211
    /**
212
     * Check if the user agent exists.
213
     *
214
     * @return bool
215
     */
216
    public function hasUserAgent()
217
    {
218
        return ! is_null($this->agent);
219
    }
220
221
    /**
222
     * Check if the device exists.
223
     *
224
     * @return bool
225
     */
226
    public function hasDevice()
227
    {
228
        return ! is_null($this->device);
229
    }
230
231
    /**
232
     * Check if the referer exists.
233
     *
234
     * @return bool
235
     */
236
    public function hasReferer()
237
    {
238
        return ! is_null($this->referer);
239
    }
240
241
    /**
242
     * Check if the cookie exists.
243
     *
244
     * @return bool
245
     */
246
    public function hasCookie()
247
    {
248
        return ! is_null($this->cookie);
249
    }
250
}
251