diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-10-04 11:32:04 +0200 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-10-04 11:32:04 +0200 |
commit | 94a3dd52da3ae180af37c6fd0e8c24b3562da388 (patch) | |
tree | acced055660bfd65ca3e955ea26d412457ba4507 /src/Controller/Map.php | |
parent | fa00b957378a393f8edbfc98ef111d35d18ecb09 (diff) |
initial commit 2
Diffstat (limited to 'src/Controller/Map.php')
-rw-r--r-- | src/Controller/Map.php | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/Controller/Map.php b/src/Controller/Map.php new file mode 100644 index 0000000..59c1e4e --- /dev/null +++ b/src/Controller/Map.php @@ -0,0 +1,43 @@ +<?php + +namespace App\Controller; + +use App\DB; +use App\View; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\Annotation\Route; + +class Map +{ + #[Route(path: '/map/{x}/{y}/{range}', defaults: ['range' => 1], methods: ['GET'])] + public function train(Request $request): Response + { + $x = $request->get('x'); + $y = $request->get('y'); + $range = $request->get('range'); + + $statement = DB::query( + 'select * from villages where x>=:x1 and x<=:x2 and y>=:y1 and y<=:y2', + [ + 'x1' => $x - $range, + 'x2' => $x + $range, + 'y1' => $y - $range, + 'y2' => $y + $range, + ] + ); + $villages = $statement->fetchAll(); + + $map = []; + foreach ($villages as $village) { + $map[$village['x']][$village['y']] = $village; + } + + return new Response(View::render('map.twig', [ + 'x' => $x, + 'y' => $y, + 'range' => $range, + 'map' => $map, + ])); + } +} |