Controller und Tickets vereinheitlicht (CRUD)

This commit is contained in:
2025-06-23 14:46:12 +02:00
parent 66ff531ba4
commit d8865cbd27
16 changed files with 559 additions and 213 deletions

View File

@@ -6,62 +6,59 @@ use Blog\Model\EventModel;
class EventController {
protected $view;
protected $eventModel;
private $model;
private $view;
public function __construct($view) {
$this->eventModel = new EventModel();
$this->model = new EventModel();
$this->view = $view;
}
public function showEvents() {
$events = $this->eventModel->getEvents();
$events = $this->model->getEvents();
$this->view->setVars([
"events" => $events
]);
}
public function getEvent() {
$ausstellungid = $_GET['ausstellungid'];
$event = $this->eventModel->getEvent($ausstellungid);
$this->view->setVars([
"event" => $event
]);
}
public function updateEvent() {
$event = array(
"ausstellungid" => $_POST['ausstellungid'],
"standortid" => $_POST['standortid'],
"datum_von" => $_POST['datumVon'],
"datum_bis" => $_POST['datumBis'],
"name" => $_POST['name'],
"beschreibung" => $_POST['beschreibung'],
"max_tickets" => $_POST['max_tickets'],
"preis" => $_POST['preis'],
);
$this->eventModel->updateEvent($event);
$this->view->setVars([
"ausstellungid" => $_POST['ausstellungid'],
'events' => $events
]);
}
public function createEvent() {
$event = array(
"standortid" => $_POST['standortid'],
"datum_von" => $_POST['datumVon'],
"datum_bis" => $_POST['datumBis'],
"name" => $_POST['name'],
"beschreibung" => $_POST['beschreibung'],
"max_tickets" => $_POST['max_tickets'],
"preis" => $_POST['preis'],
);
$data = [
'name' => $_POST['name'] ?? null,
'beschreibung' => $_POST['beschreibung'] ?? null,
'standortid' => $_POST['standortid'] ?? null,
'datum_von' => $_POST['datum_von'] ?? null,
'datum_bis' => $_POST['datum_bis'] ?? null,
'max_tickets' => $_POST['max_tickets'] ?? null,
'preis' => $_POST['preis'] ?? null
];
$this->eventModel->createEvent($event);
$this->view->setVars([
"name" => $_POST['name'],
]);
$this->model->createEvent($data);
$this->view->setVars(['event' => $data]);
exit;
}
public function editEventForm() {
$id = $_GET['ausstellungid'];
$event = $this->model->getEvent($id);
$this->view->setVars(['event' => $event]);
}
public function updateEvent($id, $data) {
$id = $_POST['ausstellungid'];
$data = [
'standortid' => $_POST['standortid'] ?? null,
'datum_von' => $_POST['datum_von'] ?? null,
'datum_bis' => $_POST['datum_bis'] ?? null,
'name' => $_POST['name'] ?? null,
'beschreibung' => $_POST['beschreibung'] ?? null,
'max_tickets' => $_POST['max_tickets'] ?? null,
'preis' => $_POST['preis'] ?? null
];
$this->model->updateEvent($id, $data);
}
public function deleteEvent($id) {
$this->model->deleteEvent($id);
$this->view->setVars(['id' => $id]);
}
}