1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\GameRating\Communication\Controller; |
4
|
|
|
|
5
|
|
|
use App\GameRating\Business\GameRatingFacadeInterface; |
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
7
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
8
|
|
|
|
9
|
|
|
class UserRating extends Controller |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var GameRatingFacadeInterface |
13
|
|
|
*/ |
14
|
|
|
private $gameRatingFacade; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @param GameRatingFacadeInterface $gameRatingFacade |
18
|
|
|
*/ |
19
|
|
|
public function __construct(GameRatingFacadeInterface $gameRatingFacade) |
20
|
|
|
{ |
21
|
|
|
$this->gameRatingFacade = $gameRatingFacade; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @Route("/users/", name="game_rating_users") |
26
|
|
|
*/ |
27
|
|
|
public function users() |
28
|
|
|
{ |
29
|
|
|
$userScoreWithPositions = $this->gameRatingFacade->getUserScoreWithPosition(); |
30
|
|
|
return $this->render( |
31
|
|
|
'game_rating/user_rating/users.html.twig', |
32
|
|
|
[ |
33
|
|
|
'userScoreWithPositions' => $userScoreWithPositions, |
34
|
|
|
] |
35
|
|
|
); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @Route("/myInfo/", name="game_rating_my_info") |
40
|
|
|
*/ |
41
|
|
|
public function myInfo() |
42
|
|
|
{ |
43
|
|
|
$userScoreWithPositions = $this->gameRatingFacade->getUserScoreWithPosition(); |
44
|
|
|
$myScoreWithPositions = false; |
45
|
|
|
$userId = $this->getUser()->getId(); |
46
|
|
|
foreach ($userScoreWithPositions as $userScoreWithPosition) { |
47
|
|
|
if ($userScoreWithPosition->getUserScore()->getUser()->getId() === $userId) { |
48
|
|
|
$myScoreWithPositions = $userScoreWithPosition; |
49
|
|
|
break; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
return $this->render( |
53
|
|
|
'game_rating/user_rating/my_info.html.twig', |
54
|
|
|
[ |
55
|
|
|
'myScoreWithPositions' => $myScoreWithPositions, |
56
|
|
|
] |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @Route("/ratingTop3/", name="game_rating_top_three") |
62
|
|
|
*/ |
63
|
|
|
public function ratingTopThree() |
64
|
|
|
{ |
65
|
|
|
$userScoreWithPositions = $this->gameRatingFacade->getUserScoreWithPosition(); |
66
|
|
|
$topTree = []; |
67
|
|
|
|
68
|
|
|
for ($i = 0; $i < 3; $i++) { |
69
|
|
|
if(isset($userScoreWithPositions[$i])) { |
70
|
|
|
$topTree[] = $userScoreWithPositions[$i]; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $this->render( |
75
|
|
|
'game_rating/user_rating/top_three.html.twig', |
76
|
|
|
[ |
77
|
|
|
'userScoreWithPositions' => $topTree, |
78
|
|
|
] |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
} |