|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LPTracker\models; |
|
4
|
|
|
|
|
5
|
|
|
use LPTracker\exceptions\LPTrackerSDKException; |
|
6
|
|
|
|
|
7
|
|
|
class View extends Model |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @var integer |
|
11
|
|
|
*/ |
|
12
|
|
|
protected $id; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $uuid; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $ymClientId; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $gaClientId; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var integer |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $projectId; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $source; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $campaign; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var string |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $keyword; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var string |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $seoSystem; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var string |
|
56
|
|
|
*/ |
|
57
|
|
|
protected $page; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var string |
|
61
|
|
|
*/ |
|
62
|
|
|
protected $referer; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @var Visitor|null |
|
66
|
|
|
*/ |
|
67
|
|
|
protected $visitor; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @var Visitor|null |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $realVisitor; |
|
73
|
|
|
|
|
74
|
|
|
public function __construct(array $viewData = []) |
|
75
|
|
|
{ |
|
76
|
|
|
if (isset($viewData['id'])) { |
|
77
|
|
|
$this->id = (int) $viewData['id']; |
|
78
|
|
|
} |
|
79
|
|
|
if (isset($viewData['project_id'])) { |
|
80
|
|
|
$this->projectId = (int) $viewData['project_id']; |
|
81
|
|
|
} |
|
82
|
|
|
if (isset($viewData['uuid'])) { |
|
83
|
|
|
$this->uuid = $viewData['uuid']; |
|
84
|
|
|
} |
|
85
|
|
|
if (isset($viewData['ym_client_id'])) { |
|
86
|
|
|
$this->ymClientId = $viewData['ym_client_id']; |
|
87
|
|
|
} |
|
88
|
|
|
if (isset($viewData['ga_client_id'])) { |
|
89
|
|
|
$this->gaClientId = $viewData['ga_client_id']; |
|
90
|
|
|
} |
|
91
|
|
|
if (isset($viewData['source'])) { |
|
92
|
|
|
$this->source = $viewData['source']; |
|
93
|
|
|
} |
|
94
|
|
|
if (isset($viewData['campaign'])) { |
|
95
|
|
|
$this->campaign = $viewData['campaign']; |
|
96
|
|
|
} |
|
97
|
|
|
if (isset($viewData['keyword'])) { |
|
98
|
|
|
$this->keyword = $viewData['keyword']; |
|
99
|
|
|
} |
|
100
|
|
|
if (isset($viewData['seo_system'])) { |
|
101
|
|
|
$this->seoSystem = $viewData['seo_system']; |
|
102
|
|
|
} |
|
103
|
|
|
if (isset($viewData['page'])) { |
|
104
|
|
|
$this->page = $viewData['page']; |
|
105
|
|
|
} |
|
106
|
|
|
if (isset($viewData['referer'])) { |
|
107
|
|
|
$this->referer = $viewData['referer']; |
|
108
|
|
|
} |
|
109
|
|
|
if (isset($viewData['visitor'])) { |
|
110
|
|
|
$this->visitor = new Visitor($viewData['visitor']); |
|
111
|
|
|
} |
|
112
|
|
|
if (isset($viewData['real_visitor'])) { |
|
113
|
|
|
$this->realVisitor = new Visitor($viewData['real_visitor']); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @return bool |
|
119
|
|
|
* @throws LPTrackerSDKException |
|
120
|
|
|
*/ |
|
121
|
|
|
public function validate() |
|
122
|
|
|
{ |
|
123
|
|
|
if (empty($this->projectId)) { |
|
124
|
|
|
throw new LPTrackerSDKException('Project ID is required'); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
if ($this->visitor !== null) { |
|
128
|
|
|
$this->visitor->validate(); |
|
129
|
|
|
} |
|
130
|
|
|
if ($this->realVisitor !== null) { |
|
131
|
|
|
$this->realVisitor->validate(); |
|
132
|
|
|
} |
|
133
|
|
|
return true; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @return array |
|
138
|
|
|
*/ |
|
139
|
|
|
public function toArray() |
|
140
|
|
|
{ |
|
141
|
|
|
$result = [ |
|
142
|
|
|
'id' => $this->getId(), |
|
143
|
|
|
'project_id' => $this->getProjectId(), |
|
144
|
|
|
'uuid' => $this->getUuid(), |
|
145
|
|
|
'ym_client_id' => $this->getYmClientId(), |
|
146
|
|
|
'ga_client_id' => $this->getGaClientId(), |
|
147
|
|
|
'source' => $this->getSource(), |
|
148
|
|
|
'campaign' => $this->getCampaign(), |
|
149
|
|
|
'keyword' => $this->getKeyword(), |
|
150
|
|
|
'seo_system' => $this->getSeoSystem(), |
|
151
|
|
|
'page' => $this->getPage(), |
|
152
|
|
|
'referer' => $this->getReferer(), |
|
153
|
|
|
'visitor' => $this->visitor !== null |
|
154
|
|
|
? $this->visitor->toArray() |
|
155
|
|
|
: null, |
|
156
|
|
|
'real_visitor' => $this->realVisitor !== null |
|
157
|
|
|
? $this->realVisitor->toArray() |
|
158
|
|
|
: null, |
|
159
|
|
|
]; |
|
160
|
|
|
return $result; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @return int |
|
165
|
|
|
*/ |
|
166
|
|
|
public function getId() |
|
167
|
|
|
{ |
|
168
|
|
|
return $this->id; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* @return int |
|
173
|
|
|
*/ |
|
174
|
|
|
public function getProjectId() |
|
175
|
|
|
{ |
|
176
|
|
|
return $this->projectId; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* @return string |
|
181
|
|
|
*/ |
|
182
|
|
|
public function getSource() |
|
183
|
|
|
{ |
|
184
|
|
|
return $this->source; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* @param string $source |
|
189
|
|
|
* @return $this |
|
190
|
|
|
*/ |
|
191
|
|
|
public function setSource($source) |
|
192
|
|
|
{ |
|
193
|
|
|
$this->source = $source; |
|
194
|
|
|
return $this; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* @return string |
|
199
|
|
|
*/ |
|
200
|
|
|
public function getCampaign() |
|
201
|
|
|
{ |
|
202
|
|
|
return $this->campaign; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* @param string $campaign |
|
207
|
|
|
* @return $this |
|
208
|
|
|
*/ |
|
209
|
|
|
public function setCampaign($campaign) |
|
210
|
|
|
{ |
|
211
|
|
|
$this->campaign = $campaign; |
|
212
|
|
|
return $this; |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* @return string |
|
217
|
|
|
*/ |
|
218
|
|
|
public function getKeyword() |
|
219
|
|
|
{ |
|
220
|
|
|
return $this->keyword; |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
/** |
|
224
|
|
|
* @param string $keyword |
|
225
|
|
|
* @return $this |
|
226
|
|
|
*/ |
|
227
|
|
|
public function setKeyword($keyword) |
|
228
|
|
|
{ |
|
229
|
|
|
$this->keyword = $keyword; |
|
230
|
|
|
return $this; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* @return string |
|
235
|
|
|
*/ |
|
236
|
|
|
public function getSeoSystem() |
|
237
|
|
|
{ |
|
238
|
|
|
return $this->seoSystem; |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
|
|
* @param string $seoSystem |
|
243
|
|
|
* @return $this |
|
244
|
|
|
*/ |
|
245
|
|
|
public function setSeoSystem($seoSystem) |
|
246
|
|
|
{ |
|
247
|
|
|
$this->seoSystem = $seoSystem; |
|
248
|
|
|
return $this; |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
/** |
|
252
|
|
|
* @return string |
|
253
|
|
|
*/ |
|
254
|
|
|
public function getPage() |
|
255
|
|
|
{ |
|
256
|
|
|
return $this->page; |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
/** |
|
260
|
|
|
* @param string $page |
|
261
|
|
|
* @return $this |
|
262
|
|
|
*/ |
|
263
|
|
|
public function setPage($page) |
|
264
|
|
|
{ |
|
265
|
|
|
$this->page = $page; |
|
266
|
|
|
return $this; |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* @return string |
|
271
|
|
|
*/ |
|
272
|
|
|
public function getReferer() |
|
273
|
|
|
{ |
|
274
|
|
|
return $this->referer; |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
/** |
|
278
|
|
|
* @param string $referer |
|
279
|
|
|
* @return $this |
|
280
|
|
|
*/ |
|
281
|
|
|
public function setReferer($referer) |
|
282
|
|
|
{ |
|
283
|
|
|
$this->referer = $referer; |
|
284
|
|
|
return $this; |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
/** |
|
288
|
|
|
* @return string |
|
289
|
|
|
*/ |
|
290
|
|
|
public function getUuid() |
|
291
|
|
|
{ |
|
292
|
|
|
return $this->uuid; |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
/** |
|
296
|
|
|
* @return string |
|
297
|
|
|
*/ |
|
298
|
|
|
public function getYmClientId() |
|
299
|
|
|
{ |
|
300
|
|
|
return $this->ymClientId; |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
/** |
|
304
|
|
|
* @return string |
|
305
|
|
|
*/ |
|
306
|
|
|
public function getGaClientId() |
|
307
|
|
|
{ |
|
308
|
|
|
return $this->gaClientId; |
|
309
|
|
|
} |
|
310
|
|
|
|
|
311
|
|
|
/** |
|
312
|
|
|
* @return Visitor|null |
|
313
|
|
|
*/ |
|
314
|
|
|
public function getVisitor() |
|
315
|
|
|
{ |
|
316
|
|
|
return $this->visitor; |
|
317
|
|
|
} |
|
318
|
|
|
|
|
319
|
|
|
/** |
|
320
|
|
|
* @return Visitor|null |
|
321
|
|
|
*/ |
|
322
|
|
|
public function getRealVisitor() |
|
323
|
|
|
{ |
|
324
|
|
|
return $this->realVisitor; |
|
325
|
|
|
} |
|
326
|
|
|
} |
|
327
|
|
|
|