|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace VideoGamesRecords\CoreBundle\Command\Ranking; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
8
|
|
|
use Symfony\Component\Console\Attribute\AsCommand; |
|
9
|
|
|
use Symfony\Component\Console\Command\Command; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
12
|
|
|
use Symfony\Component\DependencyInjection\Attribute\Autowire; |
|
13
|
|
|
use VideoGamesRecords\CoreBundle\Contracts\Ranking\RankingCommandInterface; |
|
14
|
|
|
use VideoGamesRecords\CoreBundle\Entity\Serie; |
|
15
|
|
|
use VideoGamesRecords\CoreBundle\Ranking\Command\Player\PlayerSerieRankingHandler; |
|
16
|
|
|
use VideoGamesRecords\CoreBundle\ValueObject\SerieStatus; |
|
17
|
|
|
|
|
18
|
|
|
#[AsCommand( |
|
19
|
|
|
name: 'Command to update all players rankings after scoring', |
|
20
|
|
|
description: 'Command to update players ranking' |
|
21
|
|
|
)] |
|
22
|
|
|
class PlayerSerieRankingUpdateCommand extends Command |
|
23
|
|
|
{ |
|
24
|
|
|
private EntityManagerInterface $em; |
|
25
|
|
|
private RankingCommandInterface $rankingCommand; |
|
26
|
|
|
|
|
27
|
|
|
public function __construct( |
|
28
|
|
|
EntityManagerInterface $em, |
|
29
|
|
|
#[Autowire(service: PlayerSerieRankingHandler::class)] |
|
30
|
|
|
RankingCommandInterface $rankingCommand |
|
31
|
|
|
) { |
|
32
|
|
|
$this->em = $em; |
|
33
|
|
|
$this->rankingCommand = $rankingCommand; |
|
34
|
|
|
parent::__construct(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param InputInterface $input |
|
39
|
|
|
* @param OutputInterface $output |
|
40
|
|
|
* @return int |
|
41
|
|
|
*/ |
|
42
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
43
|
|
|
{ |
|
44
|
|
|
$series = $this->em->getRepository(Serie::class)->findBy(['status' => SerieStatus::ACTIVE]); |
|
45
|
|
|
/** @var Serie $serie */ |
|
46
|
|
|
foreach ($series as $serie) { |
|
47
|
|
|
$this->rankingCommand->handle($serie->getId()); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return Command::SUCCESS; |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|