blob: 69d23e1ae28d4478be6abf8c0fec59e475733f54 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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,
]));
}
}
|