|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace VideoGamesRecords\CoreBundle\Ranking\Command\Player; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityRepository; |
|
6
|
|
|
use VideoGamesRecords\CoreBundle\Entity\Player; |
|
7
|
|
|
use VideoGamesRecords\CoreBundle\Event\PlayerEvent; |
|
8
|
|
|
use VideoGamesRecords\CoreBundle\Ranking\Command\AbstractRankingHandler; |
|
9
|
|
|
use VideoGamesRecords\CoreBundle\Tools\Ranking; |
|
10
|
|
|
use VideoGamesRecords\CoreBundle\VideoGamesRecordsCoreEvents; |
|
11
|
|
|
|
|
12
|
|
|
class PlayerRankingHandler extends AbstractRankingHandler |
|
13
|
|
|
{ |
|
14
|
|
|
public function handle($mixed): void |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var Player $player */ |
|
17
|
|
|
$player = $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Player')->find($mixed); |
|
18
|
|
|
if (null === $player) { |
|
19
|
|
|
return; |
|
20
|
|
|
} |
|
21
|
|
|
if ($player->getId() == 0) { |
|
|
|
|
|
|
22
|
|
|
return; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
$query = $this->em->createQuery(" |
|
26
|
|
|
SELECT |
|
27
|
|
|
p.id, |
|
28
|
|
|
SUM(g.nbChart) as nbChartMax, |
|
29
|
|
|
round(AVG(pg.rankPointChart),2) as averageGameRank, |
|
30
|
|
|
SUM(pg.chartRank0) as chartRank0, |
|
31
|
|
|
SUM(pg.chartRank1) as chartRank1, |
|
32
|
|
|
SUM(pg.chartRank2) as chartRank2, |
|
33
|
|
|
SUM(pg.chartRank3) as chartRank3, |
|
34
|
|
|
SUM(pg.nbChart) as nbChart, |
|
35
|
|
|
SUM(pg.nbChartProven) as nbChartProven, |
|
36
|
|
|
SUM(pg.pointChart) as pointChart, |
|
37
|
|
|
SUM(pg.pointGame) as pointGame, |
|
38
|
|
|
COUNT(DISTINCT pg.game) as nbGame |
|
39
|
|
|
FROM VideoGamesRecords\CoreBundle\Entity\PlayerGame pg |
|
40
|
|
|
JOIN pg.player p |
|
41
|
|
|
JOIN pg.game g |
|
42
|
|
|
WHERE pg.player = :player |
|
43
|
|
|
AND g.boolRanking = 1 |
|
44
|
|
|
GROUP BY p.id"); |
|
45
|
|
|
$query->setParameter('player', $player); |
|
46
|
|
|
$row = $query->getOneOrNullResult(); |
|
47
|
|
|
|
|
48
|
|
|
$player->setNbChartMax($row['nbChartMax']); |
|
49
|
|
|
$player->setAverageGameRank($row['averageGameRank']); |
|
50
|
|
|
$player->setChartRank0($row['chartRank0']); |
|
51
|
|
|
$player->setChartRank1($row['chartRank1']); |
|
52
|
|
|
$player->setChartRank2($row['chartRank2']); |
|
53
|
|
|
$player->setChartRank3($row['chartRank3']); |
|
54
|
|
|
$player->setNbChart($row['nbChart']); |
|
55
|
|
|
$player->setNbChartProven($row['nbChartProven']); |
|
56
|
|
|
$player->setNbGame($row['nbGame']); |
|
57
|
|
|
$player->setPointChart($row['pointChart']); |
|
58
|
|
|
$player->setPointGame($row['pointGame']); |
|
59
|
|
|
|
|
60
|
|
|
// 2 game Ranking |
|
61
|
|
|
$data = [ |
|
62
|
|
|
'gameRank0' => 0, |
|
63
|
|
|
'gameRank1' => 0, |
|
64
|
|
|
'gameRank2' => 0, |
|
65
|
|
|
'gameRank3' => 0, |
|
66
|
|
|
]; |
|
67
|
|
|
|
|
68
|
|
|
//----- data rank0 |
|
69
|
|
|
$query = $this->em->createQuery(" |
|
70
|
|
|
SELECT |
|
71
|
|
|
p.id, |
|
72
|
|
|
COUNT(pg.game) as nb |
|
73
|
|
|
FROM VideoGamesRecords\CoreBundle\Entity\PlayerGame pg |
|
74
|
|
|
JOIN pg.game g |
|
75
|
|
|
JOIN pg.player p |
|
76
|
|
|
WHERE pg.rankPointChart = 1 |
|
77
|
|
|
AND pg.player = :player |
|
78
|
|
|
AND g.nbPlayer > 1 |
|
79
|
|
|
AND g.boolRanking = 1 |
|
80
|
|
|
AND pg.nbEqual = 1 |
|
81
|
|
|
GROUP BY p.id"); |
|
82
|
|
|
|
|
83
|
|
|
$query->setParameter('player', $player); |
|
84
|
|
|
$row = $query->getOneOrNullResult(); |
|
85
|
|
|
if ($row) { |
|
86
|
|
|
$data['gameRank0'] = $row['nb']; |
|
87
|
|
|
} |
|
88
|
|
|
//----- data rank1 to rank3 |
|
89
|
|
|
$query = $this->em->createQuery(" |
|
90
|
|
|
SELECT |
|
91
|
|
|
p.id, |
|
92
|
|
|
COUNT(pg.game) as nb |
|
93
|
|
|
FROM VideoGamesRecords\CoreBundle\Entity\PlayerGame pg |
|
94
|
|
|
JOIN pg.game g |
|
95
|
|
|
JOIN pg.player p |
|
96
|
|
|
WHERE pg.rankPointChart = :rank |
|
97
|
|
|
AND pg.player = :player |
|
98
|
|
|
AND g.boolRanking = 1 |
|
99
|
|
|
GROUP BY p.id"); |
|
100
|
|
|
|
|
101
|
|
|
$query->setParameter('player', $player); |
|
102
|
|
|
for ($i = 1; $i <= 3; $i++) { |
|
103
|
|
|
$query->setParameter('rank', $i); |
|
104
|
|
|
$row = $query->getOneOrNullResult(); |
|
105
|
|
|
if ($row) { |
|
106
|
|
|
$data['gameRank' . $i] = $row['nb']; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
$player->setGameRank0($data['gameRank0']); |
|
111
|
|
|
$player->setGameRank1($data['gameRank1']); |
|
112
|
|
|
$player->setGameRank2($data['gameRank2']); |
|
113
|
|
|
$player->setGameRank3($data['gameRank3']); |
|
114
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
// 3 Badge Ranking |
|
117
|
|
|
$query = $this->em->createQuery(" |
|
118
|
|
|
SELECT |
|
119
|
|
|
p.id, |
|
120
|
|
|
COUNT(pb.badge) as nbMasterBadge, |
|
121
|
|
|
SUM(b.value) as pointBadge |
|
122
|
|
|
FROM VideoGamesRecords\CoreBundle\Entity\PlayerBadge pb |
|
123
|
|
|
JOIN pb.badge b |
|
124
|
|
|
JOIN b.game g |
|
125
|
|
|
JOIN pb.player p |
|
126
|
|
|
WHERE b.type = :type |
|
127
|
|
|
AND pb.player = :player |
|
128
|
|
|
AND pb.ended_at IS NULL |
|
129
|
|
|
AND g.boolRanking = 1 |
|
130
|
|
|
GROUP BY p.id"); |
|
131
|
|
|
$query->setParameter('type', 'Master'); |
|
132
|
|
|
$query->setParameter('player', $player); |
|
133
|
|
|
|
|
134
|
|
|
$row = $query->getOneOrNullResult(); |
|
135
|
|
|
if ($row) { |
|
136
|
|
|
$player->setNbMasterBadge($row['nbMasterBadge']); |
|
137
|
|
|
$player->setPointBadge($row['pointBadge']); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
// 4 nbChartWithPlatform |
|
141
|
|
|
$query = $this->em->createQuery(" |
|
142
|
|
|
SELECT COUNT(pc) as nb |
|
143
|
|
|
FROM VideoGamesRecords\CoreBundle\Entity\PlayerChart pc |
|
144
|
|
|
WHERE pc.player = :player |
|
145
|
|
|
AND pc.platform IS NOT NULL"); |
|
146
|
|
|
$query->setParameter('player', $player); |
|
147
|
|
|
|
|
148
|
|
|
$nb = $query->getSingleScalarResult(); |
|
149
|
|
|
$player->setNbChartWithPlatform($nb); |
|
150
|
|
|
$player->getCountry()?->setBoolMaj(true); |
|
151
|
|
|
|
|
152
|
|
|
$this->em->persist($player); |
|
153
|
|
|
$this->em->flush(); |
|
154
|
|
|
|
|
155
|
|
|
$event = new PlayerEvent($player); |
|
156
|
|
|
$this->eventDispatcher->dispatch($event, VideoGamesRecordsCoreEvents::PLAYER_MAJ_COMPLETED); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
|
|
160
|
|
|
} |
|
161
|
|
|
|