MAPG-3 select 1 place randomly from places (with demo map id 1)

This commit is contained in:
Bence Pőcze 2020-05-17 23:35:10 +02:00
parent 153acd1a4e
commit 90a0e497b3

View File

@ -2,6 +2,7 @@
use MapGuesser\Util\Geo\Bounds; use MapGuesser\Util\Geo\Bounds;
use MapGuesser\Util\Geo\Position; use MapGuesser\Util\Geo\Position;
use mysqli;
class GuessController extends BaseController class GuessController extends BaseController
{ {
@ -9,8 +10,20 @@ class GuessController extends BaseController
protected function operate() : void protected function operate() : void
{ {
// demo position $mysql = new mysqli($_ENV['DB_HOST'], $_ENV['DB_USER'], $_ENV['DB_PASSWORD'], $_ENV['DB_NAME']);
$realPosition = new Position(47.85239, 13.35101);
// demo map
$mapId = 1;
// using RAND() for the time being, could be changed in the future
$stmt = $mysql->prepare('SELECT lat, lng FROM places WHERE map_id=? ORDER BY RAND() LIMIT 1');
$stmt->bind_param("i", $mapId);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
$realPosition = new Position($row['lat'], $row['lng']);
// demo bounds // demo bounds
$bounds = new Bounds($realPosition); $bounds = new Bounds($realPosition);