|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace App\GameRating\Business\UserPoint; |
|
5
|
|
|
|
|
6
|
|
|
use App\GameBetting\Business\GameExtraPoints\PointsProviderInterface; |
|
7
|
|
|
use App\GameBetting\Business\Games\UserPastGamesInterface; |
|
8
|
|
|
use App\GameRating\Business\UserPoint\Info\UserScore; |
|
9
|
|
|
use App\User\Persistence\Entity\User; |
|
10
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
11
|
|
|
|
|
12
|
|
|
class UserScoreProvider implements UserScoreProviderInterface |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var EntityManagerInterface |
|
16
|
|
|
*/ |
|
17
|
|
|
private $entityManager; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var UserPastGamesInterface |
|
21
|
|
|
*/ |
|
22
|
|
|
private $userPastGamesInterface; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var PointsProviderInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
private $extraPointProvider; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param EntityManagerInterface $entityManager |
|
31
|
|
|
* @param UserPastGamesInterface $userPastGamesInterface |
|
32
|
|
|
* @param PointsProviderInterface $extraPointProvider |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct( |
|
35
|
|
|
EntityManagerInterface $entityManager, |
|
36
|
|
|
UserPastGamesInterface $userPastGamesInterface, |
|
37
|
|
|
PointsProviderInterface $extraPointProvider |
|
38
|
|
|
) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->entityManager = $entityManager; |
|
41
|
|
|
$this->userPastGamesInterface = $userPastGamesInterface; |
|
42
|
|
|
$this->extraPointProvider = $extraPointProvider; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return UserScore[] |
|
48
|
|
|
*/ |
|
49
|
|
|
public function get(): array |
|
50
|
|
|
{ |
|
51
|
|
|
$users = $this->entityManager->getRepository(User::class)->findAll(); |
|
52
|
|
|
$usersScores = []; |
|
53
|
|
|
foreach ($users as $user) { |
|
54
|
|
|
$userScore = new UserScore($user); |
|
55
|
|
|
$userPastGames = $this->userPastGamesInterface->get($user); |
|
56
|
|
|
foreach ($userPastGames as $userPastGame) { |
|
57
|
|
|
$userScore->addScore($userPastGame->getScore()); |
|
58
|
|
|
} |
|
59
|
|
|
$extraScore = $this->extraPointProvider->get($user); |
|
60
|
|
|
$userScore->setExtraScore($extraScore); |
|
61
|
|
|
$usersScores[] = $userScore; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return $usersScores; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
} |