Passed
Branch develop (aa60bf)
by BENARD
05:22
created

Player::setChartRank1()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace VideoGamesRecords\CoreBundle\Entity;
4
5
use ApiPlatform\Core\Annotation\ApiFilter;
6
use ApiPlatform\Core\Annotation\ApiResource;
7
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
8
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
9
use ApiPlatform\Core\Serializer\Filter\GroupFilter;
10
use DateTime;
11
use Doctrine\Common\Collections\Collection;
12
use Doctrine\ORM\Mapping as ORM;
13
use Knp\DoctrineBehaviors\Contract\Entity\SluggableInterface;
14
use Knp\DoctrineBehaviors\Model\Sluggable\SluggableTrait;
15
use Symfony\Component\Validator\Constraints as Assert;
16
use VideoGamesRecords\CoreBundle\Entity\User\UserInterface;
17
use VideoGamesRecords\CoreBundle\Model\Entity\RankCupTrait;
18
use VideoGamesRecords\CoreBundle\Model\Entity\RankMedalTrait;
19
use VideoGamesRecords\CoreBundle\Model\Entity\RankPointChartTrait;
20
use VideoGamesRecords\CoreBundle\Model\Entity\RankPointGameTrait;
21
22
/**
23
 * Player
24
 *
25
 * @ORM\Table(name="vgr_player")
26
 * @ORM\Entity(repositoryClass="VideoGamesRecords\CoreBundle\Repository\PlayerRepository")
27
 * @ApiResource(attributes={"order"={"pseudo"}})
28
 * @ApiFilter(
29
 *     SearchFilter::class,
30
 *     properties={
31
 *          "pseudo": "partial",
32
 *          "user.enabled": "exact",
33
 *      }
34
 * )
35
 * @ApiFilter(
36
 *     GroupFilter::class,
37
 *     arguments={
38
 *          "parameterName": "groups",
39
 *          "overrideDefaultGroups": true,
40
 *          "whitelist": {
41
 *              "player.read",
42
 *              "player.team",
43
 *              "player.country",
44
 *              "country.read",
45
 *              "player.pointChart",
46
 *              "player.medal",
47
 *              "player.user",
48
 *              "vgr.user.read",
49
 *              "team.read.mini",
50
 *              "user.status.read",
51
 *          }
52
 *     }
53
 * )
54
 * @ApiFilter(
55
 *     OrderFilter::class,
56
 *     properties={
57
 *          "id":"ASC",
58
 *          "pseudo" : "ASC",
59
 *          "user.createdAt": "DESC",
60
 *          "user.nbConnexion": "DESC",
61
 *          "user.lastLogin": "DESC",
62
 *          "user.nbForumMessage": "DESC"
63
 *     },
64
 *     arguments={"orderParameterName"="order"}
65
 * )
66
 */
