Passed
Push — master ( 69410e...6e6431 )
by Nico
42:43 queued 11:08
created

User::setPasswordToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
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\UserRpgBehaviorEnum;
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")
89
     *
90
     */
91
    private int $race = 9;
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="smallint", length=1, enumType=UserRpgBehaviorEnum::class)
227
     *
228
     */
229
    private UserRpgBehaviorEnum $rpg_behavior = UserRpgBehaviorEnum::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
     * @Column(type="integer", nullable=true)
245
     *
246
     */
247
    private ?int $last_boarding = null;
248
249
    /**
250
     *
251
     * @ManyToOne(targetEntity="Alliance", inversedBy="members")
252
     * @JoinColumn(name="allys_id", referencedColumnName="id")
253
     */
254
    private ?AllianceInterface $alliance = null;
255
256
    /**
257
     *
258
     * @ManyToOne(targetEntity="Faction")
259
     * @JoinColumn(name="race", referencedColumnName="id")
260
     */
261
    private FactionInterface $faction;
262
263
    /**
264
     * @var ArrayCollection<int, UserAwardInterface>
265
     *
266
     * @OneToMany(targetEntity="UserAward", mappedBy="user", indexBy="award_id")
267
     * @OrderBy({"award_id": "ASC"})
268
     */
269
    private Collection $awards;
270
271
    /**
272
     * @var ArrayCollection<int, ColonyInterface>
273
     *
274
     * @OneToMany(targetEntity="Colony", mappedBy="user")
275
     * @OrderBy({"colonies_classes_id": "ASC", "id": "ASC"})
276
     */
277
    private Collection $colonies;
278
279
    /**
280
     * @var ArrayCollection<int, UserLayerInterface>
281
     *
282
     * @OneToMany(targetEntity="UserLayer", mappedBy="user", indexBy="layer_id")
283
     */
284
    private Collection $userLayers;
285
286
    /**
287
     * @OneToOne(targetEntity="UserLock", mappedBy="user")
288
     */
289
    private ?UserLockInterface $userLock = null;
290
291
    /** @var null|array<mixed> */
292
    private $sessiondataUnserialized;
293
294
    public function __construct()
295
    {
296
        $this->awards = new ArrayCollection();
297
        $this->colonies = new ArrayCollection();
298
        $this->userLayers = new ArrayCollection();
299
    }
300
301
    public function getId(): int
302
    {
303
        return $this->id;
304
    }
305
306
    public function getName(): string
307
    {
308
        //if UMODE active, add info to user name
309
        if ($this->isVacationRequestOldEnough()) {
310
            return $this->username . '[b][color=red] (UMODE)[/color][/b]';
311
        }
312
        return $this->username;
313
    }
314
315
    public function setUsername(string $username): UserInterface
316
    {
317
        $this->username = $username;
318
        return $this;
319
    }
320
321
    public function getLogin(): string
322
    {
323
        return $this->login;
324
    }
325
326
    public function setLogin(string $login): UserInterface
327
    {
328
        $this->login = $login;
329
        return $this;
330
    }
331
332
    public function getPassword(): string
333
    {
334
        return $this->pass;
335
    }
336
337
    public function setPassword(string $password): UserInterface
338
    {
339
        $this->pass = $password;
340
        return $this;
341
    }
342
343
    public function getSmsCode(): ?string
344
    {
345
        return $this->sms_code;
346
    }
347
348
    public function setSmsCode(?string $code): UserInterface
349
    {
350
        $this->sms_code = $code;
351
        return $this;
352
    }
353
354
    public function getEmail(): string
355
    {
356
        return $this->email;
357
    }
358
359
    public function setEmail(string $email): UserInterface
360
    {
361
        $this->email = $email;
362
        return $this;
363
    }
364
365
    public function getMobile(): ?string
366
    {
367
        return $this->mobile;
368
    }
369
370
    public function setMobile(?string $mobile): UserInterface
371
    {
372
        $this->mobile = $mobile;
373
        return $this;
374
    }
375
376
    public function getRgbCode(): string
377
    {
378
        return $this->rgb_code;
379
    }
380
381
    public function setRgbCode(string $rgbCode): UserInterface
382
    {
383
        $this->rgb_code = $rgbCode;
384
        return $this;
385
    }
386
387
    public function getCss(): string
388
    {
389
        return $this->css;
390
    }
391
392
    public function setCss(string $Css): UserInterface
393
    {
394
        $this->css = $Css;
395
        return $this;
396
    }
397
398
399
    public function getFactionId(): int
400
    {
401
        return $this->race;
402
    }
403
404
    public function setFaction(FactionInterface $faction): UserInterface
405
    {
406
        $this->faction = $faction;
407
        return $this;
408
    }
409
410
    public function getFaction(): FactionInterface
411
    {
412
        return $this->faction;
413
    }
414
415
    public function getAwards(): Collection
416
    {
417
        return $this->awards;
418
    }
