From d5c0e59d2981ef64610c2c27fa2904cb66326042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 17 May 2020 22:26:23 +0200 Subject: [PATCH 1/7] MAPG-3 move utils classes into Util namespace --- src/{ => Util}/Geo/Bounds.php | 2 +- src/{ => Util}/Geo/Position.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/{ => Util}/Geo/Bounds.php (97%) rename src/{ => Util}/Geo/Position.php (93%) diff --git a/src/Geo/Bounds.php b/src/Util/Geo/Bounds.php similarity index 97% rename from src/Geo/Bounds.php rename to src/Util/Geo/Bounds.php index f813f0e..e8c9710 100644 --- a/src/Geo/Bounds.php +++ b/src/Util/Geo/Bounds.php @@ -1,4 +1,4 @@ - Date: Sun, 17 May 2020 22:28:34 +0200 Subject: [PATCH 2/7] MAPG-3 move index.php's view part to views/guess.php --- public/index.php => views/guess.php | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) rename public/index.php => views/guess.php (69%) diff --git a/public/index.php b/views/guess.php similarity index 69% rename from public/index.php rename to views/guess.php index 2bb1e39..4658d5a 100644 --- a/public/index.php +++ b/views/guess.php @@ -1,26 +1,10 @@ -extend(new MapGuesser\Geo\Position(48.07683,7.35758)); -$bounds->extend(new MapGuesser\Geo\Position(47.57496, 19.08077)); - -?> - - MapGuesser -
@@ -36,5 +20,4 @@ $bounds->extend(new MapGuesser\Geo\Position(47.57496, 19.08077)); - - \ No newline at end of file + From 555984caf5b8de0a83e2daec8d3ffc4ceee967ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 17 May 2020 22:30:22 +0200 Subject: [PATCH 3/7] MAPG-3 create basic contoller functionality --- main.php | 4 +++- public/.htaccess | 5 +++++ public/index.php | 16 ++++++++++++++++ src/Controller/BaseController.php | 24 ++++++++++++++++++++++++ src/Controller/GuessController.php | 22 ++++++++++++++++++++++ 5 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 public/.htaccess create mode 100644 public/index.php create mode 100644 src/Controller/BaseController.php create mode 100644 src/Controller/GuessController.php diff --git a/main.php b/main.php index bd37059..b8c37f0 100644 --- a/main.php +++ b/main.php @@ -2,7 +2,9 @@ require 'vendor/autoload.php'; -$dotenv = Dotenv\Dotenv::createImmutable(__DIR__); +const ROOT = __DIR__; + +$dotenv = Dotenv\Dotenv::createImmutable(ROOT); $dotenv->load(); if (!empty($_ENV['DEV'])) { diff --git a/public/.htaccess b/public/.htaccess new file mode 100644 index 0000000..3a37342 --- /dev/null +++ b/public/.htaccess @@ -0,0 +1,5 @@ +RewriteEngine On +RewriteBase / +RewriteCond %{REQUEST_FILENAME} !-d +RewriteCond %{REQUEST_FILENAME} !-f +RewriteRule ^ index.php [L] diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000..cae72c9 --- /dev/null +++ b/public/index.php @@ -0,0 +1,16 @@ +render(); diff --git a/src/Controller/BaseController.php b/src/Controller/BaseController.php new file mode 100644 index 0000000..9e2c2a7 --- /dev/null +++ b/src/Controller/BaseController.php @@ -0,0 +1,24 @@ +operate(); + + extract($this->variables); + + ob_start(); + require ROOT . '/views/' . $this->view . '.php'; + $content = ob_get_contents(); + ob_end_clean(); + + return $content; + } + + abstract protected function operate() : void; +} diff --git a/src/Controller/GuessController.php b/src/Controller/GuessController.php new file mode 100644 index 0000000..68d2369 --- /dev/null +++ b/src/Controller/GuessController.php @@ -0,0 +1,22 @@ +extend(new Position(48.07683,7.35758)); + $bounds->extend(new Position(47.57496, 19.08077)); + + $this->variables = compact('realPosition', 'bounds'); + } +} From 033e03335f14250c6f53579ec7158990cdae6335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 17 May 2020 22:31:13 +0200 Subject: [PATCH 4/7] MAPG-3 add initial SQL structure --- install/db.sql | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 install/db.sql diff --git a/install/db.sql b/install/db.sql new file mode 100644 index 0000000..538e3da --- /dev/null +++ b/install/db.sql @@ -0,0 +1,27 @@ +SET NAMES utf8mb4; +SET foreign_key_checks = 0; + + +DROP TABLE IF EXISTS `maps`; +CREATE TABLE `maps` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + `description` text NOT NULL, + `bound_south_lat` decimal(8,6) NOT NULL, + `bound_west_lng` decimal(9,6) NOT NULL, + `bound_north_lat` decimal(8,6) NOT NULL, + `bound_east_lng` decimal(9,6) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + + +DROP TABLE IF EXISTS `places`; +CREATE TABLE `places` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `map_id` int(10) unsigned NOT NULL, + `lat` decimal(8,6) NOT NULL, + `lng` decimal(9,6) NOT NULL, + PRIMARY KEY (`id`), + KEY `map_id` (`map_id`), + CONSTRAINT `places_map_id` FOREIGN KEY (`map_id`) REFERENCES `maps` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; From 731a168323200546d7ffc0cad3f428e1b2e13064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 17 May 2020 22:33:48 +0200 Subject: [PATCH 5/7] MAPG-3 remove pov from panorama for the time being --- public/static/js/mapguesser.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/public/static/js/mapguesser.js b/public/static/js/mapguesser.js index bf76f05..1dc203d 100644 --- a/public/static/js/mapguesser.js +++ b/public/static/js/mapguesser.js @@ -53,10 +53,6 @@ var googleLink; function initialize() { panorama = new google.maps.StreetViewPanorama(document.getElementById('panorama'), { position: realPosition, - pov: { - heading: 34, - pitch: 10 - }, disableDefaultUI: true, linksControl: true, showRoadLabels: false From 153acd1a4e19d978fedd257859cb391890778349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 17 May 2020 23:32:57 +0200 Subject: [PATCH 6/7] MAPG-3 add DB connection variables to .env.example --- .env.example | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.env.example b/.env.example index 1570bcb..4cd7025 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,6 @@ DEV=true +DB_HOST=mariadb +DB_USER=mapguesser +DB_PASSWORD=mapguesser +DB_NAME=mapguesser GOOGLE_MAPS_JS_API_KEY=your_google_maps_js_api_key From 90a0e497b3026b3e49a1d16cc90e18150a6cc863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 17 May 2020 23:35:10 +0200 Subject: [PATCH 7/7] MAPG-3 select 1 place randomly from places (with demo map id 1) --- src/Controller/GuessController.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Controller/GuessController.php b/src/Controller/GuessController.php index 68d2369..55ec2f4 100644 --- a/src/Controller/GuessController.php +++ b/src/Controller/GuessController.php @@ -2,6 +2,7 @@ use MapGuesser\Util\Geo\Bounds; use MapGuesser\Util\Geo\Position; +use mysqli; class GuessController extends BaseController { @@ -9,8 +10,20 @@ class GuessController extends BaseController protected function operate() : void { - // demo position - $realPosition = new Position(47.85239, 13.35101); + $mysql = new mysqli($_ENV['DB_HOST'], $_ENV['DB_USER'], $_ENV['DB_PASSWORD'], $_ENV['DB_NAME']); + + // 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 $bounds = new Bounds($realPosition);