1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace VideoGamesRecords\CoreBundle\Ranking\Command\Player; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityRepository; |
6
|
|
|
use Doctrine\ORM\NonUniqueResultException; |
7
|
|
|
use VideoGamesRecords\CoreBundle\Entity\Player; |
8
|
|
|
use VideoGamesRecords\CoreBundle\Event\PlayerEvent; |
9
|
|
|
use VideoGamesRecords\CoreBundle\Handler\Ranking\AbstractRankingHandler; |
10
|
|
|
use VideoGamesRecords\CoreBundle\Tools\Ranking; |
11
|
|
|
use VideoGamesRecords\CoreBundle\VideoGamesRecordsCoreEvents; |
12
|
|
|
|
13
|
|
|
class PlayerRankingHandler extends AbstractRankingHandler |
14
|
|
|
{ |
15
|
|
|
/*public function majAll() |
16
|
|
|
{ |
17
|
|
|
$query = $this->em->createQuery(" |
18
|
|
|
SELECT p |
19
|
|
|
FROM VideoGamesRecords\CoreBundle\Entity\Player p |
20
|
|
|
WHERE p.nbChart > 0" |
21
|
|
|
); |
22
|
|
|
$players = $query->getResult(); |
23
|
|
|
foreach ($players as $player) { |
24
|
|
|
$this->handle($player->getId()); |
25
|
|
|
} |
26
|
|
|
}*/ |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @throws NonUniqueResultException |
30
|
|
|
*/ |
31
|
|
|
public function handle($mixed): void |
32
|
|
|
{ |
33
|
|
|
/** @var Player $player */ |
34
|
|
|
$player = $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Player')->find($mixed); |
35
|
|
|
if (null === $player) { |
36
|
|
|
return; |
37
|
|
|
} |
38
|
|
|
if ($player->getId() == 0) { |
|
|
|
|
39
|
|
|
return; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$query = $this->em->createQuery(" |
43
|
|
|
SELECT |
44
|
|
|
p.id, |
45
|
|
|
SUM(g.nbChart) as nbChartMax, |
46
|
|
|
round(AVG(pg.rankPointChart),2) as averageGameRank, |
47
|
|
|
SUM(pg.chartRank0) as chartRank0, |
48
|
|
|
SUM(pg.chartRank1) as chartRank1, |
49
|
|
|
SUM(pg.chartRank2) as chartRank2, |
50
|
|
|
SUM(pg.chartRank3) as chartRank3, |
51
|
|
|
SUM(pg.nbChart) as nbChart, |
52
|
|
|
SUM(pg.nbChartProven) as nbChartProven, |
53
|
|
|
SUM(pg.pointChart) as pointChart, |
54
|
|
|
SUM(pg.pointGame) as pointGame, |
55
|
|
|
COUNT(DISTINCT pg.game) as nbGame |
56
|
|
|
FROM VideoGamesRecords\CoreBundle\Entity\PlayerGame pg |
57
|
|
|
JOIN pg.player p |
58
|
|
|
JOIN pg.game g |
59
|
|
|
WHERE pg.player = :player |
60
|
|
|
AND g.boolRanking = 1 |
61
|
|
|
GROUP BY p.id"); |
62
|
|
|
$query->setParameter('player', $player); |
63
|
|
|
$row = $query->getOneOrNullResult(); |
64
|
|
|
|
65
|
|
|
$player->setNbChartMax($row['nbChartMax']); |
66
|
|
|
$player->setAverageGameRank($row['averageGameRank']); |
67
|
|
|
$player->setChartRank0($row['chartRank0']); |
68
|
|
|
$player->setChartRank1($row['chartRank1']); |
69
|
|
|
$player->setChartRank2($row['chartRank2']); |
70
|
|
|
$player->setChartRank3($row['chartRank3']); |
71
|
|
|
$player->setNbChart($row['nbChart']); |
72
|
|
|
$player->setNbChartProven($row['nbChartProven']); |
73
|
|
|
$player->setNbGame($row['nbGame']); |
74
|
|
|
$player->setPointChart($row['pointChart']); |
75
|
|
|
$player->setPointGame($row['pointGame']); |
76
|
|
|
|
77
|
|
|
// 2 game Ranking |
78
|
|
|
$data = [ |
79
|
|
|
'gameRank0' => 0, |
80
|
|
|
'gameRank1' => 0, |
81
|
|
|
'gameRank2' => 0, |
82
|
|
|
'gameRank3' => 0, |
83
|
|
|
]; |
84
|
|
|
|
85
|
|
|
//----- data rank0 |
86
|
|
|
$query = $this->em->createQuery(" |
87
|
|
|
SELECT |
88
|
|
|
p.id, |
89
|
|
|
COUNT(pg.game) as nb |
90
|
|
|
FROM VideoGamesRecords\CoreBundle\Entity\PlayerGame pg |
91
|
|
|
JOIN pg.game g |
92
|
|
|
JOIN pg.player p |
93
|
|
|
WHERE pg.rankPointChart = 1 |
94
|
|
|
AND pg.player = :player |
95
|
|
|
AND g.nbPlayer > 1 |
96
|
|
|
AND g.boolRanking = 1 |
97
|
|
|
AND pg.nbEqual = 1 |
98
|
|
|
GROUP BY p.id"); |
99
|
|
|
|
100
|
|
|
$query->setParameter('player', $player); |
101
|
|
|
$row = $query->getOneOrNullResult(); |
102
|
|
|
if ($row) { |
103
|
|
|
$data['gameRank0'] = $row['nb']; |
104
|
|
|
} |
105
|
|
|
//----- data rank1 to rank3 |
106
|
|
|
$query = $this->em->createQuery(" |
107
|
|
|
SELECT |
108
|
|
|
p.id, |
109
|
|
|
COUNT(pg.game) as nb |
110
|
|
|
FROM VideoGamesRecords\CoreBundle\Entity\PlayerGame pg |
111
|
|
|
JOIN pg.game g |
112
|
|
|
JOIN pg.player p |
113
|
|
|
WHERE pg.rankPointChart = :rank |
114
|
|
|
AND pg.player = :player |
115
|
|
|
AND g.boolRanking = 1 |
116
|
|
|
GROUP BY p.id"); |
117
|
|
|
|
118
|
|
|
$query->setParameter('player', $player); |
119
|
|
|
for ($i = 1; $i <= 3; $i++) { |
120
|
|
|
$query->setParameter('rank', $i); |
121
|
|
|
$row = $query->getOneOrNullResult(); |
122
|
|
|
if ($row) { |
123
|
|
|
$data['gameRank' . $i] = $row['nb']; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
$player->setGameRank0($data['gameRank0']); |
128
|
|
|
$player->setGameRank1($data['gameRank1']); |
129
|
|
|
$player->setGameRank2($data['gameRank2']); |
130
|
|
|
$player->setGameRank3($data['gameRank3']); |
131
|
|
|
|
132
|
|
|
|
133
|
|
|
// 3 Badge Ranking |
134
|
|
|
$query = $this->em->createQuery(" |
135
|
|
|
SELECT |
136
|
|
|
p.id, |
137
|
|
|
COUNT(pb.badge) as nbMasterBadge, |
138
|
|
|
SUM(b.value) as pointBadge |
139
|
|
|
FROM VideoGamesRecords\CoreBundle\Entity\PlayerBadge pb |
140
|
|
|
JOIN pb.badge b |
141
|
|
|
JOIN b.game g |
142
|
|
|
JOIN pb.player p |
143
|
|
|
WHERE b.type = :type |
144
|
|
|
AND pb.player = :player |
145
|
|
|
AND pb.ended_at IS NULL |
146
|
|
|
AND g.boolRanking = 1 |
147
|
|
|
GROUP BY p.id"); |
148
|
|
|
$query->setParameter('type', 'Master'); |
149
|
|
|
$query->setParameter('player', $player); |
150
|
|
|
|
151
|
|
|
$row = $query->getOneOrNullResult(); |
152
|
|
|
if ($row) { |
153
|
|
|
$player->setNbMasterBadge($row['nbMasterBadge']); |
154
|
|
|
$player->setPointBadge($row['pointBadge']); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
// 4 nbChartWithPlatform |
158
|
|
|
$query = $this->em->createQuery(" |
159
|
|
|
SELECT COUNT(pc) as nb |
160
|
|
|
FROM VideoGamesRecords\CoreBundle\Entity\PlayerChart pc |
161
|
|
|
WHERE pc.player = :player |
162
|
|
|
AND pc.platform IS NOT NULL"); |
163
|
|
|
$query->setParameter('player', $player); |
164
|
|
|
|
165
|
|
|
$nb = $query->getSingleScalarResult(); |
166
|
|
|
$player->setNbChartWithPlatform($nb); |
167
|
|
|
$player->getCountry()?->setBoolMaj(true); |
168
|
|
|
|
169
|
|
|
$this->em->persist($player); |
170
|
|
|
$this->em->flush(); |
171
|
|
|
|
172
|
|
|
$event = new PlayerEvent($player); |
173
|
|
|
$this->eventDispatcher->dispatch($event, VideoGamesRecordsCoreEvents::PLAYER_MAJ_COMPLETED); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @return void |
178
|
|
|
*/ |
179
|
|
|
public function majRank(): void |
180
|
|
|
{ |
181
|
|
|
$this->majRankPointChart(); |
182
|
|
|
$this->majRankPointGame(); |
183
|
|
|
$this->majRankMedal(); |
184
|
|
|
$this->majRankCup(); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @return void |
189
|
|
|
*/ |
190
|
|
|
public function majRankPointChart(): void |
191
|
|
|
{ |
192
|
|
|
$players = $this->getPlayerRepository()->findBy(array(), array('pointChart' => 'DESC')); |
193
|
|
|
Ranking::addObjectRank($players); |
194
|
|
|
$this->em->flush(); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @return void |
199
|
|
|
*/ |
200
|
|
|
public function majRankMedal(): void |
201
|
|
|
{ |
202
|
|
|
$players = $this->getPlayerRepository()->findBy(array(), array('chartRank0' => 'DESC', 'chartRank1' => 'DESC', 'chartRank2' => 'DESC', 'chartRank3' => 'DESC')); |
203
|
|
|
Ranking::addObjectRank($players, 'rankMedal', array('chartRank0', 'chartRank1', 'chartRank2', 'chartRank3')); |
204
|
|
|
$this->em->flush(); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @return void |
209
|
|
|
*/ |
210
|
|
|
public function majRankPointGame(): void |
211
|
|
|
{ |
212
|
|
|
$players = $this->getPlayerRepository()->findBy(array(), array('pointGame' => 'DESC')); |
213
|
|
|
Ranking::addObjectRank($players, 'rankPointGame', array('pointGame')); |
214
|
|
|
$this->em->flush(); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @return void |
219
|
|
|
*/ |
220
|
|
|
public function majRankCup(): void |
221
|
|
|
{ |
222
|
|
|
$players = $this->getPlayerRepository()->findBy(array(), array('gameRank0' => 'DESC', 'gameRank1' => 'DESC', 'gameRank2' => 'DESC', 'gameRank3' => 'DESC')); |
223
|
|
|
Ranking::addObjectRank($players, 'rankCup', array('gameRank0', 'gameRank1', 'gameRank2', 'gameRank3')); |
224
|
|
|
$this->em->flush(); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @return void |
229
|
|
|
*/ |
230
|
|
|
public function majRankProof(): void |
231
|
|
|
{ |
232
|
|
|
$players = $this->getPlayerRepository()->findBy(array(), array('nbChartProven' => 'DESC')); |
233
|
|
|
Ranking::addObjectRank($players, 'rankProof', array('nbChartProven')); |
234
|
|
|
$this->em->flush(); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @return void |
239
|
|
|
*/ |
240
|
|
|
public function majRankBadge(): void |
241
|
|
|
{ |
242
|
|
|
$players = $this->getPlayerRepository()->findBy(array(), array('pointBadge' => 'DESC', 'nbMasterBadge' => 'DESC')); |
243
|
|
|
Ranking::addObjectRank($players, 'rankBadge', array('pointBadge', 'nbMasterBadge')); |
244
|
|
|
$this->em->flush(); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
private function getPlayerRepository(): EntityRepository |
248
|
|
|
{ |
249
|
|
|
return $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Player'); |
250
|
|
|
} |
251
|
|
|
} |
252
|
|
|
|