diff --git a/api/salony/index.php b/api/salony/index.php index 2d2105e..233864b 100644 --- a/api/salony/index.php +++ b/api/salony/index.php @@ -19,7 +19,7 @@ try { // === GET ALL PLACES === $places = $pdo->query(" - SELECT id, type, name, woj + SELECT id, name, woj FROM salon_places ORDER BY id ASC ")->fetchAll(); @@ -30,7 +30,7 @@ foreach ($places as $place) { // === GET SHOPS FOR PLACE === $stmt = $pdo->prepare(" - SELECT address, open_hours, url_address, lat, lng + SELECT address, open_hours, url_address, url_shop, lat, lng FROM shops WHERE place_id = ? ORDER BY id ASC @@ -40,17 +40,32 @@ foreach ($places as $place) { $shops = []; foreach ($stmt as $shop) { - $shops[] = [ - 'address' => $shop['address'], - 'openHours' => $shop['open_hours'], - 'urlAddress'=> $shop['url_address'], - 'lat' => (string)$shop['lat'], - 'lng' => (string)$shop['lng'], + $shopItem = [ + 'lat' => (string)$shop['lat'], + 'lng' => (string)$shop['lng'], ]; + + if (!empty($shop['address'])) { + $shopItem['address'] = $shop['address']; + } + + if (!empty($shop['openHours'])) { + $shopItem['openHours'] = $shop['open_hours']; + } + + if (!empty($shop['url_address'])) { + $shopItem['urlAddress'] = $shop['url_address']; + } + + if (!empty($shop['url_shop'])) { + $shopItem['shopUrl'] = $shop['url_shop']; + } + + $shops[] = $shopItem; } $result[] = [ - 'type' => $place['type'], + 'type' => "city", //! do sprawdzenia czy city jest potrzebne 'name' => $place['name'], 'woj' => $place['woj'] === null ? false : $place['woj'], 'shops' => $shops diff --git a/salony/actions/add.php b/salony/actions/add.php index 7e8ecbf..e0b935f 100644 --- a/salony/actions/add.php +++ b/salony/actions/add.php @@ -6,11 +6,10 @@ if ($_POST) { // === Dodajemy miejsce === $stmt = $pdo->prepare(" - INSERT INTO salon_places (type, name, woj) - VALUES (?, ?, ?) + INSERT INTO salon_places (name, woj) + VALUES (?, ?) "); $stmt->execute([ - $_POST['type'], $_POST['name'], $_POST['woj'] ?: null ]); @@ -19,7 +18,7 @@ if ($_POST) { // === Dodajemy sklep (shop) === $stmt = $pdo->prepare(" - INSERT INTO shops (place_id, address, open_hours, url_address, lat, lng) + INSERT INTO shops (place_id, address, open_hours, url_address, url_shop, lat, lng) VALUES (?, ?, ?, ?, ?, ?) "); $stmt->execute([ @@ -27,6 +26,7 @@ if ($_POST) { $_POST['address'] ?: null, $_POST['open_hours'] ?: null, $_POST['url_address'], + $_POST['url_shop'], $_POST['lat'], $_POST['lng'], ]); diff --git a/salony/actions/edit.php b/salony/actions/edit.php index 39bd908..33a5dcd 100644 --- a/salony/actions/edit.php +++ b/salony/actions/edit.php @@ -15,9 +15,8 @@ $shops = $shops->fetchAll(); if ($_POST) { // Aktualizujemy miejsce - $pdo->prepare("UPDATE salon_places SET type=?, name=?, woj=? WHERE id=?") + $pdo->prepare("UPDATE salon_places SET name=?, woj=? WHERE id=?") ->execute([ - $_POST['type'], $_POST['name'], $_POST['woj'] ?: null, $id @@ -27,12 +26,13 @@ if ($_POST) { $shopId = $shops[0]['id'] ?? null; if ($shopId) { $pdo->prepare(" - UPDATE shops SET address=?, open_hours=?, url_address=?, lat=?, lng=? + UPDATE shops SET address=?, open_hours=?, url_address=?, url_shop=?, lat=?, lng=? WHERE id=? ")->execute([ $_POST['address'] ?: null, $_POST['open_hours'] ?: null, $_POST['url_address'], + $_POST['url_shop'], $_POST['lat'], $_POST['lng'], $shopId diff --git a/salony/index.php b/salony/index.php index 665be08..28318d4 100644 --- a/salony/index.php +++ b/salony/index.php @@ -1,7 +1,18 @@ query("SELECT * FROM salon_places ORDER BY id DESC")->fetchAll(); +$places = $pdo->query(" + SELECT + p.id AS place_id, + p.name AS place_name, + p.woj, + s.id AS shop_id, + s.address, + s.open_hours + FROM salon_places p + LEFT JOIN shops s ON s.place_id = p.id + ORDER BY p.id DESC, s.id ASC")->fetchAll(); + include __DIR__ . '/components/header.php'; ?> @@ -19,22 +30,22 @@ include __DIR__ . '/components/header.php';