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 Visitor|null |
61
|
|
|
*/ |
62
|
|
|
protected $visitor; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var Visitor|null |
66
|
|
|
*/ |
67
|
|
|
protected $realVisitor; |
68
|
|
|
|
69
|
|
|
public function __construct(array $viewData = []) |
70
|
|
|
{ |
71
|
|
|
if (isset($viewData['id'])) { |
72
|
|
|
$this->id = (int) $viewData['id']; |
73
|
|
|
} |
74
|
|
|
if (isset($viewData['project_id'])) { |
75
|
|
|
$this->projectId = (int) $viewData['project_id']; |
76
|
|
|
} |
77
|
|
|
if (isset($viewData['uuid'])) { |
78
|
|
|
$this->uuid = $viewData['uuid']; |
79
|
|
|
} |
80
|
|
|
if (isset($viewData['ym_client_id'])) { |
81
|
|
|
$this->ymClientId = $viewData['ym_client_id']; |
82
|
|
|
} |
83
|
|
|
if (isset($viewData['ga_client_id'])) { |
84
|
|
|
$this->gaClientId = $viewData['ga_client_id']; |
85
|
|
|
} |
86
|
|
|
if (isset($viewData['source'])) { |
87
|
|
|
$this->source = $viewData['source']; |
88
|
|
|
} |
89
|
|
|
if (isset($viewData['campaign'])) { |
90
|
|
|
$this->campaign = $viewData['campaign']; |
91
|
|
|
} |
92
|
|
|
if (isset($viewData['keyword'])) { |
93
|
|
|
$this->keyword = $viewData['keyword']; |
94
|
|
|
} |
95
|
|
|
if (isset($viewData['seo_system'])) { |
96
|
|
|
$this->seoSystem = $viewData['seo_system']; |
97
|
|
|
} |
98
|
|
|
if (isset($viewData['page'])) { |
99
|
|
|
$this->page = $viewData['page']; |
100
|
|
|
} |
101
|
|
|
if (isset($viewData['visitor'])) { |
102
|
|
|
$this->visitor = new Visitor($viewData['visitor']); |
103
|
|
|
} |
104
|
|
|
if (isset($viewData['real_visitor'])) { |
105
|
|
|
$this->realVisitor = new Visitor($viewData['real_visitor']); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return bool |
111
|
|
|
* @throws LPTrackerSDKException |
112
|
|
|
*/ |
113
|
|
|
public function validate() |
114
|
|
|
{ |
115
|
|
|
if (empty($this->projectId)) { |
116
|
|
|
throw new LPTrackerSDKException('Project ID is required'); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
if ($this->visitor !== null) { |
120
|
|
|
$this->visitor->validate(); |
121
|
|
|
} |
122
|
|
|
if ($this->realVisitor !== null) { |
123
|
|
|
$this->realVisitor->validate(); |
124
|
|
|
} |
125
|
|
|
return true; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @return array |
130
|
|
|
*/ |
131
|
|
|
public function toArray() |
132
|
|
|
{ |
133
|
|
|
$result = [ |
134
|
|
|
'id' => $this->getId(), |
135
|
|
|
'project_id' => $this->getProjectId(), |
136
|
|
|
'uuid' => $this->getUuid(), |
137
|
|
|
'ym_client_id' => $this->getYmClientId(), |
138
|
|
|
'ga_client_id' => $this->getGaClientId(), |
139
|
|
|
'source' => $this->getSource(), |
140
|
|
|
'campaign' => $this->getCampaign(), |
141
|
|
|
'keyword' => $this->getKeyword(), |
142
|
|
|
'seo_system' => $this->getSeoSystem(), |
143
|
|
|
'page' => $this->getPage(), |
144
|
|
|
'visitor' => $this->visitor !== null |
145
|
|
|
? $this->visitor->toArray() |
146
|
|
|
: null, |
147
|
|
|
'real_visitor' => $this->realVisitor !== null |
148
|
|
|
? $this->realVisitor->toArray() |
149
|
|
|
: null, |
150
|
|
|
]; |
151
|
|
|
return $result; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @return int |
156
|
|
|
*/ |
157
|
|
|
public function getId() |
158
|
|
|
{ |
159
|
|
|
return $this->id; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @return int |
164
|
|
|
*/ |
165
|
|
|
public function getProjectId() |
166
|
|
|
{ |
167
|
|
|
return $this->projectId; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @return string |
172
|
|
|
*/ |
173
|
|
|
public function getSource() |
174
|
|
|
{ |
175
|
|
|
return $this->source; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @param string $source |
180
|
|
|
* @return $this |
181
|
|
|
*/ |
182
|
|
|
public function setSource($source) |
183
|
|
|
{ |
184
|
|
|
$this->source = $source; |
185
|
|
|
return $this; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @return string |
190
|
|
|
*/ |
191
|
|
|
public function getCampaign() |
192
|
|
|
{ |
193
|
|
|
return $this->campaign; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @param string $campaign |
198
|
|
|
* @return $this |
199
|
|
|
*/ |
200
|
|
|
public function setCampaign($campaign) |
201
|
|
|
{ |
202
|
|
|
$this->campaign = $campaign; |
203
|
|
|
return $this; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @return string |
208
|
|
|
*/ |
209
|
|
|
public function getKeyword() |
210
|
|
|
{ |
211
|
|
|
return $this->keyword; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @param string $keyword |
216
|
|
|
* @return $this |
217
|
|
|
*/ |
218
|
|
|
public function setKeyword($keyword) |
219
|
|
|
{ |
220
|
|
|
$this->keyword = $keyword; |
221
|
|
|
return $this; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @return string |
226
|
|
|
*/ |
227
|
|
|
public function getSeoSystem() |
228
|
|
|
{ |
229
|
|
|
return $this->seoSystem; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @param string $seoSystem |
234
|
|
|
* @return $this |
235
|
|
|
*/ |
236
|
|
|
public function setSeoSystem($seoSystem) |
237
|
|
|
{ |
238
|
|
|
$this->seoSystem = $seoSystem; |
239
|
|
|
return $this; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @return string |
244
|
|
|
*/ |
245
|
|
|
public function getPage() |
246
|
|
|
{ |
247
|
|
|
return $this->page; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @param string $page |
252
|
|
|
* @return $this |
253
|
|
|
*/ |
254
|
|
|
public function setPage($page) |
255
|
|
|
{ |
256
|
|
|
$this->page = $page; |
257
|
|
|
return $this; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* @return string |
262
|
|
|
*/ |
263
|
|
|
public function getUuid() |
264
|
|
|
{ |
265
|
|
|
return $this->uuid; |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* @return string |
270
|
|
|
*/ |
271
|
|
|
public function getYmClientId() |
272
|
|
|
{ |
273
|
|
|
return $this->ymClientId; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* @return string |
278
|
|
|
*/ |
279
|
|
|
public function getGaClientId() |
280
|
|
|
{ |
281
|
|
|
return $this->gaClientId; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* @return Visitor|null |
286
|
|
|
*/ |
287
|
|
|
public function getVisitor() |
288
|
|
|
{ |
289
|
|
|
return $this->visitor; |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* @return Visitor|null |
294
|
|
|
*/ |
295
|
|
|
public function getRealVisitor() |
296
|
|
|
{ |
297
|
|
|
return $this->realVisitor; |
298
|
|
|
} |
299
|
|
|
} |
300
|
|
|
|