Fix /me/games
This commit is contained in:
parent
9a7f90ecde
commit
4fc05f2eb8
1 changed files with 13 additions and 6 deletions
|
@ -61,14 +61,16 @@ class ScoreControllerProvider implements ControllerProviderInterface
|
||||||
return new JsonResponse(['success' => false, 'message' => "Invalid level"], 400);
|
return new JsonResponse(['success' => false, 'message' => "Invalid level"], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
$game = new Game();
|
$game = new Models\Game();
|
||||||
$game->setUser($user);
|
$game->setUser($user);
|
||||||
$game->setLevel($level);
|
$game->setLevel($level);
|
||||||
$game->setOriginalGameAt(new DateTime($data['time']));
|
$game->setOriginalGameAt(new \DateTime($data['time']));
|
||||||
|
|
||||||
|
$map_hits = [];
|
||||||
|
|
||||||
foreach($data['hits'] as $data_hit) {
|
foreach($data['hits'] as $data_hit) {
|
||||||
$hit = new Hit;
|
$hit = new Models\Hit();
|
||||||
$target = $this->_eh->getEm()->getRepository(Models\Target::class)->findOneBy(['position' => $hit['target_index'], 'level' => $level]);
|
$target = $this->_eh->getEm()->getRepository(Models\Target::class)->findOneBy(['position' => $data_hit['target_index'], 'level' => $level]);
|
||||||
if(empty($target)){
|
if(empty($target)){
|
||||||
return new JsonResponse(['success' => false, 'message' => "Invalid target for hit"], 400);
|
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) {
|
foreach(range(0, 33) as $i) {
|
||||||
$hit->setPoint($i, $data_hit['points']["$i"]['x'], $data_hit['points']["$i"]['y']);
|
$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()->persist($game);
|
||||||
$this->_eh->getEm()->flush();
|
$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, 'id' => $game->getId(), 'hits' => $hits_array], 200);
|
||||||
return new JsonResponse(['success' => true, 'remoteId' => $game->getId()], 200);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return $controllers;
|
return $controllers;
|
||||||
|
|
Loading…
Reference in a new issue