Alles auf Englisch umbenannt: exhibition → event, Variablen und Tabellen angepasst, Views auf neue Felder umgestellt, Controller/Model/SQL konsistent gemacht. Alte Variablennamen raus, jetzt ist alles einheitlich. Fehler aus dem Frontend gefixt.
This commit is contained in:
57
Controller/VoucherController.php
Normal file
57
Controller/VoucherController.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Blog\Controller;
|
||||
|
||||
use Blog\Model\VoucherModel;
|
||||
|
||||
class VoucherController {
|
||||
|
||||
private $model;
|
||||
private $view;
|
||||
|
||||
public function __construct($view) {
|
||||
$this->model = new VoucherModel();
|
||||
$this->view = $view;
|
||||
}
|
||||
|
||||
public function showVouchers() {
|
||||
$vouchers = $this->model->getVouchers();
|
||||
$this->view->setVars(['vouchers' => $vouchers]);
|
||||
}
|
||||
|
||||
public function createVoucher() {
|
||||
$data = [
|
||||
'code' => $_POST['code'] ?? null,
|
||||
'discount' => $_POST['discount'] ?? null,
|
||||
'event_id' => $_POST['event_id'] ?? null,
|
||||
'valid_until' => $_POST['valid_until'] ?? null
|
||||
];
|
||||
$result = $this->model->createVoucher($data);
|
||||
$this->view->setVars(['voucher' => $result]);
|
||||
exit;
|
||||
}
|
||||
|
||||
public function editVoucherForm() {
|
||||
$id = $_GET['voucher_id'];
|
||||
if ($id) {
|
||||
$voucher = $this->model->getVoucher($id);
|
||||
$this->view->setVars(['voucher' => $voucher]);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateVoucher() {
|
||||
$id = $_POST['voucher_id'];
|
||||
$data = [
|
||||
'code' => $_POST['code'] ?? null,
|
||||
'discount' => $_POST['discount'] ?? null,
|
||||
'event_id' => $_POST['event_id'] ?? null,
|
||||
'valid_until' => $_POST['valid_until'] ?? null
|
||||
];
|
||||
$this->model->updateVoucher($id, $data);
|
||||
}
|
||||
|
||||
public function deleteVoucher() {
|
||||
$id = $_GET['voucher_id'] ?? null;
|
||||
$this->model->deleteVoucher($id);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user