Passed
Push — dev ( 25cfea...72e780 )
by Nico
11:08
created

User::getName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
ccs 0
cts 4
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Orm\Entity;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
use Doctrine\ORM\Mapping\Column;
10
use Doctrine\ORM\Mapping\Entity;
11
use Doctrine\ORM\Mapping\GeneratedValue;
12
use Doctrine\ORM\Mapping\Id;
13
use Doctrine\ORM\Mapping\Index;
14
use Doctrine\ORM\Mapping\JoinColumn;
15
use Doctrine\ORM\Mapping\ManyToOne;
16
use Doctrine\ORM\Mapping\OneToMany;
17
use Doctrine\ORM\Mapping\OneToOne;
18
use Doctrine\ORM\Mapping\OrderBy;
19
use Doctrine\ORM\Mapping\Table;
20
use Stu\Component\Game\GameEnum;
21
use Stu\Component\Map\MapEnum;
22
use Stu\Component\Player\UserAwardEnum;
23
use Stu\Component\Player\UserRpgEnum;
24
use Stu\Module\PlayerSetting\Lib\UserEnum;
25
26
/**
27
 * @Entity(repositoryClass="Stu\Orm\Repository\UserRepository")
28
 * @Table(
29
 *     name="stu_user",
30
 *     indexes={
31
 *         @Index(name="user_alliance_idx", columns={"allys_id"})
32
 *     }
33
 * )
34
 **/
