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

VisitorActivity::visitor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php namespace Arcanedev\LaravelTracker\Models;
2
3
use Arcanedev\LaravelTracker\Contracts\Models\VisitorActivity as VisitorActivityContract;
4
use Arcanedev\LaravelTracker\Support\BindingManager;
5
6
/**
7
 * Class     VisitorActivity
8
 *
9
 * @package  Arcanedev\LaravelTracker\Models
10
 * @author   ARCANEDEV <[email protected]>
11
 *
12
 * @property  int             id
13
 * @property  int             visitor_id
14
 * @property  int             path_id
15
 * @property  int             query_id
16
 * @property  int             referrer_id
17
 * @property  string          method
18
 * @property  int             route_path_id
19
 * @property  bool            is_ajax
20
 * @property  bool            is_secure
21
 * @property  bool            is_json
22
 * @property  bool            wants_json
23
 * @property  int             error_id
24
 * @property  \Carbon\Carbon  created_at
25
 * @property  \Carbon\Carbon  updated_at
26
 *
27
 * @property  \Arcanedev\LaravelTracker\Models\Visitor  visitor
28
 * @property  \Arcanedev\LaravelTracker\Models\Path     path
29
 * @property  \Arcanedev\LaravelTracker\Models\Query    queryRel
30
 * @property  \Arcanedev\LaravelTracker\Models\Referer  referer
31
 * @property  \Arcanedev\LaravelTracker\Models\Error    error
32
 */
33
class VisitorActivity extends AbstractModel implements VisitorActivityContract
34
{
35
    /* ------------------------------------------------------------------------------------------------
36
     |  Properties
37
     | ------------------------------------------------------------------------------------------------
38
     */
39
    /**
40
     * The table associated with the model.
41
     *
42
     * @var string
43
     */
44
    protected $table = 'visitor_activities';
45
46
    /**
47
     * The attributes that are mass assignable.
48
     *
49
     * @var array
50
     */
51
    protected $fillable = [
52
        'visitor_id',
53
        'path_id',
54
        'query_id',
55
        'referrer_id',
56
        'method',
57
        'route_path_id',
58
        'is_ajax',
59
        'is_secure',
60
        'is_json',
61
        'wants_json',
62
        'error_id',
63
    ];
64
65
    /**
66
     * The attributes that should be cast to native types.
67
     *
68
     * @var array
69
     */
70
    protected $casts = [
71
        'id'            => 'integer',
72
        'visitor_id'    => 'integer',
73
        'path_id'       => 'integer',
74
        'query_id'      => 'integer',
75
        'referrer_id'   => 'integer',
76
        'route_path_id' => 'integer',
77
        'is_ajax'       => 'boolean',
78
        'is_secure'     => 'boolean',
79
        'is_json'       => 'boolean',
80
        'wants_json'    => 'boolean',
81
        'error_id'      => 'integer',
82
    ];
83
84
    /* ------------------------------------------------------------------------------------------------
85
     |  Relationships
86
     | ------------------------------------------------------------------------------------------------
87
     */
88
    /**
89
     * Visitor relationship.
90
     *
91
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
92
     */
93
    public function visitor()
94
    {
95
        return $this->belongsTo(
96
            $this->getModelClass(BindingManager::MODEL_VISITOR, Visitor::class)
97
        );
98
    }
99
100
    /**
101
     * Path relationship.
102
     *
103
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
104
     */
105
    public function path()
106
    {
107
        return $this->belongsTo(
108
            $this->getModelClass(BindingManager::MODEL_PATH, Path::class)
109
        );
110
    }
111
112
    /**
113
     * Query relationship.
114
     *
115
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
116
     */
117
    public function queryRel()
118
    {
119
        return $this->belongsTo(
120
            $this->getModelClass(BindingManager::MODEL_QUERY, Query::class)
121
        );
122
    }
123
124
    /**
125
     * Referrer relationship.
126
     *
127
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
128
     */
129
    public function referrer()
130
    {
131
        return $this->belongsTo(
132
            $this->getModelClass(BindingManager::MODEL_REFERER, Referer::class)
133
        );
134
    }
135
136
    /**
137
     * Error relationship.
138
     *
139
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
140
     */
141
    public function error()
142
    {
143
        return $this->belongsTo(
144
            $this->getModelClass(BindingManager::MODEL_ERROR, Error::class)
145
        );
146
    }
147
148
    /* ------------------------------------------------------------------------------------------------
149
     |  Check Functions
150
     | ------------------------------------------------------------------------------------------------
151
     */
152
    /**
153
     * Check if the referer exists.
154
     *
155
     * @return bool
156
     */
157
    public function hasReferer()
158
    {
159
        return ! is_null($this->referer);
160
    }
161
}
162