This commit is contained in:
Flatlogic Bot 2025-11-11 12:38:11 +00:00
parent 10316b3644
commit 23725f3016
5 changed files with 124 additions and 32 deletions

2
db/migrate.php Normal file
View File

@ -0,0 +1,2 @@
<?php
require_once __DIR__ . '/migrations/001_create_restaurants_table.php';

View File

@ -0,0 +1,20 @@
<?php
require_once __DIR__ . '/../config.php';
try {
$pdo = db();
$sql = "
CREATE TABLE IF NOT EXISTS restaurants (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
latitude DECIMAL(10, 8) NOT NULL,
longitude DECIMAL(11, 8) NOT NULL,
description TEXT
);
";
$pdo->exec($sql);
echo "Migration successful: 'restaurants' table created or already exists.\n";
} catch (PDOException $e) {
die("Migration failed: " . $e->getMessage() . "\n");
}

2
db/seed.php Normal file
View File

@ -0,0 +1,2 @@
<?php
require_once __DIR__ . '/seeds/001_seed_restaurants.php';

View File

@ -0,0 +1,48 @@
<?php
require_once __DIR__ . '/../config.php';
$restaurants = [
[
'name' => 'Bonito',
'latitude' => 38.716842,
'longitude' => -9.140232,
'description' => 'A cozy place with great seafood.'
],
[
'name' => 'D\'Bacalhau',
'latitude' => 38.711963,
'longitude' => -9.133382,
'description' => 'The best codfish in town.'
],
[
'name' => 'Tasca do Chico',
'latitude' => 38.714244,
'longitude' => -9.143634,
'description' => 'Live Fado music and traditional food.'
],
[
'name' => 'Solar dos Presuntos',
'latitude' => 38.717889,
'longitude' => -9.14299,
'description' => 'Famous for its fresh seafood and lively atmosphere.'
],
[
'name' => 'Cervejaria Ramiro',
'latitude' => 38.719931,
'longitude' => -9.139225,
'description' => 'A legendary seafood restaurant.'
]
];
try {
$pdo = db();
$stmt = $pdo->prepare("INSERT INTO restaurants (name, latitude, longitude, description) VALUES (:name, :latitude, :longitude, :description)");
foreach ($restaurants as $restaurant) {
$stmt->execute($restaurant);
}
echo "Seeding successful: " . count($restaurants) . " restaurants inserted.\n";
} catch (PDOException $e) {
die("Seeding failed: " . $e->getMessage() . "\n");
}

View File

@ -1,12 +1,23 @@
<?php
require_once 'db/config.php';
try {
$pdo = db();
$stmt = $pdo->query('SELECT name, latitude, longitude, description FROM restaurants');
$restaurants = $stmt->fetchAll();
} catch (PDOException $e) {
// For development, you might want to log this error.
// For production, you could show a generic error message.
error_log('Database error: ' . $e->getMessage());
$restaurants = []; // Ensure restaurants is an empty array on error
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WebSummit Restaurants Map</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
crossorigin=""/>
<style>
body {
margin: 0;
@ -21,41 +32,50 @@
<body>
<div id="map"></div>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
crossorigin=""></script>
<script>
var map = L.map('map').setView([38.7686, -9.0940], 15);
const restaurants = <?php echo json_encode($restaurants, JSON_NUMERIC_CHECK); ?>;
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© OpenStreetMap'
}).addTo(map);
function initMap() {
const webSummitLocation = { lat: 38.7686, lng: -9.0940 };
const map = new google.maps.Map(document.getElementById("map"), {
zoom: 15,
center: webSummitLocation,
});
var webSummitIcon = L.icon({
iconUrl: 'https://img.icons8.com/color/48/000000/filled-star.png',
iconSize: [48, 48],
iconAnchor: [24, 48],
popupAnchor: [0, -48]
});
const webSummitMarker = new google.maps.Marker({
position: webSummitLocation,
map: map,
icon: 'https://img.icons8.com/color/48/000000/filled-star.png',
title: "Web Summit @ MEO Arena"
});
var webSummitMarker = L.marker([38.7686, -9.0940], {icon: webSummitIcon}).addTo(map);
webSummitMarker.bindPopup("<b>Web Summit @ MEO Arena</b>").openPopup();
const infoWindow = new google.maps.InfoWindow();
const restaurants = [
{ name: 'Cantinho do Avillez', lat: 38.77, lng: -9.095 },
{ name: 'Senhor Peixe', lat: 38.765, lng: -9.092 },
{ name: 'D\'Bacalhau', lat: 38.769, lng: -9.098 },
{ name: 'The Old House', lat: 38.767, lng: -9.091 },
{ name: 'ZeroZero Pizzeria', lat: 38.771, lng: -9.096 },
{ name: 'Butchers', lat: 38.766, lng: -9.099 },
{ name: 'Honorato', lat: 38.764, lng: -9.093 }
];
webSummitMarker.addListener('click', () => {
infoWindow.setContent("<b>Web Summit @ MEO Arena</b>");
infoWindow.open(map, webSummitMarker);
});
restaurants.forEach(restaurant => {
var marker = L.marker([restaurant.lat, restaurant.lng]).addTo(map);
marker.bindPopup(`<b>${restaurant.name}</b>`);
});
restaurants.forEach(restaurant => {
const marker = new google.maps.Marker({
position: { lat: restaurant.latitude, lng: restaurant.longitude },
map: map,
title: restaurant.name
});
marker.addListener('click', () => {
let content = `<b>${restaurant.name}</b>`;
if (restaurant.description) {
content += `<br>${restaurant.description}`;
}
infoWindow.setContent(content);
infoWindow.open(map, marker);
});
});
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCzZ8gdqKEbb2BaQxSeccfE97wjfl46Ruw&callback=initMap">
</script>
</body>
</html>