419
420
    public function getColonies(): Collection
421
    {
422
        return $this->colonies;
423
    }
424
425
    public function hasColony(): bool
426
    {
427
        if (
428
            $this->getState() === UserEnum::USER_STATE_COLONIZATION_SHIP
429
            || $this->getState() === UserEnum::USER_STATE_UNCOLONIZED
430
        ) {
431
            return false;
432
        }
433
434
        return !$this->getColonies()->isEmpty();
435
    }
436
437
    public function getState(): int
438
    {
439
        return $this->state;
440
    }
441
442
    public function isLocked(): bool
443
    {
444
        return $this->getUserLock() !== null && $this->getUserLock()->getRemainingTicks() > 0;
445
    }
446
447
    public function getUserStateDescription(): string
448
    {
449
        if ($this->isLocked()) {
450
            return _('GESPERRT');
451
        }
452
        return UserEnum::getUserStateDescription($this->getState());
453
    }
454
455
    public function setState(int $state): UserInterface
456
    {
457
        $this->state = $state;
458
        return $this;
459
    }
460
461
    public function getAvatar(): string
462
    {
463
        return $this->propic;
464
    }
465
466
    public function setAvatar(string $avatar): UserInterface
467
    {
468
        $this->propic = $avatar;
469
        return $this;
470
    }
471
472
    public function isEmailNotification(): bool
473
    {
474
        return $this->email_notification;
475
    }
476
477
    public function setEmailNotification(bool $email_notification): UserInterface
478
    {
479
        $this->email_notification = $email_notification;
480
        return $this;
481
    }
482
483
    public function getLastaction(): int
484
    {
485
        return $this->lastaction;
486
    }
487
488
    public function setLastaction(int $lastaction): UserInterface
489
    {
490
        $this->lastaction = $lastaction;
491
        return $this;
492
    }
493
494
    public function getCreationDate(): int
495
    {
496
        return $this->creation;
497
    }
498
499
    public function setCreationDate(int $creationDate): UserInterface
500
    {
501
        $this->creation = $creationDate;
502
        return $this;
503
    }
504
505
    public function getKnMark(): int
506
    {
507
        return $this->kn_lez;
508
    }
509
510
    public function setKnMark(int $knMark): UserInterface
511
    {
512
        $this->kn_lez = $knMark;
513
        return $this;
514
    }
515
516
    public function getDeletionMark(): int
517
    {
518
        return $this->delmark;
519
    }
520
521
    public function setDeletionMark(int $deletionMark): UserInterface
522
    {
523
        $this->delmark = $deletionMark;
524
        return $this;
525
    }
526
527
    public function isVacationMode(): bool
528
    {
529
        return $this->vac_active;
530
    }
531
532
    public function setVacationMode(bool $vacationMode): UserInterface
533
    {
534
        $this->vac_active = $vacationMode;
535
        return $this;
536
    }
537
538
    public function getVacationRequestDate(): int
539
    {
540
        return $this->vac_request_date;
541
    }
542
543
    public function setVacationRequestDate(int $date): UserInterface
544
    {
545
        $this->vac_request_date = $date;
546
547
        return $this;
548
    }
549
550
    public function isVacationRequestOldEnough(): bool
551
    {
552
        return $this->isVacationMode() && (time() - $this->getVacationRequestDate() > UserEnum::VACATION_DELAY_IN_SECONDS);
553
    }
554
555
    public function isStorageNotification(): bool
556
    {
557
        return $this->storage_notification;
558
    }
559
560
    public function setStorageNotification(bool $storage_notification): UserInterface
561
    {
562
        $this->storage_notification = $storage_notification;
563
        return $this;
564
    }
565
566
    public function getDescription(): string
567
    {
568
        return $this->description;
569
    }
570
571
    public function setDescription(string $description): UserInterface
572
    {
573
        $this->description = $description;
574
        return $this;
575
    }
576
577
    public function isShowOnlineState(): bool
578
    {
579
        return $this->show_online_status;
580
    }
581
582
    public function setShowOnlineState(bool $showOnlineState): UserInterface
583
    {
584
        $this->show_online_status = $showOnlineState;
585
        return $this;
586
    }
587
588
    public function isShowPmReadReceipt(): bool
589
    {
590
        return $this->show_pm_read_receipt;
591
    }
592
593
    public function setShowPmReadReceipt(bool $showPmReadReceipt): UserInterface
594
    {
595
        $this->show_pm_read_receipt = $showPmReadReceipt;
596
        return $this;
597
    }
598
599
    public function isSaveLogin(): bool
600
    {
601
        return $this->save_login;
602
    }
603
604
    public function setSaveLogin(bool $save_login): UserInterface
605
    {
606
        $this->save_login = $save_login;
607
        return $this;
608
    }
609
610
    public function getFleetFixedDefault(): bool
611
    {
612
        return $this->fleet_fixed_default;
613
    }