67
class Player implements SluggableInterface
68
{
69
    use SluggableTrait;
70
    use RankCupTrait;
71
    use RankMedalTrait;
72
    use RankPointChartTrait;
73
    use RankPointGameTrait;
74
75
    /**
76
     * @ORM\OneToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\User\UserInterface")
77
     * @ORM\JoinColumn(name="normandie_user_id", referencedColumnName="id")
78
     */
79
    private $user;
80
81
    /**
82
     * @ORM\Column(name="id", type="integer")
83
     * @ORM\Id
84
     * @ORM\GeneratedValue(strategy="IDENTITY")
85
     */
86
    private ?int $id = null;
87
88
    /**
89
     * @Assert\Length(min="3",max="50")
90
     * @ORM\Column(name="pseudo", type="string", length=50, nullable=false, unique=true)
91
     */
92
    private string $pseudo;
93
94
    /**
95
     * @ORM\Column(name="avatar", type="string", length=100, nullable=false)
96
     */
97
    private string $avatar = 'default.jpg';
98
99
    /**
100
     * @ORM\Column(name="gamerCard", type="string", length=50, nullable=true)
101
     */
102
    private ?string $gamerCard;
103
104
    /**
105
     * @ORM\Column(name="pointVGR", type="integer", nullable=false)
106
     */
107
    private int $pointVGR = 0;
108
109
    /**
110
     * @ORM\Column(name="pointBadge", type="integer", nullable=false)
111
     */
112
    private int $pointBadge = 0;
113
114
    /**
115
     * @ORM\Column(name="presentation", type="text", length=65535, nullable=true)
116
     */
117
    private ?string $presentation;
118
119
    /**
120
     * @ORM\Column(name="collection", type="text", length=65535, nullable=true)
121
     */
122
    private ?string $collection;
123
124
    /**
125
     * @ORM\Column(name="rankProof", type="integer", nullable=true)
126
     */
127
    private ?int $rankProof;
128
129
    /**
130
     * @ORM\Column(name="rankBadge", type="integer", nullable=true)
131
     */
132
    private ?int $rankBadge;
133
134
    /**
135
     * @ORM\Column(name="rankCountry", type="integer", nullable=true)
136
     */
137
    private ?int $rankCountry;
138
139
    /**
140
     * @ORM\Column(name="nbGame", type="integer", nullable=false)
141
     */
142
    private int $nbGame = 0;
143
144
    /**
145
     * @ORM\Column(name="nbChart", type="integer", nullable=false)
146
     */
147
    private int $nbChart = 0;
148
149
    /**
150
     * @ORM\Column(name="nbChartProven", type="integer", nullable=false)
151
     */
152
    private int $nbChartProven = 0;
153
154
    /**
155
     * @ORM\Column(name="nbChartDisabled", type="integer", nullable=false)
156
     */
157
    private int $nbChartDisabled = 0;
158
159
    /**
160
     * @ORM\Column(name="nbMasterBadge", type="integer", nullable=false)
161
     */
162
    private int $nbMasterBadge = 0;
163
164
    /**
165
     * @ORM\Column(name="birthDate", type="date", nullable=true)
166
     */
167
    protected ?DateTime $birthDate;
168
169
    /**
170
     * @ORM\Column(name="website", type="string", length=255, nullable=true)
171
     */
172
    protected ?string $website;
173
174
    /**
175
     * @ORM\Column(name="youtube", type="string", length=255, nullable=true)
176
     */
177
    protected ?string $youtube;
178
179
    /**
180
     * @ORM\Column(name="twitch", type="string", length=255, nullable=true)
181
     */
182
    protected ?string $twitch;
183
184
    /**
185
     * @ORM\Column(name="gender", type="string", length=1, nullable=false)
186
     */
187
    protected string $gender = 'I';
188
189
    /**
190
     * @ORM\Column(name="displayPersonalInfos", type="boolean", nullable=false)
191
     */
192
    private bool $displayPersonalInfos = false;
193
194
    /**
195
     * @ORM\OneToMany(targetEntity="VideoGamesRecords\CoreBundle\Entity\PlayerPlatform", mappedBy="player")
196
     */
197
    private $playerPlatform;
198
199
    /**
200
     * @ORM\OneToMany(targetEntity="VideoGamesRecords\CoreBundle\Entity\PlayerGame", mappedBy="player")
201
     */
202
    private $playerGame;
203
204
    /**
205
     * @ORM\OneToMany(targetEntity="VideoGamesRecords\CoreBundle\Entity\PlayerGroup", mappedBy="player")
206
     */
207
    private $playerGroup;
0 ignored issues
show
introduced by
The private property $playerGroup is not used, and could be removed.
Loading history...
208
209
    /**
210
     * @ORM\OneToMany(targetEntity="VideoGamesRecords\CoreBundle\Entity\PlayerBadge", mappedBy="player")
211
     */
212
    private $playerBadge;
213
214
    /**
215
     * @ORM\OneToMany(targetEntity="VideoGamesRecords\CoreBundle\Entity\LostPosition", mappedBy="player")
216
     */
217
    private $lostPositions;
218
219
    /**
220
     * @ORM\Column(name="boolMaj", type="boolean", nullable=false, options={"default":0})
221
     */
222
    private $boolMaj = false;
223
224
    /**
225
     * @var Team
226
     *
227
     * @ORM\ManyToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\Team", inversedBy="players")
228
     * @ORM\JoinColumns({
229
     *   @ORM\JoinColumn(name="idTeam", referencedColumnName="id")
230
     * })
231
     */
232
    private $team;
233
234
    /**
235
     * @var Country
236
     *
237
     * @ORM\ManyToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\Country")
238
     * @ORM\JoinColumns({
239
     *   @ORM\JoinColumn(name="idCountry", referencedColumnName="id")
240
     * })
241
     */
242
    protected $country;
243
244
245
    /**
246
     * @ORM\OneToMany(targetEntity="VideoGamesRecords\CoreBundle\Entity\Proof", mappedBy="player")
247
     */
248
    private $proofs;
0 ignored issues
show
introduced by
The private property $proofs is not used, and could be removed.
Loading history...
249
250
    /**
251
     * @ORM\OneToMany(targetEntity="VideoGamesRecords\CoreBundle\Entity\Proof", mappedBy="playerResponding")
252
     */
253
    private $proofRespondings;
0 ignored issues
show
introduced by
The private property $proofRespondings is not used, and could be removed.
Loading history...
254
255
    /**
256
     * @ORM\OneToMany(targetEntity="VideoGamesRecords\CoreBundle\Entity\Rule", mappedBy="player")
257
     */
258
    private $rules;
0 ignored issues
show
introduced by
The private property $rules is not used, and could be removed.
Loading history...
259
260
    /**
261
     * @var DateTime
262
     * @ORM\Column(name="lastDisplayLostPosition", type="datetime", nullable=true)
263
     */
264
    protected $lastDisplayLostPosition;
265
266
    /**
267
     * @return string
268
     */
269
    public function __toString()
270
    {
271
        return sprintf('%s [%s]', $this->getPseudo(), $this->getId());
272
    }
273
274
    /**
275
     * Set id
276
     *
277
     * @param integer $id
278
     * @return $this
279
     */
280
    public function setId(int $id)
281
    {
282
        $this->id = $id;
283
        return $this;
284
    }
285
286
    /**
287
     * Get id
288
     *
289
     * @return integer
290
     */
291
    public function getId()
292
    {
293
        return $this->id;
294
    }
295
296
    /**
297
     * Set pseudo
298
     *
299
     * @param string $pseudo
300
     * @return $this
301
     */
302
    public function setPseudo(string $pseudo)
303
    {
304
        $this->pseudo = $pseudo;
305
306
        return $this;
307
    }
308
309
    /**
310
     * Get pseudo
311
     *
312
     * @return string
313
     */
314
    public function getPseudo()
315
    {
316
        return $this->pseudo;
317
    }
318
319
    /**
320
     * Set avatar
321
     *
322
     * @param string $avatar
323
     * @return $this
324
     */
325
    public function setAvatar(string $avatar)
326
    {
327
        $this->avatar = $avatar;
328
329
        return $this;
330
    }
331
332
    /**
333
     * Get avatar
334
     *
335
     * @return string
336
     */
337
    public function getAvatar()
338
    {
339
        return $this->avatar;
340
    }
341
342
    /**
343
     * Set gamerCard
344
     *
345
     * @param string $gamerCard
346
     * @return $this
347
     */
348
    public function setGamerCard(string $gamerCard)
349
    {
350
        $this->gamerCard = $gamerCard;
351
352
        return $this;
353
    }
354
355
    /**
356
     * Get gamerCard
357
     *
358
     * @return string
359
     */
360
    public function getGamerCard()
361
    {
362
        return $this->gamerCard;
363
    }
364
365
366
    /**
367
     * Set pointVGR
368
     *
369
     * @param integer $pointVGR
370
     * @return $this
371
     */
372
    public function setPointVGR(int $pointVGR)
373
    {
374
        $this->pointVGR = $pointVGR;
375
376
        return $this;
377
    }
378
379
    /**
380
     * Get pointVGR
381
     *
382
     * @return integer
383
     */
384
    public function getPointVGR()
385
    {
386
        return $this->pointVGR;
387
    }
388
389
    /**
390
     * Set pointBadge
391
     *
392
     * @param integer $pointBadge
393
     * @return $this
394
     */
395
    public function setPointBadge(int $pointBadge)
396
    {
397
        $this->pointBadge = $pointBadge;
398
399
        return $this;
400
    }
401
402
    /**
403
     * Get pointBadge
404
     *
405
     * @return integer
406
     */
407
    public function getPointBadge()
408
    {
409
        return $this->pointBadge;
410
    }
411
412
    /**
413
     * Set presentation
414
     *
415
     * @param string|null $presentation
416
     * @return $this
417
     */
418
    public function setPresentation(string $presentation = null)
419
    {
420
        $this->presentation = $presentation;
421
422
        return $this;
423
    }
424
425
    /**
426
     * Get presentation
427
     *
428
     * @return string
429
     */
430
    public function getPresentation()
431
    {
432
        return $this->presentation;
433
    }
434
435
    /**
436
     * Set collection
437
     *
438
     * @param string|null $collection
439
     * @return Player
440
     */
441
    public function setCollection(string $collection = null)
442
    {
443
        $this->collection = $collection;
444
445
        return $this;
446
    }
447
448
    /**
449
     * Get collection
450
     *
451
     * @return string
452
     */
453
    public function getCollection()
454
    {
455
        return $this->collection;
456
    }
457
458
    /**
459
     * Set rankProof
460
     *
461
     * @param integer $rankProof
462
     * @return Player
463
     */
464
    public function setRankProof(int $rankProof)
465
    {
466
        $this->rankProof = $rankProof;
467
468
        return $this;
469
    }
470
471
    /**
472
     * Get rankProof
473
     *
474
     * @return integer
475
     */
476
    public function getRankProof()
477
    {
478
        return $this->rankProof;
479
    }
480
481
    /**
482
     * Set rankBadge
483
     *
484
     * @param integer $rankBadge
485
     * @return Player
486
     */
487
    public function setRankBadge(int $rankBadge)
488
    {
489
        $this->rankBadge = $rankBadge;
490
491
        return $this;
492
    }
493
494
    /**
495
     * Get rankBadge
496
     *
497
     * @return integer
498
     */
499
    public function getRankBadge()
500
    {
501
        return $this->rankBadge;
502
    }
503
504
    /**
505
     * Set rankCountry
506
     *
507
     * @param integer $rankCountry
508
     * @return Player
509
     */
510
    public function setRankCountry(int $rankCountry)
511
    {
512
        $this->rankCountry = $rankCountry;
513
514
        return $this;
515
    }
516
517
    /**
518
     * Get rankCountry
519
     *
520
     * @return integer
521
     */
522
    public function getRankCountry()
523
    {
524
        return $this->rankCountry;
525
    }
526
527
528
    /**
529
     * Set nbGame
530
     *
531
     * @param integer $nbGame
532
     * @return Player
533
     */
534
    public function setNbGame(int $nbGame)
535
    {
536
        $this->nbGame = $nbGame;
537
538
        return $this;
539
    }
540
541
    /**
542
     * Get nbGame
543
     *
544
     * @return integer
545
     */
546
    public function getNbGame()
547
    {
548
        return $this->nbGame;
549
    }
550
551
    /**
552
     * Set nbChart
553
     *
554
     * @param integer $nbChart
555
     * @return Player
556
     */
557
    public function setNbChart(int $nbChart)
558
    {
559
        $this->nbChart = $nbChart;
560
561
        return $this;
562
    }
563
564
    /**
565
     * Get nbChart
566
     *
567
     * @return integer
568
     */
569
    public function getNbChart()
570
    {
571
        return $this->nbChart;
572
    }
573
574
    /**
575
     * Set nbChartProven
576
     *
577
     * @param integer $nbChartProven
578
     * @return Player
579
     */
580
    public function setNbChartProven(int $nbChartProven)
581
    {
582
        $this->nbChartProven = $nbChartProven;
583
584
        return $this;
585
    }
586
587
    /**
588
     * Get nbChartProven
589
     *
590
     * @return integer
591
     */
592
    public function getNbChartProven()
593
    {
594
        return $this->nbChartProven;
595
    }
596
597
    /**
598
     * Set nbChartDisabled
599
     *
600
     * @param integer $nbChartDisabled
601
     * @return Player
602
     */
603
    public function setNbChartDisabled(int $nbChartDisabled)
604
    {
605
        $this->nbChartDisabled = $nbChartDisabled;
606
607
        return $this;
608
    }
609
610
    /**
611
     * Get nbChartDisabled
612
     *
613
     * @return integer
614
     */
615
    public function getNbChartDisabled()
616
    {
617
        return $this->nbChartDisabled;
618
    }
619
620
    /**
621
     * Set nbMasterBadge
622
     *
623
     * @param integer $nbMasterBadge
624
     * @return Player
625
     */
626
    public function setNbMasterBadge(int $nbMasterBadge)
627
    {
628
        $this->nbMasterBadge = $nbMasterBadge;
629
630
        return $this;
631
    }
632
633
    /**
634
     * Get nbMasterBadge
635
     *
636
     * @return integer
637
     */
638
    public function getNbMasterBadge()
639
    {
640
        return $this->nbMasterBadge;
641
    }
642
643
644
    /**
645
     * @return string
646
     */
647
    public function getWebsite()
648
    {
649
        return $this->website;
650
    }
651
652
    /**
653
     * @param string|null $website
654
     * @return $this
655
     */
656
    public function setWebsite(string $website = null)
657
    {
658
        $this->website = $website;
659
        return $this;
660
    }
661
662
    /**
663
     * @return string
664
     */
665
    public function getYoutube()
666
    {
667
        return $this->youtube;
668
    }
669
670
    /**
671
     * @param string|null $youtube
672
     * @return $this
673
     */
674
    public function setYoutube(string $youtube = null)
675
    {
676
        $this->youtube = $youtube;
677
        return $this;
678
    }
679
680
    /**
681
     * @return string
682
     */
683
    public function getTwitch()
684
    {
685
        return $this->twitch;
686
    }
687
688
    /**
689
     * @param string|null $twitch
690
     * @return $this
691
     */
692
    public function setTwitch(string $twitch = null)
693
    {
694
        $this->twitch = $twitch;
695
        return $this;
696
    }
697
698
    /**
699
     * @return DateTime
700
     */
701
    public function getBirthDate()
702
    {
703
        return $this->birthDate;
704
    }
705
706
707
    /**
708
     * @param DateTime|null $birthDate
709
     * @return $this
710
     */
711
    public function setBirthDate(DateTime $birthDate = null)
712
    {
713
        $this->birthDate = $birthDate;
714
        return $this;
715
    }
716
717
    /**
718
     * @return string
719
     */
720
    public function getGender()
721
    {
722
        return $this->gender;
723
    }
724
725
    /**
726
     * @param string $gender
727
     * @return $this
728
     */
729
    public function setGender(string $gender)
730
    {
731
        $this->gender = $gender;
732
        return $this;
733
    }
734
735
    /**
736
     * Set displayPersonalInfos
737
     * @param bool $displayPersonalInfos
738
     * @return $this
739
     */
740
    public function setDisplayPersonalInfos(bool $displayPersonalInfos)
741
    {
742
        $this->displayPersonalInfos = $displayPersonalInfos;
743
744
        return $this;
745
    }
746
747
    /**
748
     * Get DisplayPersonalInfos
749
     * @return bool
750
     */
751
    public function getDisplayPersonalInfos()
752
    {
753
        return $this->displayPersonalInfos;
754
    }
755
756
    /**
757
     * @return UserInterface
758
     */
759
    public function getUser()
760
    {
761
        return $this->user;
762
    }
763
764
    /**
765
     * @param $user
766
     * @return Player
767
     */
768
    public function setUser($user)
769
    {
770
        $this->user = $user;
771
        return $this;
772
    }
773
774
    /**
775
     * @return mixed
776
     */
777
    public function getPlayerPlatform()
778
    {
779
        return $this->playerPlatform;
780
    }
781
782
    /**
783
     * @return mixed
784
     */
785
    public function getPlayerGame()
786
    {
787
        return $this->playerGame;
788
    }
789
790
    /**
791
     * @return mixed
792
     */
793
    public function getPlayerBadge()
794
    {
795
        return $this->playerBadge;
796
    }
797
798
    /**
799
     * Set Team
800
     * @param Team|null $team
801
     * @return $this
802
     */
803
    public function setTeam(Team $team = null)
804
    {
805
        $this->team = $team;
806
807
        return $this;
808
    }
809
810
    /**
811
     * Get team
812
     * @return Team
813
     */
814
    public function getTeam()
815
    {
816
        return $this->team;
817
    }
818
819
    /**
820
     * @return Player
821
     */
822
    public function getPlayer()
823
    {
824
        return $this;
825
    }
826
827
    /**
828
     * @return Country
829
     */
830
    public function getCountry()
831
    {
832
        return $this->country;
833
    }
834
835
    /**
836
     * @param $country
837
     * @return Player
838
     */
839
    public function setCountry($country)
840
    {
841
        $this->country = $country;
842
        return $this;
843
    }
844
845
    /**
846
     * @return Collection
847
     */
848
    public function getLostPositions(): Collection
849
    {
850
        return $this->lostPositions;
851
    }
852
853
    /**
854
     * @return DateTime
855
     */
856
    public function getLastDisplayLostPosition(): ?DateTime
857
    {
858
        return $this->lastDisplayLostPosition;
859
    }
860
861
862
    /**
863
     * @param DateTime|null $lastDisplayLostPosition
864
     * @return $this
865
     */
866
    public function setLastDisplayLostPosition(DateTime $lastDisplayLostPosition = null)
867
    {
868
        $this->lastDisplayLostPosition = $lastDisplayLostPosition;
869
        return $this;
870
    }
871
872
    /**
873
     * Set boolMaj
874
     *
875
     * @param bool $boolMaj
876
     * @return $this
877
     */
878
    public function setBoolMaj(bool $boolMaj)
879
    {
880
        $this->boolMaj = $boolMaj;
881
882
        return $this;
883
    }
884
885
    /**
886
     * Get boolMaj
887
     *
888
     * @return bool
889
     */
890
    public function getBoolMaj()
891
    {
892
        return $this->boolMaj;
893
    }
894
895
    /**
896
     * Returns an array of the fields used to generate the slug.
897
     *
898
     * @return string[]
899
     */
900
    public function getSluggableFields(): array
901
    {
902
        return ['pseudo'];
903
    }
904
905
    /**
906
     * @return bool
907
     */
908
    public function isLeader()
909
    {
910
        return ($this->getTeam() !== null) && ($this->getTeam()->getLeader()->getId() === $this->getId());
911
    }
912
913
    /**
914
     * @return string
915
     */
916
    public function getUrl()
917
    {
918
        return sprintf(
919
            '%s-player-p%d/index',
920
            $this->getSlug(),
921
            $this->getId()
922
        );
923
    }
924
}
925