64 lines
1.8 KiB
PHP
64 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Blog\Controller;
|
|
|
|
use Blog\Model\EventModel;
|
|
|
|
class EventController {
|
|
|
|
private $model;
|
|
private $view;
|
|
|
|
public function __construct($view) {
|
|
$this->model = new EventModel();
|
|
$this->view = $view;
|
|
}
|
|
|
|
public function showEvents() {
|
|
$events = $this->model->getEvents();
|
|
$this->view->setVars([
|
|
'events' => $events
|
|
]);
|
|
}
|
|
|
|
public function createEvent() {
|
|
$data = [
|
|
'location_id' => $_POST['location_id'] ?? null,
|
|
'start_date' => $_POST['start_date'] ?? null,
|
|
'end_date' => $_POST['end_date'] ?? null,
|
|
'name' => $_POST['name'] ?? null,
|
|
'description' => $_POST['description'] ?? null,
|
|
'max_tickets' => $_POST['max_tickets'] ?? null,
|
|
'ticket_price' => $_POST['ticket_price'] ?? null
|
|
];
|
|
|
|
$this->model->createEvent($data);
|
|
$this->view->setVars(['event' => $data]);
|
|
exit;
|
|
}
|
|
|
|
public function editEventForm() {
|
|
$id = $_GET['event_id'];
|
|
$event = $this->model->getEvent($id);
|
|
$this->view->setVars(['event' => $event]);
|
|
}
|
|
|
|
public function updateEvent($id, $data) {
|
|
$id = $_POST['event_id'];
|
|
$data = [
|
|
'location_id' => $_POST['location_id'] ?? null,
|
|
'start_date' => $_POST['start_date'] ?? null,
|
|
'end_date' => $_POST['end_date'] ?? null,
|
|
'name' => $_POST['name'] ?? null,
|
|
'description' => $_POST['description'] ?? null,
|
|
'max_tickets' => $_POST['max_tickets'] ?? null,
|
|
'ticket_price' => $_POST['ticket_price'] ?? null
|
|
];
|
|
$this->model->updateEvent($id, $data);
|
|
}
|
|
|
|
public function deleteEvent($id) {
|
|
$this->model->deleteEvent($id);
|
|
$this->view->setVars(['id' => $id]);
|
|
}
|
|
} |