614
615
    public function setFleetFixedDefault(bool $fleetFixedDefault): UserInterface
616
    {
617
        $this->fleet_fixed_default = $fleetFixedDefault;
618
        return $this;
619
    }
620
621
    public function getTick(): int
622
    {
623
        return $this->tick;
624
    }
625
626
    public function setTick(int $tick): UserInterface
627
    {
628
        $this->tick = $tick;
629
        return $this;
630
    }
631
632
    public function getUserLayers(): Collection
633
    {
634
        return $this->userLayers;
635
    }
636
637
    public function hasSeen(int $layerId): bool
638
    {
639
        return $this->getUserLayers()->containsKey($layerId);
640
    }
641
642
    public function hasExplored(int $layerId): bool
643
    {
644
        return $this->hasSeen($layerId) && $this->getUserLayers()->get($layerId)->isExplored();
645
    }
646
647
    public function getSessiondata(): string
648
    {
649
        return $this->sessiondata;
650
    }
651
652
    public function setSessiondata(string $sessiondata): UserInterface
653
    {
654
        $this->sessiondata = $sessiondata;
655
        $this->sessiondataUnserialized = null;
656
        return $this;
657
    }
658
659
    public function getPasswordToken(): string
660
    {
661
        return $this->password_token;
662
    }
663
664
    public function setPasswordToken(string $password_token): UserInterface
665
    {
666
        $this->password_token = $password_token;
667
        return $this;
668
    }
669
670
    public function getPrestige(): int
671
    {
672
        return $this->prestige;
673
    }
674
675
    public function setPrestige(int $prestige): UserInterface
676
    {
677
        $this->prestige = $prestige;
678
        return $this;
679
    }
680
681
    public function getStartPage(): ?string
682
    {
683
        return $this->start_page;
684
    }
685
686
    public function setStartPage(?string $startPage): UserInterface
687
    {
688
        $this->start_page = $startPage;
689
        return $this;
690
    }
691
692
    public function getRpgBehavior(): UserRpgBehaviorEnum
693
    {
694
        return $this->rpg_behavior;
695
    }
696
697
    public function setRpgBehavior(UserRpgBehaviorEnum $rpgBehavior): UserInterface
698
    {
699
        $this->rpg_behavior = $rpgBehavior;
700
        return $this;
701
    }
702
703
    public function getDeals(): bool
704
    {
705
        return $this->deals;
706
    }
707
708
    public function setDeals(bool $deals): UserInterface
709
    {
710
        $this->deals = $deals;
711
        return $this;
712
    }
713
714
    public function getLastBoarding(): ?int
715
    {
716
        return $this->last_boarding;
717
    }
718
719
    public function setLastBoarding(int $lastBoarding): UserInterface
720
    {
721
        $this->last_boarding = $lastBoarding;
722
        return $this;
723
    }
724
725
    public function isOnline(): bool
726
    {
727
        return !($this->getLastAction() < time() - GameEnum::USER_ONLINE_PERIOD);
728
    }
729
730
    public function getAlliance(): ?AllianceInterface
731
    {
732
        return $this->alliance;
733
    }
734
735
    public function setAlliance(?AllianceInterface $alliance): UserInterface
736
    {
737
        $this->alliance = $alliance;
738
        return $this;
739
    }
740
741
    public function setAllianceId(?int $allianceId): UserInterface
742
    {
743
        $this->allys_id = $allianceId;
744
        return $this;
745
    }
746
747
    public function getSessionDataUnserialized(): array
748
    {
749
        if ($this->sessiondataUnserialized === null) {
750
            $this->sessiondataUnserialized = unserialize($this->getSessionData());
751
            if (!is_array($this->sessiondataUnserialized)) {
752
                $this->sessiondataUnserialized = [];
753
            }
754
        }
755
        return $this->sessiondataUnserialized;
756
    }
757
758
    public function isContactable(): bool
759
    {
760
        return $this->getId() != UserEnum::USER_NOONE;
761
    }
762
763
    public function hasAward(int $awardId): bool
764
    {
765
        return $this->awards->containsKey($awardId) === true;
766
    }
767
768
    public function hasStationsNavigation(): bool
769
    {
770
        if ($this->isNpc()) {
771
            return true;
772
        }
773
774
        return $this->hasAward(UserAwardEnum::RESEARCHED_STATIONS);
775
    }
776
777
    public function isNpc(): bool
778
    {
779
        return $this->getId() < UserEnum::USER_FIRST_ID;
780
    }
781
782
    public function getUserLock(): ?UserLockInterface
783
    {
784
        return $this->userLock;
785
    }
786
787
    public function __toString(): string
788
    {
789
        return sprintf('userName: %s', $this->getName());
790
    }
791
792
    public function hasTranslation(): bool
793
    {
794
        $text = $this->getDescription();
795
        return strpos($text, '[translate]') !== false && strpos($text, '[/translate]') !== false;
796
    }
797
}
798