35
class User implements UserInterface
36
{
37
    /**
38
     * @Id
39
     * @Column(type="integer")
40
     * @GeneratedValue(strategy="IDENTITY")
41
     *
42
     */
43
    private int $id;
44
45
    /**
46
     * @Column(type="string")
47
     *
48
     */
49
    private string $username = '';
50
51
    /**
52
     * @Column(type="string", length=20)
53
     *
54
     */
55
    private string $login = '';
56
57
    /**
58
     * @Column(type="string", length=255)
59
     *
60
     */
61
    private string $pass = '';
62
63
    /**
64
     * @Column(type="string", length=6, nullable=true)
65
     *
66
     */
67
    private ?string $sms_code = null;
68
69
    /**
70
     * @Column(type="string", length=200)
71
     *
72
     */
73
    private string $email = '';
74
75
    /**
76
     * @Column(type="string", length=255, nullable=true)
77
     *
78
     */
79
    private ?string $mobile = null;
80
81
    /**
82
     * @Column(type="integer", nullable=true)
83
     *
84
     */
85
    private ?int $allys_id = null;
86
87
    /**
88
     * @Column(type="integer", nullable=true)
89
     *
90
     */
91
    private ?int $race = null;
92
93
    /**
94
     * @Column(type="smallint")
95
     *
96
     */
97
    private int $state = UserEnum::USER_STATE_NEW;
98
99
    /**
100
     * @Column(type="string", length=200)
101
     *
102
     */
103
    private string $propic = '';
104
105
    /**
106
     * @Column(type="boolean")
107
     *
108
     */
109
    private bool $email_notification = true;
110
111
    /**
112
     * @Column(type="integer")
113
     *
114
     */
115
    private int $lastaction = 0;
116
117
    /**
118
     * @Column(type="integer")
119
     *
120
     */
121
    private int $creation = 0;
122
123
    /**
124
     * @Column(type="integer")
125
     *
126
     */
127
    private int $kn_lez = 0;
128
129
    /**
130
     * @Column(type="smallint")
131
     *
132
     */
133
    private int $delmark = 0;
134
135
    /**
136
     * @Column(type="boolean")
137
     *
138
     */
139
    private bool $vac_active = false;
140
141
    /**
142
     * @Column(type="integer")
143
     *
144
     */
145
    private int $vac_request_date = 0;
146
147
    /**
148
     * @Column(type="boolean")
149
     *
150
     */
151
    private bool $storage_notification = true;
152
153
    /**
154
     * @Column(type="text")
155
     *
156
     */
157
    private string $description = '';
158
159
    /**
160
     * @Column(type="boolean")
161
     *
162
     */
163
    private bool $show_online_status = true;
164
165
    /**
166
     * @Column(type="boolean")
167
     *
168
     */
169
    private bool $show_pm_read_receipt = true;
170
171
    /**
172
     * @Column(type="boolean")
173
     *
174
     */
175
    private bool $save_login = true;
176
177
    /**
178
     * @Column(type="boolean")
179
     *
180
     */
181
    private bool $fleet_fixed_default = false;
182
183
    /**
184
     * @Column(type="smallint")
185
     *
186
     */
187
    private int $tick = 1;
188
189
    /**
190
     * @Column(type="smallint", nullable=true)
191
     *
192
     */
193
    private ?int $maptype = MapEnum::MAPTYPE_INSERT;
0 ignored issues
show
introduced by
The private property $maptype is not used, and could be removed.
Loading history...
194
195
    /**
196
     * @Column(type="text")
197
     *
198
     */
199
    private string $sessiondata = '';
200
201
    /**
202
     * @Column(type="string", length=255)
203
     *
204
     */
205
    private string $password_token = '';
206
207
    /**
208
     * @Column(type="string", length=7)
209
     *
210
     */
211
    private string $rgb_code = '';
212
213
    /**
214
     * @Column(type="integer")
215
     *
216
     */
217
    private int $prestige = 0;
218
219
    /**
220
     * @Column(type="string", length=100, nullable=true)
221
     *
222
     */
223
    private ?string $start_page = null;
224
225
    /**
226
     * @Column(type="integer", options={"default": 0})
227
     *
228
     */
229
    private int $rpg_behavior = UserRpgEnum::RPG_BEHAVIOR_NOT_SET;
230
231
    /**
232
     * @Column(type="string", length=100)
233
     *
234
     */
235
    private string $css = 'schwarz';
236
237
    /**
238
     * @Column(type="boolean", options={"default": false})
239
     *
240
     */
241
    private bool $deals = false;
242
243
    /**
244
     *
245
     * @ManyToOne(targetEntity="Alliance", inversedBy="members")
246
     * @JoinColumn(name="allys_id", referencedColumnName="id")
247
     */
248
    private ?AllianceInterface $alliance = null;
249
250
    /**
251
     *
252
     * @ManyToOne(targetEntity="Faction")
253
     * @JoinColumn(name="race", referencedColumnName="id")
254
     */
255
    private ?FactionInterface $faction = null;
256
257
    /**
258
     * @var ArrayCollection<int, UserAwardInterface>
259
     *
260
     * @OneToMany(targetEntity="UserAward", mappedBy="user", indexBy="award_id")
261
     * @OrderBy({"award_id": "ASC"})
262
     */
263
    private Collection $awards;
264
265
    /**
266
     * @var ArrayCollection<int, ColonyInterface>
267
     *
268
     * @OneToMany(targetEntity="Colony", mappedBy="user")
269
     * @OrderBy({"colonies_classes_id": "ASC", "id": "ASC"})
270
     */
271
    private Collection $colonies;
272
273
    /**
274
     * @var ArrayCollection<int, UserLayerInterface>
275
     *
276
     * @OneToMany(targetEntity="UserLayer", mappedBy="user", indexBy="layer_id")
277
     */
278
    private Collection $userLayers;
279
280
    /**
281
     * @OneToOne(targetEntity="UserLock", mappedBy="user")
282
     */
283
    private ?UserLockInterface $userLock = null;
284
285
    /** @var null|array<mixed> */
286
    private $sessiondataUnserialized;
287
288
    public function __construct()
289
    {
290
        $this->awards = new ArrayCollection();
291
        $this->colonies = new ArrayCollection();
292
        $this->userLayers = new ArrayCollection();
293
    }
294
295
    public function getId(): int
296
    {
297
        return $this->id;
298
    }
299
300
    public function getName(): string
301
    {
302
        //if UMODE active, add info to user name
303
        if ($this->isVacationRequestOldEnough()) {
304
            return $this->username . '[b][color=red] (UMODE)[/color][/b]';
305
        }
306
        return $this->username;
307
    }
308
309
    public function setUsername(string $username): UserInterface
310
    {
311
        $this->username = $username;
312
        return $this;
313
    }
314
315
    public function getLogin(): string
316
    {
317
        return $this->login;
318
    }
319
320
    public function setLogin(string $login): UserInterface
321
    {
322
        $this->login = $login;
323
        return $this;
324
    }
325
326
    public function getPassword(): string
327
    {
328
        return $this->pass;
329
    }
330
331
    public function setPassword(string $password): UserInterface
332
    {
333
        $this->pass = $password;
334
        return $this;
335
    }
336
337
    public function getSmsCode(): ?string
338
    {
339
        return $this->sms_code;
340
    }
341
342
    public function setSmsCode(?string $code): UserInterface
343
    {
344
        $this->sms_code = $code;
345
        return $this;
346
    }
347
348
    public function getEmail(): string
349
    {
350
        return $this->email;
351
    }
352
353
    public function setEmail(string $email): UserInterface
354
    {
355
        $this->email = $email;
356
        return $this;
357
    }
358
359
    public function getMobile(): ?string
360
    {
361
        return $this->mobile;
362
    }
363
364
    public function setMobile(?string $mobile): UserInterface
365
    {
366
        $this->mobile = $mobile;
367
        return $this;
368
    }
369
370
    public function getRgbCode(): string
371
    {
372
        return $this->rgb_code;
373
    }
374
375
    public function setRgbCode(string $rgbCode): UserInterface
376
    {
377
        $this->rgb_code = $rgbCode;
378
        return $this;
379
    }
380
381
    public function getCss(): string
382
    {
383
        return $this->css;
384
    }
385
386
    public function setCss(string $Css): UserInterface
387
    {
388
        $this->css = $Css;
389
        return $this;
390
    }
391
392
393
    public function getFactionId(): ?int
394
    {
395
        return $this->race;
396
    }
397
398
    public function setFaction(FactionInterface $faction): UserInterface
399
    {
400
        $this->faction = $faction;
401
        return $this;
402
    }
403
404
    public function getFaction(): ?FactionInterface
405
    {
406
        return $this->faction;
407
    }
408
409
    public function getAwards(): Collection
410
    {
411
        return $this->awards;
412
    }
413
414
    public function getColonies(): Collection
415
    {
416
        return $this->colonies;
417
    }
418
419
    public function hasColony(): bool
420
    {
421
        if (
422
            $this->getState() === UserEnum::USER_STATE_COLONIZATION_SHIP
423
            || $this->getState() === UserEnum::USER_STATE_UNCOLONIZED
424
        ) {
425
            return false;
426
        }
427
428
        return !$this->getColonies()->isEmpty();
429
    }
430
431
    public function getState(): int
432
    {
433
        return $this->state;
434
    }
435
436
    public function isLocked(): bool
437
    {
438
        return $this->getUserLock() !== null && $this->getUserLock()->getRemainingTicks() > 0;
439
    }
440
441
    public function getUserStateDescription(): string
442
    {
443
        if ($this->isLocked()) {
444
            return _('GESPERRT');
445
        }
446
        return UserEnum::getUserStateDescription($this->getState());
447
    }
448
449
    public function setState(int $state): UserInterface
450
    {
451
        $this->state = $state;
452
        return $this;
453
    }
454
455
    public function getAvatar(): string
456
    {
457
        return $this->propic;
458
    }
459
460
    public function setAvatar(string $avatar): UserInterface
461
    {
462
        $this->propic = $avatar;
463
        return $this;
464
    }
465
466
    public function isEmailNotification(): bool
467
    {
468
        return $this->email_notification;
469
    }
470
471
    public function setEmailNotification(bool $email_notification): UserInterface
472
    {
473
        $this->email_notification = $email_notification;
474
        return $this;
475
    }
476
477
    public function getLastaction(): int
478
    {
479
        return $this->lastaction;
480
    }
481
482
    public function setLastaction(int $lastaction): UserInterface
483
    {
484
        $this->lastaction = $lastaction;
485
        return $this;
486
    }
487
488
    public function getCreationDate(): int
489
    {
490
        return $this->creation;
491
    }
492
493
    public function setCreationDate(int $creationDate): UserInterface
494
    {
495
        $this->creation = $creationDate;
496
        return $this;
497
    }
498
499
    public function getKnMark(): int
500
    {
501
        return $this->kn_lez;
502
    }
503
504
    public function setKnMark(int $knMark): UserInterface
505
    {
506
        $this->kn_lez = $knMark;
507
        return $this;
508
    }
509
510
    public function getDeletionMark(): int
511
    {
512
        return $this->delmark;
513
    }
514
515
    public function setDeletionMark(int $deletionMark): UserInterface
516
    {
517
        $this->delmark = $deletionMark;
518
        return $this;
519
    }
520
521
    public function isVacationMode(): bool
522
    {
523
        return $this->vac_active;
524
    }
525
526
    public function setVacationMode(bool $vacationMode): UserInterface
527
    {
528
        $this->vac_active = $vacationMode;
529
        return $this;
530
    }
531
532
    public function getVacationRequestDate(): int
533
    {
534
        return $this->vac_request_date;
535
    }
536
537
    public function setVacationRequestDate(int $date): UserInterface
538
    {
539
        $this->vac_request_date = $date;
540
541
        return $this;
542
    }
543
544
    public function isVacationRequestOldEnough(): bool
545
    {
546
        return $this->isVacationMode() && (time() - $this->getVacationRequestDate() > UserEnum::VACATION_DELAY_IN_SECONDS);
547
    }
548
549
    public function isStorageNotification(): bool
550
    {
551
        return $this->storage_notification;
552
    }
553
554
    public function setStorageNotification(bool $storage_notification): UserInterface
555
    {
556
        $this->storage_notification = $storage_notification;
557
        return $this;
558
    }
559
560
    public function getDescription(): string
561
    {
562
        return $this->description;
563
    }
564
565
    public function setDescription(string $description): UserInterface
566
    {
567
        $this->description = $description;
568
        return $this;
569
    }
570
571
    public function isShowOnlineState(): bool
572
    {
573
        return $this->show_online_status;
574
    }
575
576
    public function setShowOnlineState(bool $showOnlineState): UserInterface
577
    {
578
        $this->show_online_status = $showOnlineState;
579
        return $this;
580
    }
581
582
    public function isShowPmReadReceipt(): bool
583
    {
584
        return $this->show_pm_read_receipt;
585
    }
586
587
    public function setShowPmReadReceipt(bool $showPmReadReceipt): UserInterface
588
    {
589
        $this->show_pm_read_receipt = $showPmReadReceipt;
590
        return $this;
591
    }
592
593
    public function isSaveLogin(): bool
594
    {
595
        return $this->save_login;
596
    }
597
598
    public function setSaveLogin(bool $save_login): UserInterface
599
    {
600
        $this->save_login = $save_login;
601
        return $this;
602
    }
603
604
    public function getFleetFixedDefault(): bool
605
    {
606
        return $this->fleet_fixed_default;
607
    }
608
609
    public function setFleetFixedDefault(bool $fleetFixedDefault): UserInterface
610
    {
611
        $this->fleet_fixed_default = $fleetFixedDefault;
612
        return $this;
613
    }
614
615
    public function getTick(): int
616
    {
617
        return $this->tick;
618
    }
619
620
    public function setTick(int $tick): UserInterface
621
    {
622
        $this->tick = $tick;
623
        return $this;
624
    }
625
626
    public function getUserLayers(): Collection
627
    {
628
        return $this->userLayers;
629
    }
630
631
    public function hasSeen(int $layerId): bool
632
    {
633
        return $this->getUserLayers()->containsKey($layerId);
634
    }
635
636
    public function hasExplored(int $layerId): bool
637
    {
638
        return $this->hasSeen($layerId) && $this->getUserLayers()->get($layerId)->isExplored();
639
    }
640
641
    public function getSessiondata(): string
642
    {
643
        return $this->sessiondata;
644
    }
645
646
    public function setSessiondata(string $sessiondata): UserInterface
647
    {
648
        $this->sessiondata = $sessiondata;
649
        $this->sessiondataUnserialized = null;
650
        return $this;
651
    }
652
653
    public function getPasswordToken(): string
654
    {
655
        return $this->password_token;
656
    }
657
658
    public function setPasswordToken(string $password_token): UserInterface
659
    {
660
        $this->password_token = $password_token;
661
        return $this;
662
    }
663
664
    public function getPrestige(): int
665
    {
666
        return $this->prestige;
667
    }
668
669
    public function setPrestige(int $prestige): UserInterface
670
    {
671
        $this->prestige = $prestige;
672
        return $this;
673
    }
674
675
    public function getStartPage(): ?string
676
    {
677
        return $this->start_page;
678
    }
679
680
    public function setStartPage(?string $startPage): UserInterface
681
    {
682
        $this->start_page = $startPage;
683
        return $this;
684
    }
685
686
    public function getRpgBehavior(): int
687
    {
688
        return $this->rpg_behavior;
689
    }
690
691
    public function setRpgBehavior(int $RPGbehavior): UserInterface
692
    {
693
        $this->rpg_behavior = $RPGbehavior;
694
        return $this;
695
    }
696
697
    public function getRpgBehaviorText(): string
698
    {
699
        return UserRpgEnum::getRpgBehaviorText($this->getRpgBehavior());
700
    }
701
702
    public function getDeals(): bool
703
    {
704
        return $this->deals;
705
    }
706
707
    public function setDeals(bool $deals): UserInterface
708
    {
709
        $this->deals = $deals;
710
        return $this;
711
    }
712
713
    public function isOnline(): bool
714
    {
715
        return !($this->getLastAction() < time() - GameEnum::USER_ONLINE_PERIOD);
716
    }
717
718
    public function getAlliance(): ?AllianceInterface
719
    {
720
        return $this->alliance;
721
    }
722
723
    public function setAlliance(?AllianceInterface $alliance): UserInterface
724
    {
725
        $this->alliance = $alliance;
726
        return $this;
727
    }
728
729
    public function setAllianceId(?int $allianceId): UserInterface
730
    {
731
        $this->allys_id = $allianceId;
732
        return $this;
733
    }
734
735
    public function getSessionDataUnserialized(): array
736
    {
737
        if ($this->sessiondataUnserialized === null) {
738
            $this->sessiondataUnserialized = unserialize($this->getSessionData());
739
            if (!is_array($this->sessiondataUnserialized)) {
740
                $this->sessiondataUnserialized = [];
741
            }
742
        }
743
        return $this->sessiondataUnserialized;
744
    }
745
746
    public function isContactable(): bool
747
    {
748
        return $this->getId() != UserEnum::USER_NOONE;
749
    }
750
751
    public function hasAward(int $awardId): bool
752
    {
753
        return $this->awards->containsKey($awardId) === true;
754
    }
755
756
    public function hasStationsNavigation(): bool
757
    {
758
        if ($this->isNpc()) {
759
            return true;
760
        }
761
762
        return $this->hasAward(UserAwardEnum::RESEARCHED_STATIONS);
763
    }
764
765
    public function isNpc(): bool
766
    {
767
        return $this->getId() < UserEnum::USER_FIRST_ID;
768
    }
769
770
    public function getUserLock(): ?UserLockInterface
771
    {
772
        return $this->userLock;
773
    }
774
775
    public function __toString(): string
776
    {
777
        return sprintf('userName: %s', $this->getName());
778
    }
779
780
    public function hasTranslation(): bool
781
    {
782
        $text = $this->getDescription();
783
        return strpos($text, '[translate]') !== false && strpos($text, '[/translate]') !== false;
784
    }
785
}
786