1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace App\GameApi\Business\WorldCupSfgIo\Import; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use App\GameApi\Business\WorldCupSfgIo\Client\ClientInterface; |
8
|
|
|
use App\GameCore\Persistence\Entity\Game; |
9
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
10
|
|
|
|
11
|
|
|
class LiveGame implements LiveGameInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var EntityManagerInterface |
15
|
|
|
*/ |
16
|
|
|
private $entityManager; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var ClientInterface |
20
|
|
|
*/ |
21
|
|
|
private $client; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param EntityManagerInterface $entityManager |
25
|
|
|
* @param ClientInterface $client |
26
|
|
|
*/ |
27
|
|
|
public function __construct(EntityManagerInterface $entityManager, ClientInterface $client) |
28
|
|
|
{ |
29
|
|
|
$this->entityManager = $entityManager; |
30
|
|
|
$this->client = $client; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function updateLiveGames() : void |
34
|
|
|
{ |
35
|
|
|
$activeGamesGames = $this->entityManager |
36
|
|
|
->getRepository(Game::class) |
37
|
|
|
->findActiveGames(); |
38
|
|
|
|
39
|
|
|
if (!empty($activeGamesGames)) { |
40
|
|
|
$changeEntity = false; |
41
|
|
|
$games = $this->client->getGames(); |
42
|
|
|
foreach ($activeGamesGames as $activeGamesGame) { |
43
|
|
|
foreach ($games as $game) { |
44
|
|
|
$findTeamFirst = $activeGamesGame->getTeamFirst()->getName() === $game->getFirstTeamName(); |
45
|
|
|
$findTeamSecond = $activeGamesGame->getTeamSecond()->getName() === $game->getSecondTeamName(); |
46
|
|
|
$checkTeamFirstResult = (int)$activeGamesGame->getFirstTeamResult() !== $game->getFirstTeamResult(); |
47
|
|
|
$checkTeamSecondResult = (int)$activeGamesGame->getSecondTeamResult() !== $game->getSecondTeamResult(); |
48
|
|
|
if ($findTeamFirst && $findTeamSecond && $checkTeamFirstResult && $checkTeamSecondResult) { |
49
|
|
|
$changeEntity = true; |
50
|
|
|
$activeGamesGame->setFirstTeamResult($game->getFirstTeamResult()); |
51
|
|
|
$activeGamesGame->setSecondTeamResult($game->getSecondTeamResult()); |
52
|
|
|
$this->entityManager->persist($activeGamesGame); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if ($changeEntity === true) { |
|
|
|
|
58
|
|
|
$this->entityManager->flush($activeGamesGame); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
} |