Issues (3627)

app/bundles/PageBundle/Entity/Hit.php (2 issues)

1
<?php
2
3
/*
4
 * @copyright   2014 Mautic Contributors. All rights reserved
5
 * @author      Mautic
6
 *
7
 * @link        http://mautic.org
8
 *
9
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10
 */
11
12
namespace Mautic\PageBundle\Entity;
13
14
use Doctrine\ORM\Mapping as ORM;
15
use Mautic\ApiBundle\Serializer\Driver\ApiMetadataDriver;
16
use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder;
17
use Mautic\EmailBundle\Entity\Email;
18
use Mautic\LeadBundle\Entity\Lead;
19
use Mautic\LeadBundle\Entity\LeadDevice;
20
21
/**
22
 * Class Hit.
23
 */
24
class Hit
25
{
26
    /**
27
     * @var int
28
     */
29
    private $id;
30
31
    /**
32
     * @var \DateTime
33
     */
34
    private $dateHit;
35
36
    /**
37
     * @var \DateTime
38
     */
39
    private $dateLeft;
40
41
    /**
42
     * @var Page
43
     */
44
    private $page;
45
46
    /**
47
     * @var Redirect
48
     */
49
    private $redirect;
50
51
    /**
52
     * @var \Mautic\EmailBundle\Entity\Email
53
     */
54
    private $email;
55
56
    /**
57
     * @var \Mautic\LeadBundle\Entity\Lead
58
     */
59
    private $lead;
60
61
    /**
62
     * @var \Mautic\CoreBundle\Entity\IpAddress
63
     */
64
    private $ipAddress;
65
66
    /**
67
     * @var string
68
     */
69
    private $country;
70
71
    /**
72
     * @var string
73
     */
74
    private $region;
75
76
    /**
77
     * @var string
78
     */
79
    private $city;
80
81
    /**
82
     * @var string
83
     */
84
    private $isp;
85
86
    /**
87
     * @var string
88
     */
89
    private $organization;
90
91
    /**
92
     * @var int
93
     */
94
    private $code;
95
96
    private $referer;
97
98
    private $url;
99
100
    /**
101
     * @var string
102
     */
103
    private $urlTitle;
104
105
    /**
106
     * @var string
107
     */
108
    private $userAgent;
109
110
    /**
111
     * @var string
112
     */
113
    private $remoteHost;
114
115
    /**
116
     * @var string
117
     */
118
    private $pageLanguage;
119
120
    /**
121
     * @var string
122
     */
123
    private $browserLanguages = [];
124
125
    /**
126
     * @var string
127
     **/
128
    private $trackingId;
129
130
    /**
131
     * @var string
132
     */
133
    private $source;
134
135
    /**
136
     * @var int
137
     */
138
    private $sourceId;
139
140
    /**
141
     * @var array
142
     */
143
    private $query = [];
144
    /**
145
     * @var LeadDevice
146
     */
147
    private $device;
148
149
    public static function loadMetadata(ORM\ClassMetadata $metadata)
150
    {
151
        $builder = new ClassMetadataBuilder($metadata);
152
153
        $builder->setTable('page_hits')
154
            ->setCustomRepositoryClass('Mautic\PageBundle\Entity\HitRepository')
155
            ->addIndex(['tracking_id'], 'page_hit_tracking_search')
156
            ->addIndex(['code'], 'page_hit_code_search')
157
            ->addIndex(['source', 'source_id'], 'page_hit_source_search')
158
            ->addIndex(['date_hit', 'date_left'], 'date_hit_left_index');
159
        // There should be a 128 char prefix index but it cannot be created here
160
        // created in fixtures instead
161
        //->addIndex(['url'], 'page_hit_url');
162
163
        $builder->addBigIntIdField();
164
165
        $builder->createField('dateHit', 'datetime')
166
            ->columnName('date_hit')
167
            ->build();
168
169
        $builder->createField('dateLeft', 'datetime')
170
            ->columnName('date_left')
171
            ->nullable()
172
            ->build();
173
174
        $builder->createManyToOne('page', 'Page')
175
            ->addJoinColumn('page_id', 'id', true, false, 'SET NULL')
176
            ->build();
177
178
        $builder->createManyToOne('redirect', 'Redirect')
179
            ->addJoinColumn('redirect_id', 'id', true, false, 'SET NULL')
180
            ->build();
181
182
        $builder->createManyToOne('email', 'Mautic\EmailBundle\Entity\Email')
183
            ->addJoinColumn('email_id', 'id', true, false, 'SET NULL')
184
            ->build();
185
186
        $builder->addLead(true, 'SET NULL');
187
188
        $builder->addIpAddress();
189
190
        $builder->createField('country', 'string')
191
            ->nullable()
192
            ->build();
193
194
        $builder->createField('region', 'string')
195
            ->nullable()
196
            ->build();
197
198
        $builder->createField('city', 'string')
199
            ->nullable()
200
            ->build();
201
202
        $builder->createField('isp', 'string')
203
            ->nullable()
204
            ->build();
205
206
        $builder->createField('organization', 'string')
207
            ->nullable()
208
            ->build();
209
210
        $builder->addField('code', 'integer');
211
212
        $builder->createField('referer', 'text')
213
            ->nullable()
214
            ->build();
215
216
        $builder->createField('url', 'text')
217
            ->nullable()
218
            ->build();
219
220
        $builder->createField('urlTitle', 'string')
221
            ->columnName('url_title')
222
            ->nullable()
223
            ->build();
224
225
        $builder->createField('userAgent', 'text')
226
            ->columnName('user_agent')
227
            ->nullable()
228
            ->build();
229
230
        $builder->createField('remoteHost', 'string')
231
            ->columnName('remote_host')
232
            ->nullable()
233
            ->build();
234
235
        $builder->createField('pageLanguage', 'string')
236
            ->columnName('page_language')
237
            ->nullable()
238
            ->build();
239
240
        $builder->createField('browserLanguages', 'array')
241
            ->columnName('browser_languages')
242
            ->nullable()
243
            ->build();
244
245
        $builder->createField('trackingId', 'string')
246
            ->columnName('tracking_id')
247
            ->build();
248
249
        $builder->createField('source', 'string')
250
            ->nullable()
251
            ->build();
252
253
        $builder->createField('sourceId', 'integer')
254
            ->columnName('source_id')
255
            ->nullable()
256
            ->build();
257
258
        $builder->addNullableField('query', 'array');
259
260
        $builder->createManyToOne('device', 'Mautic\LeadBundle\Entity\LeadDevice')
261
            ->addJoinColumn('device_id', 'id', true, false, 'SET NULL')
262
            ->cascadePersist()
263
            ->build();
264
    }
265
266
    /**
267
     * Prepares the metadata for API usage.
268
     *
269
     * @param $metadata
270
     */
271
    public static function loadApiMetadata(ApiMetadataDriver $metadata)
272
    {
273
        $metadata->setGroupPrefix('hit')
274
            ->addProperties(
275
                [
276
                    'id',
277
                    'dateHit',
278
                    'dateLeft',
279
                    'page',
280
                    'redirect',
281
                    'email',
282
                    'lead',
283
                    'ipAddress',
284
                    'country',
285
                    'region',
286
                    'city',
287
                    'isp',
288
                    'organization',
289
                    'code',
290
                    'referer',
291
                    'url',
292
                    'urlTitle',
293
                    'userAgent',
294
                    'remoteHost',
295
                    'pageLanguage',
296
                    'browserLanguages',
297
                    'trackingId',
298
                    'source',
299
                    'sourceId',
300
                    'query',
301
                ]
302
            )
303
            ->build();
304
    }
305
306
    /**
307
     * Get id.
308
     *
309
     * @return int
310
     */
311
    public function getId()
312
    {
313
        return $this->id;
314
    }
315
316
    /**
317
     * Set dateHit.
318
     *
319
     * @param \DateTime $dateHit
320
     *
321
     * @return Hit
322
     */
323
    public function setDateHit($dateHit)
324
    {
325
        $this->dateHit = $dateHit;
326
327
        return $this;
328
    }
329
330
    /**
331
     * Get dateHit.
332
     *
333
     * @return \DateTime
334
     */
335
    public function getDateHit()
336
    {
337
        return $this->dateHit;
338
    }
339
340
    /**
341
     * @return \DateTime
342
     */
343
    public function getDateLeft()
344
    {
345
        return $this->dateLeft;
346
    }
347
348
    /**
349
     * @param \DateTime $dateLeft
350
     *
351
     * @return Hit
352
     */
353
    public function setDateLeft($dateLeft)
354
    {
355
        $this->dateLeft = $dateLeft;
356
357
        return $this;
358
    }
359
360
    /**
361
     * Set country.
362
     *
363
     * @param string $country
364
     *
365
     * @return Hit
366
     */
367
    public function setCountry($country)
368
    {
369
        $this->country = $country;
370
371
        return $this;
372
    }
373
374
    /**
375
     * Get country.
376
     *
377
     * @return string
378
     */
379
    public function getCountry()
380
    {
381
        return $this->country;
382
    }
383
384
    /**
385
     * Set region.
386
     *
387
     * @param string $region
388
     *
389
     * @return Hit
390
     */
391
    public function setRegion($region)
392
    {
393
        $this->region = $region;
394
395
        return $this;
396
    }
397
398
    /**
399
     * Get region.
400
     *
401
     * @return string
402
     */
403
    public function getRegion()
404
    {
405
        return $this->region;
406
    }
407
408
    /**
409
     * Set city.
410
     *
411
     * @param string $city
412
     *
413
     * @return Hit
414
     */
415
    public function setCity($city)
416
    {
417
        $this->city = $city;
418
419
        return $this;
420
    }
421
422
    /**
423
     * Get city.
424
     *
425
     * @return string
426
     */
427
    public function getCity()
428
    {
429
        return $this->city;
430
    }
431
432
    /**
433
     * Set isp.
434
     *
435
     * @param string $isp
436
     *
437
     * @return Hit
438
     */
439
    public function setIsp($isp)
440
    {
441
        $this->isp = $isp;
442
443
        return $this;
444
    }
445
446
    /**
447
     * Get isp.
448
     *
449
     * @return string
450
     */
451
    public function getIsp()
452
    {
453
        return $this->isp;
454
    }
455
456
    /**
457
     * Set organization.
458
     *
459
     * @param string $organization
460
     *
461
     * @return Hit
462
     */
463
    public function setOrganization($organization)
464
    {
465
        $this->organization = $organization;
466
467
        return $this;
468
    }
469
470
    /**
471
     * Get organization.
472
     *
473
     * @return string
474
     */
475
    public function getOrganization()
476
    {
477
        return $this->organization;
478
    }
479
480
    /**
481
     * Set code.
482
     *
483
     * @param int $code
484
     *
485
     * @return Hit
486
     */
487
    public function setCode($code)
488
    {
489
        $this->code = $code;
490
491
        return $this;
492
    }
493
494
    /**
495
     * Get code.
496
     *
497
     * @return int
498
     */
499
    public function getCode()
500
    {
501
        return $this->code;
502
    }
503
504
    /**
505
     * Set referer.
506
     *
507
     * @param string $referer
508
     *
509
     * @return Hit
510
     */
511
    public function setReferer($referer)
512
    {
513
        $this->referer = $referer;
514
515
        return $this;
516
    }
517
518
    /**
519
     * Get referer.
520
     *
521
     * @return string
522
     */
523
    public function getReferer()
524
    {
525
        return $this->referer;
526
    }
527
528
    /**
529
     * Set url.
530
     *
531
     * @param string $url
532
     *
533
     * @return Hit
534
     */
535
    public function setUrl($url)
536
    {
537
        $this->url = $url;
538
539
        return $this;
540
    }
541
542
    /**
543
     * Get url.
544
     *
545
     * @return string
546
     */
547
    public function getUrl()
548
    {
549
        return $this->url;
550
    }
551
552
    /**
553
     * Set url title.
554
     *
555
     * @param string $urlTitle
556
     *
557
     * @return Hit
558
     */
559
    public function setUrlTitle($urlTitle)
560
    {
561
        $this->urlTitle = $urlTitle;
562
563
        return $this;
564
    }
565
566
    /**
567
     * Get url title.
568
     *
569
     * @return string
570
     */
571
    public function getUrlTitle()
572
    {
573
        return $this->urlTitle;
574
    }
575
576
    /**
577
     * Set userAgent.
578
     *
579
     * @param string $userAgent
580
     *
581
     * @return Hit
582
     */
583
    public function setUserAgent($userAgent)
584
    {
585
        $this->userAgent = $userAgent;
586
587
        return $this;
588
    }
589
590
    /**
591
     * Get userAgent.
592
     *
593
     * @return string
594
     */
595
    public function getUserAgent()
596
    {
597
        return $this->userAgent;
598
    }
599
600
    /**
601
     * Set remoteHost.
602
     *
603
     * @param string $remoteHost
604
     *
605
     * @return Hit
606
     */
607
    public function setRemoteHost($remoteHost)
608
    {
609
        $this->remoteHost = $remoteHost;
610
611
        return $this;
612
    }
613
614
    /**
615
     * Get remoteHost.
616
     *
617
     * @return string
618
     */
619
    public function getRemoteHost()
620
    {
621
        return $this->remoteHost;
622
    }
623
624
    /**
625
     * Set page.
626
     *
627
     * @param Page $page
628
     *
629
     * @return Hit
630
     */
631
    public function setPage(Page $page = null)
632
    {
633
        $this->page = $page;
634
635
        return $this;
636
    }
637
638
    /**
639
     * Get page.
640
     *
641
     * @return Page
642
     */
643
    public function getPage()
644
    {
645
        return $this->page;
646
    }
647
648
    /**
649
     * Set ipAddress.
650
     *
651
     * @return Hit
652
     */
653
    public function setIpAddress(\Mautic\CoreBundle\Entity\IpAddress $ipAddress)
654
    {
655
        $this->ipAddress = $ipAddress;
656
657
        return $this;
658
    }
659
660
    /**
661
     * Get ipAddress.
662
     *
663
     * @return \Mautic\CoreBundle\Entity\IpAddress
664
     */
665
    public function getIpAddress()
666
    {
667
        return $this->ipAddress;
668
    }
669
670
    /**
671
     * Set trackingId.
672
     *
673
     * @param int $trackingId
674
     *
675
     * @return Page
676
     */
677
    public function setTrackingId($trackingId)
678
    {
679
        $this->trackingId = $trackingId;
680
681
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Mautic\PageBundle\Entity\Hit which is incompatible with the documented return type Mautic\PageBundle\Entity\Page.
Loading history...
682
    }
683
684
    /**
685
     * Get trackingId.
686
     *
687
     * @return int
688
     */
689
    public function getTrackingId()
690
    {
691
        return $this->trackingId;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->trackingId returns the type string which is incompatible with the documented return type integer.
Loading history...
692
    }
693
694
    /**
695
     * Set pageLanguage.
696
     *
697
     * @param string $pageLanguage
698
     *
699
     * @return Hit
700
     */
701
    public function setPageLanguage($pageLanguage)
702
    {
703
        $this->pageLanguage = $pageLanguage;
704
705
        return $this;
706
    }
707
708
    /**
709
     * Get pageLanguage.
710
     *
711
     * @return string
712
     */
713
    public function getPageLanguage()
714
    {
715
        return $this->pageLanguage;
716
    }
717
718
    /**
719
     * Set browserLanguages.
720
     *
721
     * @param string $browserLanguages
722
     *
723
     * @return Hit
724
     */
725
    public function setBrowserLanguages($browserLanguages)
726
    {
727
        $this->browserLanguages = $browserLanguages;
728
729
        return $this;
730
    }
731
732
    /**
733
     * Get browserLanguages.
734
     *
735
     * @return string
736
     */
737
    public function getBrowserLanguages()
738
    {
739
        return $this->browserLanguages;
740
    }
741
742
    /**
743
     * @return Lead
744
     */
745
    public function getLead()
746
    {
747
        return $this->lead;
748
    }
749
750
    /**
751
     * @return Hit
752
     */
753
    public function setLead(Lead $lead)
754
    {
755
        $this->lead = $lead;
756
757
        return $this;
758
    }
759
760
    /**
761
     * @return string
762
     */
763
    public function getSource()
764
    {
765
        return $this->source;
766
    }
767
768
    /**
769
     * @param string $source
770
     *
771
     * @return Hit
772
     */
773
    public function setSource($source)
774
    {
775
        $this->source = $source;
776
777
        return $this;
778
    }
779
780
    /**
781
     * @return int
782
     */
783
    public function getSourceId()
784
    {
785
        return $this->sourceId;
786
    }
787
788
    /**
789
     * @param int $sourceId
790
     *
791
     * @return Hit
792
     */
793
    public function setSourceId($sourceId)
794
    {
795
        $this->sourceId = (int) $sourceId;
796
797
        return $this;
798
    }
799
800
    /**
801
     * @return Redirect
802
     */
803
    public function getRedirect()
804
    {
805
        return $this->redirect;
806
    }
807
808
    /**
809
     * @return Hit
810
     */
811
    public function setRedirect(Redirect $redirect)
812
    {
813
        $this->redirect = $redirect;
814
815
        return $this;
816
    }
817
818
    /**
819
     * @return mixed
820
     */
821
    public function getEmail()
822
    {
823
        return $this->email;
824
    }
825
826
    /**
827
     * @param mixed $email
828
     */
829
    public function setEmail(Email $email)
830
    {
831
        $this->email = $email;
832
    }
833
834
    /**
835
     * @return array
836
     */
837
    public function getQuery()
838
    {
839
        return $this->query;
840
    }
841
842
    /**
843
     * @param array $query
844
     *
845
     * @return Hit
846
     */
847
    public function setQuery($query)
848
    {
849
        $this->query = $query;
850
851
        return $this;
852
    }
853
854
    /**
855
     * @return LeadDevice
856
     */
857
    public function getDeviceStat()
858
    {
859
        return $this->device;
860
    }
861
862
    /**
863
     * @return Hit
864
     */
865
    public function setDeviceStat(LeadDevice $device)
866
    {
867
        $this->device = $device;
868
869
        return $this;
870
    }
871
}
872