61 lines
1.7 KiB
PHP
61 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Blog\Controller;
|
|
|
|
use Blog\Model\LocationModel;
|
|
|
|
class LocationController {
|
|
|
|
private $model;
|
|
private $view;
|
|
|
|
public function __construct($view) {
|
|
$this->model = new LocationModel();
|
|
$this->view = $view;
|
|
}
|
|
|
|
public function showLocations() {
|
|
$locations = $this->model->getLocations();
|
|
$this->view->setVars(['locations' => $locations]);
|
|
}
|
|
|
|
public function createLocation() {
|
|
$data = [
|
|
'street' => $_POST['street'],
|
|
'house_number' => $_POST['house_number'],
|
|
'postal_code' => $_POST['postal_code'],
|
|
'city' => $_POST['city'],
|
|
'country' => $_POST['country'],
|
|
'phone' => $_POST['phone'],
|
|
'email' => $_POST['email']
|
|
];
|
|
$result = $this->model->createLocation($data);
|
|
$this->view->setVars(['location' => $result]);
|
|
}
|
|
|
|
public function editLocationForm() {
|
|
$id = $_GET['location_id'];
|
|
$location = $this->model->getLocation($id);
|
|
$this->view->setVars(['location' => $location]);
|
|
}
|
|
|
|
public function updateLocation() {
|
|
$data = [
|
|
'street' => $_POST['street'],
|
|
'house_number' => $_POST['house_number'],
|
|
'postal_code' => $_POST['postal_code'],
|
|
'city' => $_POST['city'],
|
|
'country' => $_POST['country'],
|
|
'phone' => $_POST['phone'],
|
|
'email' => $_POST['email']
|
|
];
|
|
$location_id = $_POST['location_id'];
|
|
$result = $this->model->updateLocation($location_id, $data);
|
|
$this->view->setVars(['location' => $result]);
|
|
}
|
|
|
|
public function deleteLocation() {
|
|
$id = $_GET['location_id'] ?? null;
|
|
$this->model->deleteLocation($id);
|
|
}
|
|
} |