Passed
Push — develop ( 574080...0f5d99 )
by BENARD
04:30
created

Player::setLastDisplayLostPosition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
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 Gedmo\Timestampable\Traits\TimestampableEntity;
14
use Knp\DoctrineBehaviors\Contract\Entity\SluggableInterface;
15
use Knp\DoctrineBehaviors\Model\Sluggable\SluggableTrait;
16
use Symfony\Component\Validator\Constraints as Assert;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Validator\Constraints was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use VideoGamesRecords\CoreBundle\Model\Entity\AverageChartRankTrait;
18
use VideoGamesRecords\CoreBundle\Model\Entity\AverageGameRankTrait;
19
use VideoGamesRecords\CoreBundle\Model\Entity\NbChartProvenTrait;
20
use VideoGamesRecords\CoreBundle\Model\Entity\NbChartTrait;
21
use VideoGamesRecords\CoreBundle\Model\Entity\NbGameTrait;
22
use VideoGamesRecords\CoreBundle\Model\Entity\Player\PlayerCommunicationDataTrait;
23
use VideoGamesRecords\CoreBundle\Model\Entity\Player\PlayerPersonalDataTrait;
24
use VideoGamesRecords\CoreBundle\Model\Entity\RankCupTrait;
25
use VideoGamesRecords\CoreBundle\Model\Entity\RankMedalTrait;
26
use VideoGamesRecords\CoreBundle\Model\Entity\RankPointBadgeTrait;
27
use VideoGamesRecords\CoreBundle\Model\Entity\RankPointChartTrait;
28
use VideoGamesRecords\CoreBundle\Model\Entity\RankPointGameTrait;
29
30
/**
31
 * Player
32
 *
33
* @ORM\Table(
34
 *     name="vgr_player",
35
 *     indexes={
36
 *         @ORM\Index(name="idx_pointGame", columns={"pointGame"}),
37
 *         @ORM\Index(name="idx_chartRank", columns={"chartRank0", "chartRank1", "chartRank2", "chartRank3"}),
38
 *         @ORM\Index(name="idx_gameRank", columns={"gameRank0", "gameRank1", "gameRank2", "gameRank3"}),
39
 *     }
40
 * )
41
 * @ORM\Entity(repositoryClass="VideoGamesRecords\CoreBundle\Repository\PlayerRepository")
42
 * @ORM\EntityListeners({"VideoGamesRecords\CoreBundle\EventListener\Entity\PlayerListener"})
43
 * @ApiResource(attributes={"order"={"pseudo"}})
44
 * @ApiFilter(
45
 *     SearchFilter::class,
46
 *     properties={
47
 *          "pseudo": "partial",
48
 *          "user.enabled": "exact",
49
 *      }
50
 * )
51
 * @ApiFilter(
52
 *     GroupFilter::class,
53
 *     arguments={
54
 *          "parameterName": "groups",
55
 *          "overrideDefaultGroups": true,
56
 *          "whitelist": {
57
 *              "player.read",
58
 *              "player.team",
59
 *              "player.country",
60
 *              "country.read",
61
 *              "player.pointChart",
62
 *              "player.medal",
63
 *              "player.user_id",
64
 *              "team.read.mini",
65
 *            "player.status",
66
 *              "player.status.read"
67
 *          }
68
 *     }
69
 * )
70
 * @ApiFilter(
71
 *     OrderFilter::class,
72
 *     properties={
73
 *          "id":"ASC",
74
 *          "pseudo" : "ASC",
75
 *          "createdAt": "DESC",
76
 *          "nbConnexion": "DESC",
77
 *          "lastLogin": "DESC",
78
 *          "nbForumMessage": "DESC"
79
 *     },
80
 *     arguments={"orderParameterName"="order"}
81
 * )
82
 */
