Passed
Branch develop (cb87a6)
by BENARD
05:06
created

Team::getGameRank1()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 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\SearchFilter;
8
use ApiPlatform\Core\Serializer\Filter\GroupFilter;
9
use Doctrine\Common\Collections\ArrayCollection;
10
use Doctrine\Common\Collections\Collection;
11
use Doctrine\ORM\Mapping as ORM;
12
use Knp\DoctrineBehaviors\Contract\Entity\SluggableInterface;
13
use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
14
use Knp\DoctrineBehaviors\Model\Sluggable\SluggableTrait;
15
use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
16
use Symfony\Component\Validator\Constraints as Assert;
17
use VideoGamesRecords\CoreBundle\Model\Entity\RankCupTrait;
18
use VideoGamesRecords\CoreBundle\Model\Entity\RankMedalTrait;
19
use VideoGamesRecords\CoreBundle\Model\Entity\RankPointGameTrait;
20
use VideoGamesRecords\CoreBundle\Model\Entity\RankPointChartTrait;
21
/**
22
 * Team
23
 *
24
 * @ORM\Table(name="vgr_team")
25
 * @ORM\Entity(repositoryClass="VideoGamesRecords\CoreBundle\Repository\TeamRepository")
26
 * @ORM\EntityListeners({"VideoGamesRecords\CoreBundle\EventListener\Entity\TeamListener"})
27
 * @ApiResource(attributes={"order"={"libTeam"}})
28
 * @ApiFilter(
29
 *     SearchFilter::class,
30
 *     properties={
31
 *          "libTeam": "partial"
32
 *      }
33
 * )
34
 * @ApiFilter(
35
 *     GroupFilter::class,
36
 *     arguments={
37
 *         "parameterName": "groups",
38
 *         "overrideDefaultGroups": false,
39
 *         "whitelist": {
40
 *             "team.rank.pointChart",
41
 *             "team.rank.pointGame",
42
 *             "team.rank.medal",
43
 *             "team.rank.cup",
44
 *             "team.rank.badge",
45
 *             "team.players"
46
 *         }
47
 *     }
48
 * )
49
 */
