|
1
|
|
|
<?php |
|
2
|
|
|
namespace Shlinkio\Shlink\Core\Entity; |
|
3
|
|
|
|
|
4
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
5
|
|
|
use Shlinkio\Shlink\Common\Entity\AbstractEntity; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class Visit |
|
9
|
|
|
* @author |
|
10
|
|
|
* @link |
|
11
|
|
|
* |
|
12
|
|
|
* @ORM\Entity(repositoryClass="Shlinkio\Shlink\Core\Repository\VisitRepository") |
|
13
|
|
|
* @ORM\Table(name="visits") |
|
14
|
|
|
*/ |
|
15
|
|
|
class Visit extends AbstractEntity implements \JsonSerializable |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var string |
|
19
|
|
|
* @ORM\Column(type="string", length=256, nullable=true) |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $referer; |
|
22
|
|
|
/** |
|
23
|
|
|
* @var \DateTime |
|
24
|
|
|
* @ORM\Column(type="datetime", nullable=false) |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $date; |
|
27
|
|
|
/** |
|
28
|
|
|
* @var string |
|
29
|
|
|
* @ORM\Column(type="string", length=256, name="remote_addr", nullable=true) |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $remoteAddr; |
|
32
|
|
|
/** |
|
33
|
|
|
* @var string |
|
34
|
|
|
* @ORM\Column(type="string", length=256, name="user_agent", nullable=true) |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $userAgent; |
|
37
|
|
|
/** |
|
38
|
|
|
* @var ShortUrl |
|
39
|
|
|
* @ORM\ManyToOne(targetEntity=ShortUrl::class) |
|
40
|
|
|
* @ORM\JoinColumn(name="short_url_id", referencedColumnName="id") |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $shortUrl; |
|
43
|
|
|
/** |
|
44
|
|
|
* @var VisitLocation |
|
45
|
|
|
* @ORM\ManyToOne(targetEntity=VisitLocation::class, cascade={"persist"}) |
|
46
|
|
|
* @ORM\JoinColumn(name="visit_location_id", referencedColumnName="id", nullable=true) |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $visitLocation; |
|
49
|
|
|
|
|
50
|
7 |
|
public function __construct() |
|
51
|
|
|
{ |
|
52
|
7 |
|
$this->date = new \DateTime(); |
|
53
|
7 |
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return string |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getReferer() |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->referer; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param string $referer |
|
65
|
|
|
* @return $this |
|
66
|
|
|
*/ |
|
67
|
3 |
|
public function setReferer($referer) |
|
68
|
|
|
{ |
|
69
|
3 |
|
$this->referer = $referer; |
|
70
|
3 |
|
return $this; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return \DateTime |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getDate() |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->date; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @param \DateTime $date |
|
83
|
|
|
* @return $this |
|
84
|
|
|
*/ |
|
85
|
|
|
public function setDate($date) |
|
86
|
|
|
{ |
|
87
|
|
|
$this->date = $date; |
|
88
|
|
|
return $this; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @return ShortUrl |
|
93
|
|
|
*/ |
|
94
|
|
|
public function getShortUrl() |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->shortUrl; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param ShortUrl $shortUrl |
|
101
|
|
|
* @return $this |
|
102
|
|
|
*/ |
|
103
|
2 |
|
public function setShortUrl($shortUrl) |
|
104
|
|
|
{ |
|
105
|
2 |
|
$this->shortUrl = $shortUrl; |
|
106
|
2 |
|
return $this; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @return string |
|
111
|
|
|
*/ |
|
112
|
3 |
|
public function getRemoteAddr() |
|
113
|
|
|
{ |
|
114
|
3 |
|
return $this->remoteAddr; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @param string $remoteAddr |
|
119
|
|
|
* @return $this |
|
120
|
|
|
*/ |
|
121
|
5 |
|
public function setRemoteAddr($remoteAddr) |
|
122
|
|
|
{ |
|
123
|
5 |
|
$this->remoteAddr = $remoteAddr; |
|
124
|
5 |
|
return $this; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @return string |
|
129
|
|
|
*/ |
|
130
|
|
|
public function getUserAgent() |
|
131
|
|
|
{ |
|
132
|
|
|
return $this->userAgent; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @param string $userAgent |
|
137
|
|
|
* @return $this |
|
138
|
|
|
*/ |
|
139
|
3 |
|
public function setUserAgent($userAgent) |
|
140
|
|
|
{ |
|
141
|
3 |
|
$this->userAgent = $userAgent; |
|
142
|
3 |
|
return $this; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* @return VisitLocation |
|
147
|
|
|
*/ |
|
148
|
|
|
public function getVisitLocation() |
|
149
|
|
|
{ |
|
150
|
|
|
return $this->visitLocation; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* @param VisitLocation $visitLocation |
|
155
|
|
|
* @return $this |
|
156
|
|
|
*/ |
|
157
|
2 |
|
public function setVisitLocation($visitLocation) |
|
158
|
|
|
{ |
|
159
|
2 |
|
$this->visitLocation = $visitLocation; |
|
160
|
2 |
|
return $this; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Specify data which should be serialized to JSON |
|
165
|
|
|
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php |
|
166
|
|
|
* @return mixed data which can be serialized by <b>json_encode</b>, |
|
167
|
|
|
* which is a value of any type other than a resource. |
|
168
|
|
|
* @since 5.4.0 |
|
169
|
|
|
*/ |
|
170
|
1 |
|
public function jsonSerialize() |
|
171
|
|
|
{ |
|
172
|
|
|
return [ |
|
173
|
1 |
|
'referer' => $this->referer, |
|
174
|
1 |
|
'date' => isset($this->date) ? $this->date->format(\DateTime::ISO8601) : null, |
|
175
|
1 |
|
'remoteAddr' => $this->remoteAddr, |
|
176
|
1 |
|
'userAgent' => $this->userAgent, |
|
177
|
1 |
|
'visitLocation' => $this->visitLocation, |
|
178
|
1 |
|
]; |
|
179
|
|
|
} |
|
180
|
|
|
} |
|
181
|
|
|
|