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