|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace VideoGamesRecords\CoreBundle\Ranking\Command\Team; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; |
|
|
|
|
|
|
6
|
|
|
use Symfony\Component\Serializer\Serializer; |
|
7
|
|
|
use VideoGamesRecords\CoreBundle\Entity\Game; |
|
8
|
|
|
use VideoGamesRecords\CoreBundle\Event\GameEvent; |
|
9
|
|
|
use VideoGamesRecords\CoreBundle\Handler\Ranking\AbstractRankingHandler; |
|
10
|
|
|
use VideoGamesRecords\CoreBundle\Tools\Ranking; |
|
11
|
|
|
use VideoGamesRecords\CoreBundle\VideoGamesRecordsCoreEvents; |
|
12
|
|
|
|
|
13
|
|
|
class TeamGameRankingHandler extends AbstractRankingHandler |
|
14
|
|
|
{ |
|
15
|
|
|
public function handle($mixed): void |
|
16
|
|
|
{ |
|
17
|
|
|
/** @var Game $game */ |
|
18
|
|
|
$game = $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Game')->find($mixed); |
|
19
|
|
|
if (null === $game) { |
|
20
|
|
|
return; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
//----- delete |
|
24
|
|
|
$query = $this->em->createQuery( |
|
25
|
|
|
'DELETE VideoGamesRecords\CoreBundle\Entity\TeamGame tg WHERE tg.game = :game' |
|
26
|
|
|
); |
|
27
|
|
|
$query->setParameter('game', $game); |
|
28
|
|
|
$query->execute(); |
|
29
|
|
|
|
|
30
|
|
|
//----- select ans save result in array |
|
31
|
|
|
$query = $this->em->createQuery(" |
|
32
|
|
|
SELECT |
|
33
|
|
|
t.id, |
|
34
|
|
|
'' as rankPointChart, |
|
35
|
|
|
'' as rankMedal, |
|
36
|
|
|
SUM(tg.chartRank0) as chartRank0, |
|
37
|
|
|
SUM(tg.chartRank1) as chartRank1, |
|
38
|
|
|
SUM(tg.chartRank2) as chartRank2, |
|
39
|
|
|
SUM(tg.chartRank3) as chartRank3, |
|
40
|
|
|
SUM(tg.pointChart) as pointChart |
|
41
|
|
|
FROM VideoGamesRecords\CoreBundle\Entity\TeamGroup tg |
|
42
|
|
|
JOIN tg.group g |
|
43
|
|
|
JOIN tg.team t |
|
44
|
|
|
WHERE g.game = :game |
|
45
|
|
|
GROUP BY t.id |
|
46
|
|
|
ORDER BY pointChart DESC"); |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
$query->setParameter('game', $game); |
|
50
|
|
|
$result = $query->getResult(); |
|
51
|
|
|
|
|
52
|
|
|
$list = []; |
|
53
|
|
|
foreach ($result as $row) { |
|
54
|
|
|
$list[] = $row; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$game->setNbTeam(count($list)); |
|
58
|
|
|
|
|
59
|
|
|
//----- add some data |
|
60
|
|
|
$list = Ranking::addRank($list, 'rankPointChart', ['pointChart'], true); |
|
61
|
|
|
$list = Ranking::order($list, ['chartRank0' => SORT_DESC, 'chartRank1' => SORT_DESC, 'chartRank2' => SORT_DESC, 'chartRank3' => SORT_DESC]); |
|
62
|
|
|
$list = Ranking::addRank($list, 'rankMedal', ['chartRank0', 'chartRank1', 'chartRank2', 'chartRank3']); |
|
63
|
|
|
$list = Ranking::calculateGamePoints($list, array('rankPointChart', 'nbEqual'), 'pointGame', 'pointChart'); |
|
64
|
|
|
|
|
65
|
|
|
$normalizer = new ObjectNormalizer(); |
|
66
|
|
|
$serializer = new Serializer([$normalizer]); |
|
67
|
|
|
|
|
68
|
|
|
foreach ($list as $row) { |
|
69
|
|
|
if (isset($row['id'])) { |
|
70
|
|
|
$teamGame = $serializer->denormalize( |
|
71
|
|
|
$row, 'VideoGamesRecords\CoreBundle\Entity\TeamGame' |
|
72
|
|
|
); |
|
73
|
|
|
$teamGame->setTeam($this->em->getReference('VideoGamesRecords\CoreBundle\Entity\Team', $row['id'])); |
|
74
|
|
|
$teamGame->setGame($game); |
|
75
|
|
|
|
|
76
|
|
|
$this->em->persist($teamGame); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
$this->em->flush(); |
|
80
|
|
|
|
|
81
|
|
|
$event = new GameEvent($game); |
|
82
|
|
|
$this->eventDispatcher->dispatch($event, VideoGamesRecordsCoreEvents::TEAM_GAME_MAJ_COMPLETED); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths