Chart   A
last analyzed

Complexity

Total Complexity 33

Size/Duplication

Total Lines 383
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 33
eloc 175
dl 0
loc 383
rs 9.76
c 4
b 0
f 0

30 Methods

Rating   Name   Duplication   Size   Complexity  
A getLibs() 0 3 1
A getStatusPlayer() 0 3 1
A __toString() 0 3 1
A getStatusTeam() 0 3 1
A addPlayerChart() 0 3 1
A setPlayerChartP() 0 3 1
A setId() 0 3 1
A getDefaultName() 0 3 1
A getSluggableFields() 0 3 1
A getUrl() 0 10 1
A getPlayerCharts() 0 3 1
A getId() 0 3 1
A __construct() 0 6 1
A setPlayerChart1() 0 3 1
A setLibChartFr() 0 4 2
A getCompleteName() 0 12 2
A setStatusPlayer() 0 3 1
A setGroup() 0 3 1
A getLibChartFr() 0 3 1
A getPlayerChart1() 0 3 1
A setStatusTeam() 0 3 1
A getName() 0 7 2
A getLibChartEn() 0 3 1
A setIsProofVideoOnly() 0 3 1
A addLib() 0 4 1
A getIsProofVideoOnly() 0 3 1
A getPlayerChartP() 0 3 1
A removeLib() 0 3 1
A getGroup() 0 3 1
A setLibChartEn() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VideoGamesRecords\CoreBundle\Entity;
6
7
use ApiPlatform\Metadata\ApiResource;
8
use ApiPlatform\Metadata\ApiFilter;
9
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
10
use ApiPlatform\Metadata\Get;
11
use ApiPlatform\Metadata\GetCollection;
12
use ApiPlatform\Metadata\Link;
13
use ApiPlatform\OpenApi\Model;
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Doctrine\Common\Collections\Collection;
16
use Doctrine\ORM\Mapping as ORM;
17
use Knp\DoctrineBehaviors\Contract\Entity\SluggableInterface;
18
use Knp\DoctrineBehaviors\Model\Sluggable\SluggableTrait;
19
use Gedmo\Timestampable\Traits\TimestampableEntity;
20
use Symfony\Component\Intl\Locale;
21
use Symfony\Component\Validator\Constraints as Assert;
22
use VideoGamesRecords\CoreBundle\Controller\Chart\GetFormData;
23
use VideoGamesRecords\CoreBundle\Controller\Chart\GetFormDataSimple;
24
use VideoGamesRecords\CoreBundle\Controller\Chart\Player\GetRanking;
25
use VideoGamesRecords\CoreBundle\Controller\Chart\Player\GetRankingDisabled;
26
use VideoGamesRecords\CoreBundle\Controller\Chart\Player\GetRankingPoints as PlayerGetRankingPoints;
27
use VideoGamesRecords\CoreBundle\Controller\Chart\Team\GetRankingPoints as TeamGetRankingPoints;
28
use VideoGamesRecords\CoreBundle\Repository\ChartRepository;
29
use VideoGamesRecords\CoreBundle\Traits\Entity\IsDlcTrait;
30
use VideoGamesRecords\CoreBundle\Traits\Entity\NbPostTrait;
31
use VideoGamesRecords\CoreBundle\ValueObject\ChartStatus;
32
33
#[ORM\Table(name:'vgr_chart')]
34
#[ORM\Entity(repositoryClass: ChartRepository::class)]
35
#[ORM\EntityListeners(["VideoGamesRecords\CoreBundle\EventListener\Entity\ChartListener"])]
36
#[ORM\Index(name: "idx_lib_chart_fr", columns: ["lib_chart_fr"])]
37
#[ORM\Index(name: "idx_lib_chart_en", columns: ["lib_chart_en"])]
38
#[ORM\Index(name: "idx_status_player", columns: ["status_player"])]
39
#[ORM\Index(name: "idx_status_team", columns: ["status_team"])]
40
#[ApiResource(
41
    operations: [
42
        new GetCollection(),
43
        new Get(
44
            normalizationContext: ['groups' =>
45
                ['chart:read', 'chart:libs', 'chart-lib:read', 'chart-lib:type', 'chart-type:read']
46
            ]
47
        ),
48
        new Get(
49
            uriTemplate: '/charts/{id}/form-data',
50
            controller: GetFormData::class,
51
            security: "is_granted('ROLE_PLAYER')",
52
            normalizationContext: ['groups' => [
53
                'chart:read', 'chart:libs', 'chart-lib:read',
54
                'chart-lib:type', 'chart-type:read',
55
                'chart:group', 'group:read',
56
                'chart:player-charts', 'player-chart:read', 'player-chart:chart',
57
                'player-chart:libs', 'player-chart-lib:read',
58
                'player-chart:player', 'player-chart:platform',
59
                'player-chart:status', 'player-chart-status:read']
60
            ],
61
            openapi: new Model\Operation(
62
                summary: 'Fetch chart form data',
63
                description: 'Fetch chart form data'
64
            ),
65
        ),
66
        new Get(
67
            uriTemplate: '/charts/{id}/form-data-simple',
68
            controller: GetFormDataSimple::class,
69
            security: "is_granted('ROLE_PLAYER')",
70
            normalizationContext: ['groups' => [
71
                'player-chart:read', 'player-chart:chart',
72
                'player-chart:libs', 'player-chart-lib:read', 'player-chart-lib:libChart',
73
                'player-chart:player', 'player-chart:platform']
74
            ],
75
            openapi: new Model\Operation(
76
                summary: 'Fetch chart form data',
77
                description: 'Fetch chart form data'
78
            ),
79
        ),
80
        new Get(
81
            uriTemplate: '/charts/{id}/player-ranking',
82
            controller: GetRanking::class,
83
            normalizationContext: ['groups' => [
84
                'player-chart:read',
85
                'player-chart:player', 'player:read', 'player:team', 'team:read', 'player:country', 'country:read',
86
                'player-chart:platform', 'platform:read',
87
                'player-chart:status', 'player-chart-status:read',
88
                'player-chart:proof', 'proof:read', 'prof:video', 'video:read', 'proof:picture', 'picture:read']
89
            ],
90
            openapi: new Model\Operation(
91
                summary: 'Retrieves the player chart leaderboard',
92
                description: 'Retrieves the player chart leaderboard'
93
            ),
94
        ),
95
        new Get(
96
            uriTemplate: '/charts/{id}/player-ranking-disabled',
97
            controller: GetRankingDisabled::class,
98
            normalizationContext: ['groups' => [
99
                'player-chart:read',
100
                'player-chart:player', 'player:read', 'player:team', 'team:read', 'player:country', 'country:read',
101
                'player-chart:platform', 'platform:read',
102
                'player-chart:status', 'player-chart-status:read']
103
            ],
104
            openapi: new Model\Operation(
105
                summary: 'Retrieves the chart disabled scores',
106
                description: 'Retrieves the chart disabled scores',
107
            ),
108
        ),
109
        new Get(
110
            uriTemplate: '/charts/{id}/team-ranking-points',
111
            controller: TeamGetRankingPoints::class,
112
            normalizationContext: ['groups' => [
113
                'team-chart:read', 'team-chart:team', 'team:read']
114
            ],
115
            openapi: new Model\Operation(
116
                summary: 'Retrieves the team chart leaderboard',
117
                description: 'Retrieves the team chart leaderboard'
118
            ),
119
            /*openapiContext: [
120
            'parameters' => [
121
            [
122
            'name' => 'maxRank',
123
            'in' => 'query',
124
            'type' => 'integer',
125
            'required' => false
126
            ]
127
            ]
128
            ]*/
129
        ),
130
        new Get(
131
            uriTemplate: '/charts/{id}/player-ranking-points',
132
            controller: PlayerGetRankingPoints::class,
133
            normalizationContext: ['groups' => [
134
                'player-chart:read', 'player-chart:player', 'player:read',
135
                'player-team', 'team:read',
136
                'player-country', 'country:read']
137
            ],
138
            openapi: new Model\Operation(
139
                summary: 'Retrieves the team chart leaderboard',
140
                description: 'Retrieves the team chart leaderboard'
141
            ),
142
            /*openapiContext: [
143
            'parameters' => [
144
            [
145
            'name' => 'maxRank',
146
            'in' => 'query',
147
            'type' => 'integer',
148
            'required' => false
149
            ],
150
            [
151
            'name' => 'idTeam',
152
            'in' => 'query',
153
            'type' => 'integer',
154
            'required' => false
155
            ]
156
            ]
157
            ]*/
158
        ),
159
    ],