83
class Player implements SluggableInterface
84
{
85
    use TimestampableEntity;
86
    use SluggableTrait;
87
    use RankCupTrait;
88
    use RankMedalTrait;
89
    use RankPointBadgeTrait;
90
    use RankPointChartTrait;
91
    use RankPointGameTrait;
92
    use AverageChartRankTrait;
93
    use AverageGameRankTrait;
94
    use PlayerCommunicationDataTrait;
95
    use PlayerPersonalDataTrait;
96
    use NbChartTrait;
97
    use NbChartProvenTrait;
98
    use NbGameTrait;
99
100
    /**
101
     * @ORM\Column(name="user_id", type="integer")
102
     */
103
    private int $user_id;
104
105
    /**
106
     * @ORM\Column(name="id", type="integer")
107
     * @ORM\Id
108
     */
109
    private ?int $id = null;
110
111
    /**
112
     * @Assert\Length(min="3",max="50")
113
     * @ORM\Column(name="pseudo", type="string", length=50, nullable=false, unique=true)
114
     */
115
    private string $pseudo;
116
117
    /**
118
     * @ORM\Column(name="avatar", type="string", length=100, nullable=false, options={"default":"default.jpg"})
119
     */
120
    private string $avatar = 'default.jpg';
121
122
    /**
123
     * @ORM\Column(name="gamerCard", type="string", length=50, nullable=true)
124
     */
125
    private ?string $gamerCard;
126
127
    /**
128
     * @ORM\Column(name="rankProof", type="integer", nullable=false, options={"default" : 0})
129
     */
130
    private int $rankProof = 0;
131
132
    /**
133
     * @ORM\Column(name="rankCountry", type="integer", nullable=false, options={"default" : 0})
134
     */
135
    private int $rankCountry = 0;
136
137
    /**
138
     * @ORM\Column(name="nbChartMax", type="integer", nullable=false, options={"default" : 0})
139
     */
140
    private int $nbChartMax = 0;
141
142
    /**
143
     * @ORM\Column(name="nbChartWithPlatform", type="integer", nullable=false, options={"default" : 0})
144
     */
145
    private int $nbChartWithPlatform = 0;
146
147
    /**
148
     * @ORM\Column(name="nbChartDisabled", type="integer", nullable=false, options={"default" : 0})
149
     */
150
    private int $nbChartDisabled = 0;
151
152
    /**
153
     * @ORM\Column(name="nbMasterBadge", type="integer", nullable=false, options={"default" : 0})
154
     */
155
    private int $nbMasterBadge = 0;
156
157
    /**
158
     * @ORM\Column(name="last_login",type="datetime", nullable=true)
159
     */
160
    protected ?DateTime $lastLogin = null;
161
162
    /**
163
     * @ORM\Column(name="nbConnexion", type="integer", nullable=false)
164
     */
165
    protected int $nbConnexion = 0;
166
167
    /**
168
     * @ORM\Column(name="boolMaj", type="boolean", nullable=false, options={"default":0})
169
     */
170
    private bool $boolMaj = false;
171
172
    /**
173
     * @ORM\ManyToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\Team", inversedBy="players")
174
     * @ORM\JoinColumns({
175
     *   @ORM\JoinColumn(name="idTeam", referencedColumnName="id", nullable=true, onDelete="SET NULL")
176
     * })
177
     */
178
    private ?Team $team;
179
180
    /**
181
     * @ORM\Column(name="lastDisplayLostPosition", type="datetime", nullable=true)
182
     */
183
    protected ?DateTime $lastDisplayLostPosition;
184
185
    /**
186
     * @ORM\ManyToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\PlayerStatus")
187
     * @ORM\JoinColumns({
188
     *   @ORM\JoinColumn(name="idStatus", referencedColumnName="id", nullable=false)
189
     * })
190
     */
191
    private PlayerStatus $status;
192
193
194
    /**
195
     * @return string
196
     */
197
    public function __toString()
198
    {
199
        return sprintf('%s [%s]', $this->getPseudo(), $this->getId());
200
    }
201
202
    /**
203
     * Set id
204
     *
205
     * @param integer $id
206
     * @return $this
207
     */
208
    public function setId(int $id): Player
209
    {
210
        $this->id = $id;
211
        return $this;
212
    }
213
214
    /**
215
     * Get id
216
     * @return int|null
217
     */
218
    public function getId(): ?int
219
    {
220
        return $this->id;
221
    }
222
223
    /**
224
     * Set pseudo
225
     *
226
     * @param string $pseudo
227
     * @return $this
228
     */
229
    public function setPseudo(string $pseudo): Player
230
    {
231
        $this->pseudo = $pseudo;
232
233
        return $this;
234
    }
235
236
    /**
237
     * Get pseudo
238
     *
239
     * @return string
240
     */
241
    public function getPseudo(): string
242
    {
243
        return $this->pseudo;
244
    }
245
246
    /**
247
     * Set avatar
248
     *
249
     * @param string $avatar
250
     * @return $this
251
     */
252
    public function setAvatar(string $avatar): Player
253
    {
254
        $this->avatar = $avatar;
255
256
        return $this;
257
    }
258
259
    /**
260
     * Get avatar
261
     *
262
     * @return string
263
     */
264
    public function getAvatar(): string
265
    {
266
        return $this->avatar;
267
    }
268
269
    /**
270
     * Set gamerCard
271
     *
272
     * @param string $gamerCard
273
     * @return $this
274
     */
275
    public function setGamerCard(string $gamerCard): Player
276
    {
277
        $this->gamerCard = $gamerCard;
278
279
        return $this;
280
    }
281
282
    /**
283
     * Get gamerCard
284
     * @return string|null
285
     */
286
    public function getGamerCard(): ?string
287
    {
288
        return $this->gamerCard;
289
    }
290
291
292
293
    /**
294
     * Set rankProof
295
     *
296
     * @param integer $rankProof
297
     * @return Player
298
     */
299
    public function setRankProof(int $rankProof): Player
300
    {
301
        $this->rankProof = $rankProof;
302
303
        return $this;
304
    }
305
306
    /**
307
     * Get rankProof
308
     * @return int|null
309
     */
310
    public function getRankProof(): ?int
311
    {
312
        return $this->rankProof;
313
    }
314
315
316
    /**
317
     * Set rankCountry
318
     *
319
     * @param integer $rankCountry
320
     * @return Player
321
     */
322
    public function setRankCountry(int $rankCountry): Player
323
    {
324
        $this->rankCountry = $rankCountry;
325
326
        return $this;
327
    }
328
329
    /**
330
     * Get rankCountry
331
     * @return int|null
332
     */
333
    public function getRankCountry(): ?int
334
    {
335
        return $this->rankCountry;
336
    }
337
338
    /**
339
     * Set nbChartMax
340
     *
341
     * @param integer $nbChartMax
342
     * @return Player
343
     */
344
    public function setNbChartMax(int $nbChartMax): Player
345
    {
346
        $this->nbChartMax = $nbChartMax;
347
348
        return $this;
349
    }
350
351
    /**
352
     * Get nbChartMax
353
     *
354
     * @return integer
355
     */
356
    public function getNbChartMax(): int
357
    {
358
        return $this->nbChartMax;
359
    }
360
361
    /**
362
     * Set nbChartWithPlatform
363
     *
364
     * @param integer $nbChartWithPlatform
365
     * @return Player
366
     */
367
    public function setNbChartWithPlatform(int $nbChartWithPlatform): Player
368
    {
369
        $this->nbChartWithPlatform = $nbChartWithPlatform;
370
371
        return $this;
372
    }
373
374
    /**
375
     * Get nbChartWithPlatform
376
     *
377
     * @return integer
378
     */
379
    public function getNbChartWithPlatform(): int
380
    {
381
        return $this->nbChartWithPlatform;
382
    }
383
384
    /**
385
     * Set nbChartDisabled
386
     *
387
     * @param integer $nbChartDisabled
388
     * @return Player
389
     */
390
    public function setNbChartDisabled(int $nbChartDisabled): Player
391
    {
392
        $this->nbChartDisabled = $nbChartDisabled;
393
394
        return $this;
395
    }
396
397
    /**
398
     * Get nbChartDisabled
399
     *
400
     * @return integer
401
     */
402
    public function getNbChartDisabled(): int
403
    {
404
        return $this->nbChartDisabled;
405
    }
406
407
    /**
408
     * Set nbMasterBadge
409
     *
410
     * @param integer $nbMasterBadge
411
     * @return Player
412
     */
413
    public function setNbMasterBadge(int $nbMasterBadge): Player
414
    {
415
        $this->nbMasterBadge = $nbMasterBadge;
416
417
        return $this;
418
    }
419
420
    /**
421
     * Get nbMasterBadge
422
     *
423
     * @return integer
424
     */
425
    public function getNbMasterBadge(): int
426
    {
427
        return $this->nbMasterBadge;
428
    }
429
430
431
    /**
432
     * @return DateTime|null
433
     */
434
    public function getLastLogin(): ?DateTime
435
    {
436
        return $this->lastLogin;
437
    }
438
439
    /**
440
     * @param DateTime|null $time
441
     * @return Player
442
     */
443
    public function setLastLogin(DateTime $time = null) : Player
444
    {
445
        $this->lastLogin = $time;
446
        return $this;
447
    }
448
449
    /**
450
     * @return int
451
     */
452
    public function getUserId(): int
453
    {
454
        return $this->user_id;
455
    }
456
457
    /**
458
     * @param $userId
459
     * @return Player
460
     */
461
    public function setUserId($userId): Player
462
    {
463
        $this->user_id = $userId;
464
        return $this;
465
    }
466
467
468
    /**
469
     * Set Team
470
     * @param Team|null $team
471
     * @return $this
472
     */
473
    public function setTeam(Team $team = null): Player
474
    {
475
        $this->team = $team;
476
477
        return $this;
478
    }
479
480
    /**
481
     * Get team
482
     * @return Team|null
483
     */
484
    public function getTeam(): ?Team
485
    {
486
        return $this->team;
487
    }
488
489
    /**
490
     * @return DateTime|null
491
     */
492
    public function getLastDisplayLostPosition(): ?DateTime
493
    {
494
        return $this->lastDisplayLostPosition;
495
    }
496
497
498
    /**
499
     * @param DateTime|null $lastDisplayLostPosition
500
     * @return $this
501
     */
502
    public function setLastDisplayLostPosition(DateTime $lastDisplayLostPosition = null): Player
503
    {
504
        $this->lastDisplayLostPosition = $lastDisplayLostPosition;
505
        return $this;
506
    }
507
508
    /**
509
     * Set boolMaj
510
     *
511
     * @param bool $boolMaj
512
     * @return $this
513
     */
514
    public function setBoolMaj(bool $boolMaj): Player
515
    {
516
        $this->boolMaj = $boolMaj;
517
518
        return $this;
519
    }
520
521
    /**
522
     * Get boolMaj
523
     *
524
     * @return bool
525
     */
526
    public function getBoolMaj(): bool
527
    {
528
        return $this->boolMaj;
529
    }
530
531
    /**
532
     * Set status
533
     * @param PlayerStatus $status
534
     * @return Player
535
     */
536
    public function setStatus(PlayerStatus $status): Player
537
    {
538
        $this->status = $status;
539
        return $this;
540
    }
541
542
    /**
543
     * Get status
544
     * @return PlayerStatus
545
     */
546
    public function getStatus(): PlayerStatus
547
    {
548
        return $this->status;
549
    }
550
551
    /**
552
     * @return int
553
     */
554
    public function getNbConnexion(): int
555
    {
556
        return $this->nbConnexion;
557
    }
558
559
    /**
560
     * @param int $nbConnexion
561
     * @return Player
562
     */
563
    public function setNbConnexion(int $nbConnexion): Player
564
    {
565
        $this->nbConnexion = $nbConnexion;
566
        return $this;
567
    }
568
569
    /**
570
     * Returns an array of the fields used to generate the slug.
571
     *
572
     * @return string[]
573
     */
574
    public function getSluggableFields(): array
575
    {
576
        return ['pseudo'];
577
    }
578
579
    /**
580
     * @return bool
581
     */
582
    public function isLeader(): bool
583
    {
584
        return ($this->getTeam() !== null) && ($this->getTeam()->getLeader()->getId() === $this->getId());
585
    }
586
587
    /**
588
     * @return string
589
     */
590
    public function getUrl(): string
591
    {
592
        return sprintf(
593
            '%s-player-p%d/index',
594
            $this->getSlug(),
595
            $this->getId()
596
        );
597
    }
598
}
599