|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace VideoGamesRecords\CoreBundle\Message\Dispatcher; |
|
6
|
|
|
|
|
7
|
|
|
use Symfony\Component\Messenger\Exception\ExceptionInterface; |
|
8
|
|
|
use Symfony\Component\Messenger\MessageBusInterface; |
|
9
|
|
|
use VideoGamesRecords\CoreBundle\Entity\Game; |
|
10
|
|
|
use VideoGamesRecords\CoreBundle\Entity\Group; |
|
11
|
|
|
use VideoGamesRecords\CoreBundle\Entity\Player; |
|
12
|
|
|
use VideoGamesRecords\CoreBundle\Entity\PlayerChart; |
|
13
|
|
|
use VideoGamesRecords\CoreBundle\Message\Player\UpdatePlayerChartRank; |
|
14
|
|
|
use VideoGamesRecords\CoreBundle\Message\Player\UpdatePlayerData; |
|
15
|
|
|
use VideoGamesRecords\CoreBundle\Message\Player\UpdatePlayerRank; |
|
16
|
|
|
use VideoGamesRecords\CoreBundle\Message\Team\UpdateTeamChartRank; |
|
17
|
|
|
|
|
18
|
|
|
readonly class RankingUpdateDispatcher |
|
19
|
|
|
{ |
|
20
|
|
|
public function __construct( |
|
21
|
|
|
private MessageBusInterface $bus, |
|
22
|
|
|
) { |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param Game $game |
|
27
|
|
|
* @throws ExceptionInterface |
|
28
|
|
|
*/ |
|
29
|
|
|
public function updatePlayerRankFromGame(Game $game): void |
|
30
|
|
|
{ |
|
31
|
|
|
foreach ($game->getGroups() as $group) { |
|
32
|
|
|
$this->updatePlayerRankFromGroup($group); |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param Group $group |
|
38
|
|
|
* @throws ExceptionInterface |
|
39
|
|
|
*/ |
|
40
|
|
|
public function updatePlayerRankFromGroup(Group $group): void |
|
41
|
|
|
{ |
|
42
|
|
|
foreach ($group->getCharts() as $chart) { |
|
43
|
|
|
$this->bus->dispatch(new UpdatePlayerChartRank($chart->getId())); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param Player $player |
|
49
|
|
|
* @throws ExceptionInterface |
|
50
|
|
|
*/ |
|
51
|
|
|
public function updateTeamRankFromPlayer(Player $player): void |
|
52
|
|
|
{ |
|
53
|
|
|
/** @var PlayerChart $playerChart */ |
|
54
|
|
|
foreach ($player->getPlayerCharts() as $playerChart) { |
|
55
|
|
|
$this->bus->dispatch(new UpdateTeamChartRank($playerChart->getChart()->getId())); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param Player $player |
|
61
|
|
|
* @throws ExceptionInterface |
|
62
|
|
|
*/ |
|
63
|
|
|
public function updatePlayerRankFromPlayer(Player $player): void |
|
64
|
|
|
{ |
|
65
|
|
|
$this->bus->dispatch(new UpdatePlayerData($player->getId())); |
|
|
|
|
|
|
66
|
|
|
$this->bus->dispatch(new UpdatePlayerRank()); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|