From 4fc05f2eb8d0b52a89a64fe568dbd5650f458639 Mon Sep 17 00:00:00 2001 From: Ruben Date: Sat, 3 Sep 2016 23:25:38 +0100 Subject: [PATCH] Fix /me/games --- src/Api/ScoreControllerProvider.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Api/ScoreControllerProvider.php b/src/Api/ScoreControllerProvider.php index e08916a..a886c64 100644 --- a/src/Api/ScoreControllerProvider.php +++ b/src/Api/ScoreControllerProvider.php @@ -61,14 +61,16 @@ class ScoreControllerProvider implements ControllerProviderInterface return new JsonResponse(['success' => false, 'message' => "Invalid level"], 400); } - $game = new Game(); + $game = new Models\Game(); $game->setUser($user); $game->setLevel($level); - $game->setOriginalGameAt(new DateTime($data['time'])); + $game->setOriginalGameAt(new \DateTime($data['time'])); + + $map_hits = []; foreach($data['hits'] as $data_hit) { - $hit = new Hit; - $target = $this->_eh->getEm()->getRepository(Models\Target::class)->findOneBy(['position' => $hit['target_index'], 'level' => $level]); + $hit = new Models\Hit(); + $target = $this->_eh->getEm()->getRepository(Models\Target::class)->findOneBy(['position' => $data_hit['target_index'], 'level' => $level]); if(empty($target)){ return new JsonResponse(['success' => false, 'message' => "Invalid target for hit"], 400); } @@ -95,14 +97,19 @@ class ScoreControllerProvider implements ControllerProviderInterface foreach(range(0, 33) as $i) { $hit->setPoint($i, $data_hit['points']["$i"]['x'], $data_hit['points']["$i"]['y']); } + + $map_hits[$data_hit['id']] = $hit; } $this->_eh->getEm()->persist($game); $this->_eh->getEm()->flush(); + $hits_array = []; + foreach($map_hits as $hit_player_id => $hit) { + $hits_array[$hit_player_id] = $hit->getId(); + } - // return $app['serializer']->serialize($levels, 'json'); - return new JsonResponse(['success' => true, 'remoteId' => $game->getId()], 200); + return new JsonResponse(['success' => true, 'id' => $game->getId(), 'hits' => $hits_array], 200); }); return $controllers;