1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Alpha\VisitorTrackingBundle\Entity; |
||
6 | |||
7 | use Doctrine\Common\Collections\ArrayCollection; |
||
8 | use Doctrine\Common\Collections\Collection; |
||
9 | use Doctrine\ORM\Mapping as ORM; |
||
10 | use Gedmo\Mapping\Annotation as Gedmo; |
||
11 | |||
12 | /** |
||
13 | * @ORM\Entity |
||
14 | * @ORM\Table(name="session", indexes={@ORM\Index(name="session_created_index", columns={"created"})}) |
||
15 | */ |
||
16 | class Session |
||
17 | { |
||
18 | /** |
||
19 | * @var string |
||
20 | * |
||
21 | * @ORM\Column(type="guid") |
||
22 | * @ORM\Id |
||
23 | * @ORM\GeneratedValue(strategy="UUID") |
||
24 | */ |
||
25 | protected $id; |
||
26 | |||
27 | /** |
||
28 | * @var Lifetime|null |
||
29 | * |
||
30 | * @ORM\ManyToOne(targetEntity="Lifetime", inversedBy="sessions") |
||
31 | */ |
||
32 | protected $lifetime; |
||
33 | |||
34 | /** |
||
35 | * @var Collection|PageView[] |
||
36 | * |
||
37 | * @ORM\OneToMany(targetEntity="PageView", mappedBy="session", cascade={"persist"}, fetch="EXTRA_LAZY") |
||
38 | */ |
||
39 | protected $pageViews; |
||
40 | |||
41 | /** |
||
42 | * @var Collection|Device[] |
||
43 | * |
||
44 | * @ORM\OneToMany(targetEntity="Device", mappedBy="session", cascade={"persist"}) |
||
45 | */ |
||
46 | protected $devices; |
||
47 | |||
48 | /** |
||
49 | * @var string |
||
50 | * |
||
51 | * @ORM\Column(type="string") |
||
52 | */ |
||
53 | protected $ip; |
||
54 | |||
55 | /** |
||
56 | * @var string |
||
57 | * |
||
58 | * @ORM\Column(type="string") |
||
59 | */ |
||
60 | protected $referrer; |
||
61 | |||
62 | /** |
||
63 | * @var string |
||
64 | * |
||
65 | * @ORM\Column(type="string") |
||
66 | */ |
||
67 | protected $userAgent; |
||
68 | |||
69 | /** |
||
70 | * @var string |
||
71 | * |
||
72 | * @ORM\Column(type="string") |
||
73 | */ |
||
74 | protected $queryString; |
||
75 | |||
76 | /** |
||
77 | * @var string |
||
78 | * |
||
79 | * @ORM\Column(type="string") |
||
80 | */ |
||
81 | protected $utmSource; |
||
82 | |||
83 | /** |
||
84 | * @var string |
||
85 | * |
||
86 | * @ORM\Column(type="string") |
||
87 | */ |
||
88 | protected $utmMedium; |
||
89 | |||
90 | /** |
||
91 | * @var string |
||
92 | * |
||
93 | * @ORM\Column(type="string") |
||
94 | */ |
||
95 | protected $utmCampaign; |
||
96 | |||
97 | /** |
||
98 | * @var string |
||
99 | * |
||
100 | * @ORM\Column(type="string") |
||
101 | */ |
||
102 | protected $utmTerm; |
||
103 | |||
104 | /** |
||
105 | * @var string |
||
106 | * |
||
107 | * @ORM\Column(type="string") |
||
108 | */ |
||
109 | protected $utmContent; |
||
110 | |||
111 | /** |
||
112 | * @var string |
||
113 | * |
||
114 | * @ORM\Column(type="string") |
||
115 | */ |
||
116 | protected $loanTerm; |
||
117 | |||
118 | /** |
||
119 | * @var string |
||
120 | * |
||
121 | * @ORM\Column(type="string") |
||
122 | */ |
||
123 | protected $repApr; |
||
124 | |||
125 | /** |
||
126 | * @var \DateTime |
||
127 | * |
||
128 | * @ORM\Column(type="datetime") |
||
129 | * @Gedmo\Timestampable(on="create") |
||
130 | */ |
||
131 | protected $created; |
||
132 | |||
133 | public function __construct() |
||
134 | { |
||
135 | $this->pageViews = new ArrayCollection(); |
||
136 | $this->devices = new ArrayCollection(); |
||
137 | } |
||
138 | |||
139 | public function __toString(): string |
||
140 | { |
||
141 | $id = $this->getId(); |
||
142 | |||
143 | if (!\is_string($id)) { |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
144 | return 'N/A'; |
||
145 | } |
||
146 | |||
147 | return $id; |
||
148 | } |
||
149 | |||
150 | /** |
||
151 | * @return string |
||
152 | */ |
||
153 | public function getId() |
||
154 | { |
||
155 | return $this->id; |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * @return string |
||
160 | */ |
||
161 | public function getIp() |
||
162 | { |
||
163 | return $this->ip; |
||
164 | } |
||
165 | |||
166 | /** |
||
167 | * @param string $ip |
||
168 | */ |
||
169 | public function setIp($ip): self |
||
170 | { |
||
171 | $this->ip = $ip; |
||
172 | |||
173 | return $this; |
||
174 | } |
||
175 | |||
176 | /** |
||
177 | * @return string |
||
178 | */ |
||
179 | public function getReferrer() |
||
180 | { |
||
181 | return $this->referrer; |
||
182 | } |
||
183 | |||
184 | /** |
||
185 | * @param string $referrer |
||
186 | */ |
||
187 | public function setReferrer($referrer): self |
||
188 | { |
||
189 | $this->referrer = $referrer; |
||
190 | |||
191 | return $this; |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * @return string |
||
196 | */ |
||
197 | public function getUserAgent() |
||
198 | { |
||
199 | return $this->userAgent; |
||
200 | } |
||
201 | |||
202 | /** |
||
203 | * @param string $userAgent |
||
204 | */ |
||
205 | public function setUserAgent($userAgent): self |
||
206 | { |
||
207 | $this->userAgent = $userAgent; |
||
208 | |||
209 | return $this; |
||
210 | } |
||
211 | |||
212 | /** |
||
213 | * @return string |
||
214 | */ |
||
215 | public function getQueryString() |
||
216 | { |
||
217 | return $this->queryString; |
||
218 | } |
||
219 | |||
220 | /** |
||
221 | * @param string $queryString |
||
222 | */ |
||
223 | public function setQueryString($queryString): self |
||
224 | { |
||
225 | $this->queryString = $queryString; |
||
226 | |||
227 | return $this; |
||
228 | } |
||
229 | |||
230 | /** |
||
231 | * @return string |
||
232 | */ |
||
233 | public function getUtmSource() |
||
234 | { |
||
235 | return $this->utmSource; |
||
236 | } |
||
237 | |||
238 | /** |
||
239 | * @param string $utmSource |
||
240 | */ |
||
241 | public function setUtmSource($utmSource): self |
||
242 | { |
||
243 | $this->utmSource = $utmSource; |
||
244 | |||
245 | return $this; |
||
246 | } |
||
247 | |||
248 | /** |
||
249 | * @return string |
||
250 | */ |
||
251 | public function getUtmMedium() |
||
252 | { |
||
253 | return $this->utmMedium; |
||
254 | } |
||
255 | |||
256 | /** |
||
257 | * @param string $utmMedium |
||
258 | */ |
||
259 | public function setUtmMedium($utmMedium): self |
||
260 | { |
||
261 | $this->utmMedium = $utmMedium; |
||
262 | |||
263 | return $this; |
||
264 | } |
||
265 | |||
266 | /** |
||
267 | * @return string |
||
268 | */ |
||
269 | public function getUtmCampaign() |
||
270 | { |
||
271 | return $this->utmCampaign; |
||
272 | } |
||
273 | |||
274 | /** |
||
275 | * @param string $utmCampaign |
||
276 | */ |
||
277 | public function setUtmCampaign($utmCampaign): self |
||
278 | { |
||
279 | $this->utmCampaign = $utmCampaign; |
||
280 | |||
281 | return $this; |
||
282 | } |
||
283 | |||
284 | /** |
||
285 | * @return string |
||
286 | */ |
||
287 | public function getUtmTerm() |
||
288 | { |
||
289 | return $this->utmTerm; |
||
290 | } |
||
291 | |||
292 | /** |
||
293 | * @param string $utmTerm |
||
294 | */ |
||
295 | public function setUtmTerm($utmTerm): self |
||
296 | { |
||
297 | $this->utmTerm = $utmTerm; |
||
298 | |||
299 | return $this; |
||
300 | } |
||
301 | |||
302 | /** |
||
303 | * @return string |
||
304 | */ |
||
305 | public function getUtmContent() |
||
306 | { |
||
307 | return $this->utmContent; |
||
308 | } |
||
309 | |||
310 | /** |
||
311 | * @param string $utmContent |
||
312 | */ |
||
313 | public function setUtmContent($utmContent): self |
||
314 | { |
||
315 | $this->utmContent = $utmContent; |
||
316 | |||
317 | return $this; |
||
318 | } |
||
319 | |||
320 | /** |
||
321 | * @return string |
||
322 | */ |
||
323 | public function getLoanTerm() |
||
324 | { |
||
325 | return $this->loanTerm; |
||
326 | } |
||
327 | |||
328 | /** |
||
329 | * @param string $loanTerm |
||
330 | */ |
||
331 | public function setLoanTerm($loanTerm): self |
||
332 | { |
||
333 | $this->loanTerm = $loanTerm; |
||
334 | |||
335 | return $this; |
||
336 | } |
||
337 | |||
338 | /** |
||
339 | * @return string |
||
340 | */ |
||
341 | public function getRepApr() |
||
342 | { |
||
343 | return $this->repApr; |
||
344 | } |
||
345 | |||
346 | /** |
||
347 | * @param string $repApr |
||
348 | */ |
||
349 | public function setRepApr($repApr): self |
||
350 | { |
||
351 | $this->repApr = $repApr; |
||
352 | |||
353 | return $this; |
||
354 | } |
||
355 | |||
356 | /** |
||
357 | * @return \DateTime |
||
358 | */ |
||
359 | public function getCreated() |
||
360 | { |
||
361 | return $this->created; |
||
362 | } |
||
363 | |||
364 | public function setCreated(\DateTime $created): self |
||
365 | { |
||
366 | $this->created = $created; |
||
367 | |||
368 | return $this; |
||
369 | } |
||
370 | |||
371 | /** |
||
372 | * @return Lifetime|null |
||
373 | */ |
||
374 | public function getLifetime() |
||
375 | { |
||
376 | return $this->lifetime; |
||
377 | } |
||
378 | |||
379 | public function setLifetime(?Lifetime $lifetime = null): self |
||
380 | { |
||
381 | $this->lifetime = $lifetime; |
||
382 | |||
383 | if ($lifetime instanceof Lifetime && $this->lifetime instanceof Lifetime && !$this->lifetime->getSessions()->contains($this)) { |
||
384 | $this->lifetime->addSession($this); |
||
385 | } |
||
386 | |||
387 | return $this; |
||
388 | } |
||
389 | |||
390 | public function addPageView(PageView $pageView): self |
||
391 | { |
||
392 | if ($pageView->getSession() !== $this) { |
||
393 | $pageView->setSession($this); |
||
394 | } |
||
395 | |||
396 | if (!$this->pageViews->contains($pageView)) { |
||
397 | $this->pageViews->add($pageView); |
||
398 | } |
||
399 | |||
400 | return $this; |
||
401 | } |
||
402 | |||
403 | public function removePageView(PageView $pageViews): self |
||
404 | { |
||
405 | $this->pageViews->removeElement($pageViews); |
||
406 | |||
407 | return $this; |
||
408 | } |
||
409 | |||
410 | public function addDevice(Device $device): self |
||
411 | { |
||
412 | if ($device->getSession() !== $this) { |
||
413 | $device->setSession($this); |
||
414 | } |
||
415 | |||
416 | if (!$this->devices->contains($device)) { |
||
417 | $this->devices->add($device); |
||
418 | } |
||
419 | |||
420 | return $this; |
||
421 | } |
||
422 | |||
423 | public function removeDevice(Device $device): self |
||
424 | { |
||
425 | $this->devices->removeElement($device); |
||
426 | |||
427 | return $this; |
||
428 | } |
||
429 | |||
430 | /** |
||
431 | * @return Collection|Device[] |
||
432 | */ |
||
433 | public function getDevices(): Collection |
||
434 | { |
||
435 | return $this->devices; |
||
436 | } |
||
437 | |||
438 | /** |
||
439 | * @return Collection|PageView[] |
||
440 | */ |
||
441 | public function getPageViews(): Collection |
||
442 | { |
||
443 | return $this->pageViews; |
||
444 | } |
||
445 | } |
||
446 |