1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace VideoGamesRecords\CoreBundle\Entity; |
4
|
|
|
|
5
|
|
|
use ApiPlatform\Core\Annotation\ApiFilter; |
6
|
|
|
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter; |
7
|
|
|
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter; |
8
|
|
|
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\RangeFilter; |
9
|
|
|
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter; |
10
|
|
|
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\ExistsFilter; |
11
|
|
|
use ApiPlatform\Core\Serializer\Filter\GroupFilter; |
12
|
|
|
use DateTime; |
13
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
14
|
|
|
use Doctrine\Common\Collections\Collection; |
15
|
|
|
use Doctrine\ORM\Mapping as ORM; |
16
|
|
|
use Gedmo\Timestampable\Traits\TimestampableEntity; |
17
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints as DoctrineAssert; |
18
|
|
|
use VideoGamesRecords\CoreBundle\Traits\Entity\LastUpdateTrait; |
19
|
|
|
use VideoGamesRecords\CoreBundle\Traits\Entity\NbEqualTrait; |
20
|
|
|
use VideoGamesRecords\CoreBundle\Traits\Entity\Player\PlayerTrait; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* PlayerChart |
24
|
|
|
* |
25
|
|
|
* @ORM\Table( |
26
|
|
|
* name="vgr_player_chart", |
27
|
|
|
* uniqueConstraints={ |
28
|
|
|
* @ORM\UniqueConstraint(name="unq_player_chart", columns={"idPlayer", "idChart"}) |
29
|
|
|
* }, |
30
|
|
|
* indexes={ |
31
|
|
|
* @ORM\Index(name="idx_rank", columns={"`rank`"}), |
32
|
|
|
* @ORM\Index(name="idx_point_chart", columns={"pointChart"}), |
33
|
|
|
* @ORM\Index(name="idx_top_score", columns={"isTopScore"}), |
34
|
|
|
* @ORM\Index(name="idx_last_update_player", columns={"lastUpdate", "idPlayer"}) |
35
|
|
|
* } |
36
|
|
|
* ) |
37
|
|
|
* @DoctrineAssert\UniqueEntity(fields={"chart", "player"}, message="A score already exists for the couple player / chart") |
38
|
|
|
* @ORM\Entity(repositoryClass="VideoGamesRecords\CoreBundle\Repository\PlayerChartRepository") |
39
|
|
|
* @ORM\EntityListeners({"VideoGamesRecords\CoreBundle\EventListener\Entity\PlayerChartListener"}) |
40
|
|
|
* @ApiFilter(DateFilter::class, properties={"lastUpdate": DateFilter::EXCLUDE_NULL}) |
41
|
|
|
* @ApiFilter( |
42
|
|
|
* SearchFilter::class, |
43
|
|
|
* properties={ |
44
|
|
|
* "status": "exact", |
45
|
|
|
* "player": "exact", |
46
|
|
|
* "chart": "exact", |
47
|
|
|
* "chart.group": "exact", |
48
|
|
|
* "chart.group.game": "exact", |
49
|
|
|
* "chart.group.game.platforms": "exact", |
50
|
|
|
* "rank": "exact", |
51
|
|
|
* "nbEqual": "exact", |
52
|
|
|
* "chart.libChartEn" : "partial", |
53
|
|
|
* "chart.libChartFr" : "partial", |
54
|
|
|
* } |
55
|
|
|
* ) |
56
|
|
|
* @ApiFilter( |
57
|
|
|
* RangeFilter::class, |
58
|
|
|
* properties={ |
59
|
|
|
* "chart.nbPost", |
60
|
|
|
* "rank", |
61
|
|
|
* "pointChart", |
62
|
|
|
* } |
63
|
|
|
* ) |
64
|
|
|
* @ApiFilter( |
65
|
|
|
* ExistsFilter::class, |
66
|
|
|
* properties={ |
67
|
|
|
* "proof", |
68
|
|
|
* "proof.picture", |
69
|
|
|
* "proof.video", |
70
|
|
|
* } |
71
|
|
|
* ) |
72
|
|
|
* @ApiFilter( |
73
|
|
|
* GroupFilter::class, |
74
|
|
|
* arguments={ |
75
|
|
|
* "parameterName": "groups", |
76
|
|
|
* "overrideDefaultGroups": true, |
77
|
|
|
* "whitelist": { |
78
|
|
|
* "playerChart.read", |
79
|
|
|
* "playerChart.status", |
80
|
|
|
* "playerChartStatus.read", |
81
|
|
|
* "playerChart.platform", |
82
|
|
|
* "platform.read", |
83
|
|
|
* "playerChart.player", |
84
|
|
|
* "player.read.mini", |
85
|
|
|
* "player.country", |
86
|
|
|
* "country.read", |
87
|
|
|
* "chart.read.mini", |
88
|
|
|
* "playerChart.chart", |
89
|
|
|
* "chart.group", |
90
|
|
|
* "group.read.mini", |
91
|
|
|
* "group.game", |
92
|
|
|
* "game.read.mini", |
93
|
|
|
* "playerChartLib.format", |
94
|
|
|
* "playerChart.proof", |
95
|
|
|
* "proof.read", |
96
|
|
|
* "picture.read", |
97
|
|
|
* "video.read", |
98
|
|
|
* } |
99
|
|
|
* } |
100
|
|
|
* ) |
101
|
|
|
* @ApiFilter( |
102
|
|
|
* OrderFilter::class, |
103
|
|
|
* properties={ |
104
|
|
|
* "id":"ASC", |
105
|
|
|
* "lastUpdate" : "DESC", |
106
|
|
|
* "rank" : "ASC", |
107
|
|
|
* "pointChart" : "DESC", |
108
|
|
|
* "chart.libChartEn" : "ASC", |
109
|
|
|
* "chart.libChartFr" : "ASC", |
110
|
|
|
* "chart.group.libGroupEn" : "ASC", |
111
|
|
|
* "chart.group.libGroupFr" : "ASC", |
112
|
|
|
* "chart.group.game.libGameEn" : "ASC", |
113
|
|
|
* "chart.group.game.libGameFr" : "ASC", |
114
|
|
|
* }, |
115
|
|
|
* arguments={"orderParameterName"="order"} |
116
|
|
|
* ) |
117
|
|
|
*/ |
118
|
|
|
class PlayerChart |
119
|
|
|
{ |
120
|
|
|
use PlayerTrait; |
121
|
|
|
use TimestampableEntity; |
122
|
|
|
use NbEqualTrait; |
123
|
|
|
use LastUpdateTrait; |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @ORM\Column(name="id", type="integer") |
127
|
|
|
* @ORM\Id |
128
|
|
|
* @ORM\GeneratedValue(strategy="IDENTITY") |
129
|
|
|
*/ |
130
|
|
|
private ?int $id = null; |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @ORM\Column(name="`rank`", type="integer", nullable=true) |
134
|
|
|
*/ |
135
|
|
|
private ?int $rank = null; |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @ORM\Column(name="pointChart", type="integer", nullable=false, options={"default" : 0}) |
139
|
|
|
*/ |
140
|
|
|
private int $pointChart = 0; |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @ORM\Column(name="pointPlatform", type="integer", nullable=false, options={"default" : 0}) |
144
|
|
|
*/ |
145
|
|
|
private int $pointPlatform = 0; |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @ORM\Column(name="isTopScore", type="boolean", nullable=false) |
149
|
|
|
*/ |
150
|
|
|
private bool $topScore = false; |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @ORM\Column(name="dateInvestigation", type="date", nullable=true) |
154
|
|
|
*/ |
155
|
|
|
private ?DateTime $dateInvestigation = null; |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @ORM\ManyToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\Chart", inversedBy="playerCharts", fetch="EAGER") |
159
|
|
|
* @ORM\JoinColumns({ |
160
|
|
|
* @ORM\JoinColumn(name="idChart", referencedColumnName="id", nullable=false, onDelete="CASCADE") |
161
|
|
|
* }) |
162
|
|
|
*/ |
163
|
|
|
private Chart $chart; |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @ORM\OneToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\Proof", inversedBy="playerChart") |
167
|
|
|
* @ORM\JoinColumns({ |
168
|
|
|
* @ORM\JoinColumn(name="idProof", referencedColumnName="id", nullable=true, onDelete="SET NULL") |
169
|
|
|
* }) |
170
|
|
|
*/ |
171
|
|
|
private ?Proof $proof = null; |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @ORM\ManyToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\PlayerChartStatus", inversedBy="playerCharts") |
175
|
|
|
* @ORM\JoinColumns({ |
176
|
|
|
* @ORM\JoinColumn(name="idStatus", referencedColumnName="id", nullable=false) |
177
|
|
|
* }) |
178
|
|
|
*/ |
179
|
|
|
private PlayerChartStatus $status; |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @ORM\ManyToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\Platform") |
183
|
|
|
* @ORM\JoinColumns({ |
184
|
|
|
* @ORM\JoinColumn(name="idPlatform", referencedColumnName="id") |
185
|
|
|
* }) |
186
|
|
|
*/ |
187
|
|
|
private ?Platform $platform = null; |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @var Collection<PlayerChartLib> |
191
|
|
|
* @ORM\OneToMany( |
192
|
|
|
* targetEntity="VideoGamesRecords\CoreBundle\Entity\PlayerChartLib", |
193
|
|
|
* mappedBy="playerChart", |
194
|
|
|
* cascade={"persist", "remove"}, |
195
|
|
|
* orphanRemoval=true |
196
|
|
|
* ) |
197
|
|
|
*/ |
198
|
|
|
private Collection $libs; |
199
|
|
|
|
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Constructor |
203
|
|
|
*/ |
204
|
|
|
public function __construct() |
205
|
|
|
{ |
206
|
|
|
$this->libs = new ArrayCollection(); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @return string |
211
|
|
|
*/ |
212
|
|
|
public function __toString() |
213
|
|
|
{ |
214
|
|
|
return sprintf('%s # %s [%s]', $this->getChart()->getDefaultName(), $this->getPlayer()->getPseudo(), $this->id); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Set id |
219
|
|
|
* |
220
|
|
|
* @param integer $id |
221
|
|
|
* @return PlayerChart |
222
|
|
|
*/ |
223
|
|
|
public function setId(int $id): PlayerChart |
224
|
|
|
{ |
225
|
|
|
$this->id = $id; |
226
|
|
|
return $this; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Get id |
231
|
|
|
* |
232
|
|
|
* @return integer |
233
|
|
|
*/ |
234
|
|
|
public function getId(): ?int |
235
|
|
|
{ |
236
|
|
|
return $this->id; |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* Set rank |
241
|
|
|
* |
242
|
|
|
* @param integer $rank |
243
|
|
|
* @return PlayerChart |
244
|
|
|
*/ |
245
|
|
|
public function setRank(int $rank): PlayerChart |
246
|
|
|
{ |
247
|
|
|
$this->rank = $rank; |
248
|
|
|
return $this; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* Get rank |
253
|
|
|
* |
254
|
|
|
* @return integer |
255
|
|
|
*/ |
256
|
|
|
public function getRank(): ?int |
257
|
|
|
{ |
258
|
|
|
return $this->rank; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* Set pointChart |
264
|
|
|
* @param int $pointChart |
265
|
|
|
* @return PlayerChart |
266
|
|
|
*/ |
267
|
|
|
public function setPointChart(int $pointChart): PlayerChart |
268
|
|
|
{ |
269
|
|
|
$this->pointChart = $pointChart; |
270
|
|
|
return $this; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* Get pointChart |
275
|
|
|
* |
276
|
|
|
* @return int |
277
|
|
|
*/ |
278
|
|
|
public function getPointChart(): int |
279
|
|
|
{ |
280
|
|
|
return $this->pointChart; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* Set pointPlatform |
285
|
|
|
* @param int $pointPlatform |
286
|
|
|
* @return PlayerChart |
287
|
|
|
*/ |
288
|
|
|
public function setPointPlatform(int $pointPlatform): PlayerChart |
289
|
|
|
{ |
290
|
|
|
$this->pointPlatform = $pointPlatform; |
291
|
|
|
return $this; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* Get pointPlatform |
296
|
|
|
* |
297
|
|
|
* @return int |
298
|
|
|
*/ |
299
|
|
|
public function getPointPlatform(): ?int |
300
|
|
|
{ |
301
|
|
|
return $this->pointPlatform; |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* Set topScore |
306
|
|
|
* |
307
|
|
|
* @param bool $topScore |
308
|
|
|
* |
309
|
|
|
* @return PlayerChart |
310
|
|
|
*/ |
311
|
|
|
public function setTopScore(bool $topScore): PlayerChart |
312
|
|
|
{ |
313
|
|
|
$this->topScore = $topScore; |
314
|
|
|
return $this; |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* Get topScore |
319
|
|
|
* |
320
|
|
|
* @return bool |
321
|
|
|
*/ |
322
|
|
|
public function isTopScore(): bool |
323
|
|
|
{ |
324
|
|
|
return $this->topScore; |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
|
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* Set dateInvestigation |
331
|
|
|
* @param DateTime|null $dateInvestigation |
332
|
|
|
* @return PlayerChart |
333
|
|
|
*/ |
334
|
|
|
public function setDateInvestigation(DateTime $dateInvestigation = null): PlayerChart |
335
|
|
|
{ |
336
|
|
|
$this->dateInvestigation = $dateInvestigation; |
337
|
|
|
return $this; |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* Get dateInvestigation |
342
|
|
|
* |
343
|
|
|
* @return DateTime |
344
|
|
|
*/ |
345
|
|
|
public function getDateInvestigation(): ?DateTime |
346
|
|
|
{ |
347
|
|
|
return $this->dateInvestigation; |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* Set Chart |
352
|
|
|
* @param Chart $chart |
353
|
|
|
* @return PlayerChart |
354
|
|
|
*/ |
355
|
|
|
public function setChart(Chart $chart): PlayerChart |
356
|
|
|
{ |
357
|
|
|
$this->chart = $chart; |
358
|
|
|
|
359
|
|
|
return $this; |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
/** |
363
|
|
|
* Get chart |
364
|
|
|
* |
365
|
|
|
* @return Chart |
366
|
|
|
*/ |
367
|
|
|
public function getChart(): Chart |
368
|
|
|
{ |
369
|
|
|
return $this->chart; |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* Set proof |
374
|
|
|
* @param Proof|null $proof |
375
|
|
|
* @return PlayerChart |
376
|
|
|
*/ |
377
|
|
|
public function setProof(Proof $proof = null): PlayerChart |
378
|
|
|
{ |
379
|
|
|
$this->proof = $proof; |
380
|
|
|
|
381
|
|
|
return $this; |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
/** |
385
|
|
|
* Get proof |
386
|
|
|
* |
387
|
|
|
* @return Proof |
388
|
|
|
*/ |
389
|
|
|
public function getProof(): ?Proof |
390
|
|
|
{ |
391
|
|
|
return $this->proof; |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
|
395
|
|
|
/** |
396
|
|
|
* Set platform |
397
|
|
|
* @param Platform|null $platform |
398
|
|
|
* @return PlayerChart |
399
|
|
|
*/ |
400
|
|
|
public function setPlatform(Platform $platform = null): PlayerChart |
401
|
|
|
{ |
402
|
|
|
$this->platform = $platform; |
403
|
|
|
return $this; |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
/** |
407
|
|
|
* Get platform |
408
|
|
|
* |
409
|
|
|
* @return Platform |
410
|
|
|
*/ |
411
|
|
|
public function getPlatform(): ?Platform |
412
|
|
|
{ |
413
|
|
|
return $this->platform; |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
|
417
|
|
|
/** |
418
|
|
|
* Set status |
419
|
|
|
* @param PlayerChartStatus $status |
420
|
|
|
* @return PlayerChart |
421
|
|
|
*/ |
422
|
|
|
public function setStatus(PlayerChartStatus $status): PlayerChart |
423
|
|
|
{ |
424
|
|
|
$this->status = $status; |
425
|
|
|
|
426
|
|
|
return $this; |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
/** |
430
|
|
|
* Get status |
431
|
|
|
* |
432
|
|
|
* @return PlayerChartStatus |
433
|
|
|
*/ |
434
|
|
|
public function getStatus(): PlayerChartStatus |
435
|
|
|
{ |
436
|
|
|
return $this->status; |
437
|
|
|
} |
438
|
|
|
|
439
|
|
|
/** |
440
|
|
|
* @param PlayerChartLib $lib |
441
|
|
|
* @return PlayerChart |
442
|
|
|
*/ |
443
|
|
|
public function addLib(PlayerChartLib $lib): PlayerChart |
444
|
|
|
{ |
445
|
|
|
$lib->setPlayerChart($this); |
446
|
|
|
$this->libs[] = $lib; |
447
|
|
|
return $this; |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* @param PlayerChartLib $lib |
452
|
|
|
*/ |
453
|
|
|
public function removeLib(PlayerChartLib $lib) |
454
|
|
|
{ |
455
|
|
|
$this->libs->removeElement($lib); |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* @return Collection |
460
|
|
|
*/ |
461
|
|
|
public function getLibs(): Collection |
462
|
|
|
{ |
463
|
|
|
return $this->libs; |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
/** |
467
|
|
|
* @return string |
468
|
|
|
*/ |
469
|
|
|
public function getValuesAsString() : String |
470
|
|
|
{ |
471
|
|
|
$values = []; |
472
|
|
|
foreach ($this->getLibs() as $lib) { |
473
|
|
|
$values[] = $lib->getValue(); |
474
|
|
|
} |
475
|
|
|
return implode('|', $values); |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
/** |
479
|
|
|
* @return string |
480
|
|
|
*/ |
481
|
|
|
public function getUrl(): string |
482
|
|
|
{ |
483
|
|
|
return sprintf( |
484
|
|
|
'%s-game-g%d/%s-group-g%d/%s-chart-c%d/pc-%d/index', |
485
|
|
|
$this->getChart()->getGroup()->getGame()->getSlug(), |
486
|
|
|
$this->getChart()->getGroup()->getGame()->getId(), |
487
|
|
|
$this->getChart()->getGroup()->getSlug(), |
488
|
|
|
$this->getChart()->getGroup()->getId(), |
489
|
|
|
$this->getChart()->getSlug(), |
490
|
|
|
$this->getChart()->getId(), |
491
|
|
|
$this->getId() |
492
|
|
|
); |
493
|
|
|
} |
494
|
|
|
} |
495
|
|
|
|