|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace App\GameBetting\Business\Games; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
8
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
|
9
|
|
|
use App\GameBetting\Persistence\Entity\UserBetting as UserBettingEntity; |
|
10
|
|
|
use App\GameCore\Persistence\Entity\Game; |
|
11
|
|
|
use App\GameBetting\Persistence\DataProvider\UserBetting as UserBettingDataProvider; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
class UserFutureGames implements UserFutureGamesInterface |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var EntityManagerInterface |
|
18
|
|
|
*/ |
|
19
|
|
|
private $entityManager; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @param EntityManagerInterface $entityManager |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct(EntityManagerInterface $entityManager) |
|
25
|
|
|
{ |
|
26
|
|
|
$this->entityManager = $entityManager; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function get(UserInterface $user): array |
|
30
|
|
|
{ |
|
31
|
|
|
$futureGames = $this->entityManager |
|
32
|
|
|
->getRepository(Game::class) |
|
33
|
|
|
->findFutureGames(); |
|
34
|
|
|
|
|
35
|
|
|
$gameId2UserBets = $this->getGameId2UserBets($user, $futureGames); |
|
36
|
|
|
$gamesInfo = []; |
|
37
|
|
|
/** @var Game $game */ |
|
38
|
|
|
foreach ($futureGames as $game) { |
|
39
|
|
|
$bet = new UserBettingDataProvider(); |
|
40
|
|
|
if (isset($gameId2UserBets[$game->getId()])) { |
|
41
|
|
|
$bet->setSecondTeamResult( |
|
42
|
|
|
$gameId2UserBets[$game->getId()]->getSecondTeamResult() |
|
43
|
|
|
); |
|
44
|
|
|
$bet->setFirstTeamResult( |
|
45
|
|
|
$gameId2UserBets[$game->getId()]->getFirstTeamResult() |
|
46
|
|
|
); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$gamesInfo[$game->getId()] = [ |
|
50
|
|
|
'game' => $game, |
|
51
|
|
|
'bet' => $bet |
|
52
|
|
|
]; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return $gamesInfo; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param UserInterface $user |
|
60
|
|
|
* @param $futureGames |
|
61
|
|
|
* @return UserBettingEntity[] |
|
62
|
|
|
*/ |
|
63
|
|
|
private function getGameId2UserBets(UserInterface $user, array $futureGames): array |
|
64
|
|
|
{ |
|
65
|
|
|
$userBets = $this->entityManager |
|
66
|
|
|
->getRepository(UserBettingEntity::class) |
|
67
|
|
|
->findUserBettingByUserId($user, $futureGames); |
|
68
|
|
|
|
|
69
|
|
|
/** @var UserBettingEntity[] $gameId2UserBets */ |
|
70
|
|
|
$gameId2UserBets = []; |
|
71
|
|
|
/** @var UserBettingEntity $userBet */ |
|
72
|
|
|
foreach ($userBets as $userBet) { |
|
73
|
|
|
$gameId2UserBets[$userBet->getGame()->getId()] = $userBet; |
|
74
|
|
|
} |
|
75
|
|
|
return $gameId2UserBets; |
|
76
|
|
|
} |
|
77
|
|
|
} |