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