160
    normalizationContext: ['groups' => ['chart:read']]
161
)]
162
#[ApiFilter(
163
    OrderFilter::class,
164
    properties: [
165
        'id' => 'ASC',
166
        'libChartEn' => 'ASC',
167
        'libChartFr' => 'ASC',
168
    ]
169
)]
170
class Chart implements SluggableInterface
171
{
172
    use TimestampableEntity;
173
    use SluggableTrait;
174
    use NbPostTrait;
175
    use IsDlcTrait;
176
177
    #[ORM\Id, ORM\Column, ORM\GeneratedValue]
178
    private ?int $id = null;
179
180
    #[Assert\Length(max: 255)]
181
    #[ORM\Column(length: 255, nullable: false)]
182
    private string $libChartEn = '';
183
184
    #[Assert\Length(max: 255)]
185
    #[ORM\Column(length: 255, nullable: false)]
186
    private string $libChartFr = '';
187
188
    #[ORM\Column(length: 30, nullable: false, options: ['default' => 'NORMAL'])]
189
    private string $statusPlayer = ChartStatus::NORMAL;
190
191
    #[ORM\Column(length: 30, nullable: false, options: ['default' => 'NORMAL'])]
192
    private string $statusTeam = ChartStatus::NORMAL;
193
194
    #[ORM\Column(nullable: false, options: ['default' => false])]
195
    private bool $isProofVideoOnly = false;
196
197
    #[Assert\NotNull]
198
    #[ORM\ManyToOne(targetEntity: Group::class, inversedBy: 'charts')]
199
    #[ORM\JoinColumn(name:'group_id', referencedColumnName:'id', nullable:false, onDelete:'CASCADE')]
200
    private Group $group;
201
202
    /**
203
     * @var Collection<int, ChartLib>
204
     */
205
    #[ORM\OneToMany(targetEntity: ChartLib::class, cascade:['persist', 'remove'], mappedBy: 'chart', orphanRemoval: true)]
206
    private Collection $libs;
207
208
    /**
209
     * @var Collection<int, PlayerChart>
210
     */
211
    #[ORM\OneToMany(targetEntity: PlayerChart::class, mappedBy: 'chart', fetch: 'EXTRA_LAZY')]
212
    private Collection $playerCharts;
213
214
    /**
215
     * Shortcut to playerChart.rank = 1
216
     */
217
    private ?PlayerChart $playerChart1 = null;
218
219
    /**
220
     * Shortcut to playerChart.player = player
221
     */
222
    private ?PlayerChart $playerChartP = null;
223
224
    /**
225
     * @var Collection<int, Proof>
226
     */
227
    #[ORM\OneToMany(targetEntity: Proof::class, cascade:['persist', 'remove'], mappedBy: 'chart', orphanRemoval: true)]
228
    private Collection $proofs;
229
230
    /**
231
     * @var Collection<LostPosition>
232
     */
233
    #[ORM\OneToMany(targetEntity: LostPosition::class, mappedBy: 'chart')]
234
    private Collection $lostPositions;
235
236
    public function __construct()
237
    {
238
        $this->libs = new ArrayCollection();
239
        $this->playerCharts = new ArrayCollection();
240
        $this->lostPositions = new ArrayCollection();
241
        $this->proofs = new ArrayCollection();
242
    }
243
244
    public function __toString()
245
    {
246
        return sprintf('%s [%s]', $this->getDefaultName(), $this->id);
247
    }
248
249
    public function getDefaultName(): ?string
250
    {
251
        return $this->libChartEn;
252
    }
253
254
    public function getName(): ?string
255
    {
256
        $locale = Locale::getDefault();
257
        if ($locale == 'fr') {
258
            return $this->libChartFr;
259
        } else {
260
            return $this->libChartEn;
261
        }
262
    }
263
264
    public function getCompleteName(string $locale = 'en'): string
265
    {
266
        if ($locale == 'fr') {
267
            return $this->getGroup()
268
                    ->getGame()
269
                    ->getLibGameFr() . ' - ' . $this->getGroup()
270
                    ->getLibGroupFr() . ' - ' . $this->getLibChartFr();
271
        } else {
272
            return $this->getGroup()
273
                    ->getGame()
274
                    ->getLibGameEn() . ' - ' . $this->getGroup()
275
                    ->getLibGroupEn() . ' - ' . $this->getLibChartEn();
276
        }
277
    }
278
279
280
    public function setId(int $id): void
281
    {
282
        $this->id = $id;
283
    }
284
285
    public function getId(): ?int
286
    {
287
        return $this->id;
288
    }
289
290
291
    public function setLibChartEn(string $libChartEn): void
292
    {
293
        $this->libChartEn = $libChartEn;
294
    }
295
296
    public function getLibChartEn(): string
297
    {
298
        return $this->libChartEn;
299
    }
300
301
    public function setLibChartFr(?string $libChartFr): void
302
    {
303
        if ($libChartFr) {
304
            $this->libChartFr = $libChartFr;
305
        }
306
    }
307
308
    public function getLibChartFr(): string
309
    {
310
        return $this->libChartFr;
311
    }
312
313
    public function setStatusPlayer(string $statusPlayer): void
314
    {
315
        $this->statusPlayer = $statusPlayer;
316
    }
317
318
    public function getStatusPlayer(): ChartStatus
319
    {
320
        return new ChartStatus($this->statusPlayer);
321
    }
322
323
    public function setStatusTeam(string $statusTeam): void
324
    {
325
        $this->statusTeam = $statusTeam;
326
    }
327
328
    public function getStatusTeam(): ChartStatus
329
    {
330
        return new ChartStatus($this->statusTeam);
331
    }
332
333
    public function getIsProofVideoOnly(): bool
334
    {
335
        return $this->isProofVideoOnly;
336
    }
337
338
    public function setIsProofVideoOnly(bool $isProofVideoOnly): void
339
    {
340
        $this->isProofVideoOnly = $isProofVideoOnly;
341
    }
342
343
    public function getPlayerCharts(): Collection
344
    {
345
        return $this->playerCharts;
346
    }
347
348
    public function addPlayerChart(PlayerChart $playerChart): void
349
    {
350
        $this->playerCharts->add($playerChart);
351
    }
352
353
    public function setGroup(Group $group = null): void
354
    {
355
        $this->group = $group;
356
    }
357
358
    public function getGroup(): Group
359
    {
360
        return $this->group;
361
    }
362
363
    public function addLib(ChartLib $lib): void
364
    {
365
        $lib->setChart($this);
366
        $this->libs[] = $lib;
367
    }
368
369
    public function removeLib(ChartLib $lib): void
370
    {
371
        $this->libs->removeElement($lib);
372
    }
373
374
    public function getLibs(): Collection
375
    {
376
        return $this->libs;
377
    }
378
379
380
    public function setPlayerChart1(?PlayerChart $playerChart1): void
381
    {
382
        $this->playerChart1 = $playerChart1;
383
    }
384
385
    public function getPlayerChart1(): ?PlayerChart
386
    {
387
        return $this->playerChart1;
388
    }
389
390
    public function setPlayerChartP(?PlayerChart $playerChartP): void
391
    {
392
        $this->playerChartP = $playerChartP;
393
    }
394
395
    public function getPlayerChartP(): ?PlayerChart
396
    {
397
        return $this->playerChartP;
398
    }
399
400
    public function getUrl(): string
401
    {
402
        return sprintf(
403
            '%s-game-g%d/%s-group-g%d/%s-chart-c%d/index',
404
            $this->getGroup()->getGame()->getSlug(),
405
            $this->getGroup()->getGame()->getId(),
406
            $this->getGroup()->getSlug(),
407
            $this->getGroup()->getId(),
408
            $this->getSlug(),
409
            $this->getId()
410
        );
411
    }
412
413
    public function getSluggableFields(): array
414
    {
415
        return ['defaultName'];
416
    }
417
}
418