Passed
Branch develop (177155)
by BENARD
05:17
created

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