summaryrefslogtreecommitdiff
path: root/src/http/Controller/Map.php
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-01-02 20:42:01 +0100
committerDaniel Weipert <git@mail.dweipert.de>2024-01-05 12:33:59 +0100
commitb21316248572cb27ed1f504529ad6680a473022e (patch)
treef8a2f81258cae3b1d2429fb7df5a3287954b683a /src/http/Controller/Map.php
parentf621d95f89ded05a2e916c5ee363bfe75ea37482 (diff)
gemini
Diffstat (limited to 'src/http/Controller/Map.php')
-rw-r--r--src/http/Controller/Map.php43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/http/Controller/Map.php b/src/http/Controller/Map.php
new file mode 100644
index 0000000..69d23e1
--- /dev/null
+++ b/src/http/Controller/Map.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace App\http\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 region(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,
+ ]));
+ }
+}