50
class Team implements SluggableInterface, TimestampableInterface
51
{
52
    use TimestampableTrait;
53
    use SluggableTrait;
54
    use RankCupTrait;
55
    use RankMedalTrait;
56
    use RankPointGameTrait;
57
    use RankPointChartTrait;
58
59
    const STATUS_OPENED = 'OPENED';
60
    const STATUS_CLOSED = 'CLOSED';
61
62
    const NUM_ITEMS = 20;
63
64
    /**
65
     * @var integer
66
     *
67
     * @ORM\Column(name="id", type="integer")
68
     * @ORM\Id
69
     * @ORM\GeneratedValue(strategy="IDENTITY")
70
     */
71
    private $id;
72
73
    /**
74
     * @var string
75
     *
76
     * @Assert\NotBlank()
77
     * @Assert\Length(min="5", max="50")
78
     * @ORM\Column(name="libTeam", type="string", length=50, nullable=false)
79
     */
80
    private $libTeam;
81
82
    /**
83
     * @var string
84
     *
85
     * @Assert\NotBlank()
86
     * @Assert\Length(min="2", max="4")
87
     * @ORM\Column(name="tag", type="string", length=10, nullable=false)
88
     */
89
    private $tag;
90
91
    /**
92
     * @var string
93
     *
94
     * @Assert\Length(max="255")
95
     * @Assert\Url(
96
     *    protocols = {"http", "https"}
97
     * )
98
     * @ORM\Column(name="siteWeb", type="string", length=255, nullable=true)
99
     */
100
    private $siteWeb;
101
102
    /**
103
     * @var string
104
     *
105
     * @ORM\Column(name="logo", type="string", length=30, nullable=false)
106
     */
107
    private $logo = 'default.jpg';
108
109
    /**
110
     * @var string
111
     *
112
     * @ORM\Column(name="commentaire", type="text", nullable=true)
113
     */
114
    private $commentaire;
115
116
    /**
117
     * @var string
118
     *
119
     * @Assert\Choice({"CLOSED", "OPENED"})
120
     *
121
     * @ORM\Column(name="status", type="string", nullable=false)
122
     */
123
    private $status = self::STATUS_CLOSED;
124
125
    /**
126
     * @var integer
127
     *
128
     * @ORM\Column(name="nbPlayer", type="integer", nullable=false)
129
     */
130
    private $nbPlayer = 0;
131
132
    /**
133
     * @var integer
134
     *
135
     * @ORM\Column(name="nbGame", type="integer", nullable=false)
136
     */
137
    private $nbGame = 0;
138
139
    /**
140
     * @var integer
141
     *
142
     * @ORM\Column(name="pointBadge", type="integer", nullable=false)
143
     */
144
    private $pointBadge = 0;
145
146
    /**
147
     * @var integer
148
     *
149
     * @ORM\Column(name="rankBadge", type="integer", nullable=true)
150
     */
151
    private $rankBadge;
152
153
    /**
154
     * @var integer
155
     *
156
     * @ORM\Column(name="nbMasterBadge", type="integer", nullable=false)
157
     */
158
    private $nbMasterBadge = 0;
159
160
    /**
161
     * @ORM\OneToMany(targetEntity="VideoGamesRecords\CoreBundle\Entity\Player", mappedBy="team")
162
     * @ORM\OrderBy({"pseudo" = "ASC"})
163
     */
164
    private $players;
165
166
    /**
167
     * @ORM\OneToMany(targetEntity="VideoGamesRecords\CoreBundle\Entity\TeamGame", mappedBy="team")
168
     */
169
    private $teamGame;
170
171
    /**
172
     * @ORM\OneToMany(targetEntity="VideoGamesRecords\CoreBundle\Entity\TeamBadge", mappedBy="team")
173
     */
174
    private $teamBadge;
175
176
    /**
177
     * @var Player
178
     *
179
     * @Assert\NotNull
180
     * @ORM\ManyToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\Player")
181
     * @ORM\JoinColumns({
182
     *   @ORM\JoinColumn(name="idLeader", referencedColumnName="id")
183
     * })
184
     */
185
    private $leader;
186
187
    /**
188
     * Constructor
189
     */
190
    public function __construct()
191
    {
192
        $this->players = new ArrayCollection();
193
        $this->teamGame = new ArrayCollection();
194
    }
195
196
    /**
197
     * @return string
198
     */
199
    public function __toString()
200
    {
201
        return sprintf('%s [%s]', $this->getLibTeam(), $this->id);
202
    }
203
204
205
    /**
206
     * Set id
207
     * @param integer $id
208
     * @return Team
209
     */
210
    public function setId(int $id)
211
    {
212
        $this->id = $id;
213
        return $this;
214
    }
215
216
    /**
217
     * Get id
218
     *
219
     * @return integer
220
     */
221
    public function getId()
222
    {
223
        return $this->id;
224
    }
225
226
    /**
227
     * Set libTeam
228
     * @param string $libTeam
229
     * @return Team
230
     */
231
    public function setLibTeam(string $libTeam)
232
    {
233
        $this->libTeam = $libTeam;
234
235
        return $this;
236
    }
237
238
    /**
239
     * Get libTeam
240
     *
241
     * @return string
242
     */
243
    public function getLibTeam()
244
    {
245
        return $this->libTeam;
246
    }
247
248
    /**
249
     * Set tag
250
     * @param string $tag
251
     * @return Team
252
     */
253
    public function setTag(string $tag)
254
    {
255
        $this->tag = $tag;
256
257
        return $this;
258
    }
259
260
    /**
261
     * Get tag
262
     *
263
     * @return string
264
     */
265
    public function getTag()
266
    {
267
        return $this->tag;
268
    }
269
270
    /**
271
     * Set leader
272
     * @param Player|null $leader
273
     * @return Team
274
     */
275
    public function setLeader(Player $leader = null)
276
    {
277
        $this->leader = $leader;
278
279
        return $this;
280
    }
281
282
    /**
283
     * Get leader
284
     * @return Player
285
     */
286
    public function getLeader()
287
    {
288
        return $this->leader;
289
    }
290
291
    /**
292
     * Set siteWeb
293
     * @param string $siteWeb
294
     * @return Team
295
     */
296
    public function setSiteWeb(string $siteWeb)
297
    {
298
        $this->siteWeb = $siteWeb;
299
300
        return $this;
301
    }
302
303
    /**
304
     * Get siteWeb
305
     *
306
     * @return string
307
     */
308
    public function getSiteWeb()
309
    {
310
        return $this->siteWeb;
311
    }
312
313
    /**
314
     * Set logo
315
     * @param string $logo
316
     * @return Team
317
     */
318
    public function setLogo(string $logo)
319
    {
320
        $this->logo = $logo;
321
322
        return $this;
323
    }
324
325
    /**
326
     * Get logo
327
     *
328
     * @return string
329
     */
330
    public function getLogo()
331
    {
332
        return $this->logo;
333
    }
334
335
    /**
336
     * Set commentaire
337
     * @param string $commentaire
338
     * @return Team
339
     */
340
    public function setCommentaire(string $commentaire)
341
    {
342
        $this->commentaire = $commentaire;
343
344
        return $this;
345
    }
346
347
    /**
348
     * Get commentaire
349
     *
350
     * @return string
351
     */
352
    public function getCommentaire()
353
    {
354
        return $this->commentaire;
355
    }
356
357
    /**
358
     * Set status
359
     * @param string $status
360
     * @return Team
361
     */
362
    public function setStatus(string $status)
363
    {
364
        $this->status = $status;
365
366
        return $this;
367
    }
368
369
    /**
370
     * Get status
371
     *
372
     * @return string
373
     */
374
    public function getStatus()
375
    {
376
        return $this->status;
377
    }
378
379
    /**
380
     * Set nbPlayer
381
     * @param integer $nbPlayer
382
     * @return Team
383
     */
384
    public function setNbPlayer(int $nbPlayer)
385
    {
386
        $this->nbPlayer = $nbPlayer;
387
388
        return $this;
389
    }
390
391
    /**
392
     * Get nbPlayer
393
     *
394
     * @return integer
395
     */
396
    public function getNbPlayer()
397
    {
398
        return $this->nbPlayer;
399
    }
400
401
    /**
402
     * Set nbGame
403
     * @param integer $nbGame
404
     * @return Team
405
     */
406
    public function setNbGame(int $nbGame)
407
    {
408
        $this->nbGame = $nbGame;
409
410
        return $this;
411
    }
412
413
    /**
414
     * Get nbGame
415
     *
416
     * @return integer
417
     */
418
    public function getNbGame()
419
    {
420
        return $this->nbGame;
421
    }
422
423
    /**
424
     * Set pointBadge
425
     * @param integer $pointBadge
426
     * @return Team
427
     */
428
    public function setPointBadge(int $pointBadge)
429
    {
430
        $this->pointBadge = $pointBadge;
431
432
        return $this;
433
    }
434
435
    /**
436
     * Get pointBadge
437
     *
438
     * @return integer
439
     */
440
    public function getPointBadge()
441
    {
442
        return $this->pointBadge;
443
    }
444
445
    /**
446
     * Set rankBadge
447
     * @param integer $rankBadge
448
     * @return Team
449
     */
450
    public function setRankBadge(int $rankBadge)
451
    {
452
        $this->rankBadge = $rankBadge;
453
454
        return $this;
455
    }
456
457
    /**
458
     * Get rankBadge
459
     *
460
     * @return integer
461
     */
462
    public function getRankBadge()
463
    {
464
        return $this->rankBadge;
465
    }
466
467
    /**
468
     * Set nbMasterBadge
469
     * @param integer $nbMasterBadge
470
     * @return Team
471
     */
472
    public function setNbMasterBadge(int $nbMasterBadge)
473
    {
474
        $this->nbMasterBadge = $nbMasterBadge;
475
476
        return $this;
477
    }
478
479
    /**
480
     * Get nbMasterBadge
481
     *
482
     * @return integer
483
     */
484
    public function getNbMasterBadge()
485
    {
486
        return $this->nbMasterBadge;
487
    }
488
489
    /**
490
     * @return Collection
491
     */
492
    public function getPlayers(): Collection
493
    {
494
        return $this->players;
495
    }
496
497
    /**
498
     * @return Collection
499
     */
500
    public function getTeamGame(): Collection
501
    {
502
        return $this->teamGame;
503
    }
504
505
    /**
506
     * @return mixed
507
     */
508
    public function getTeamBadge()
509
    {
510
        return $this->teamBadge;
511
    }
512
513
    /**
514
     * @return bool
515
     */
516
    public function isOpened(): bool
517
    {
518
        return ($this->getStatus() == self::STATUS_OPENED);
519
    }
520
521
    /**
522
     * @return string[]
523
     */
524
    public function getSluggableFields(): array
525
    {
526
        return ['libTeam'];
527
    }
528
529
    /**
530
     * @return array
531
     */
532
    public static function getStatusChoices()
533
    {
534
        return [
535
            self::STATUS_CLOSED => self::STATUS_CLOSED,
536
            self::STATUS_OPENED => self::STATUS_OPENED,
537
        ];
538
    }
539
}
540