57 lines
1.5 KiB
PHP
57 lines
1.5 KiB
PHP
<?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);
|
|
}
|
|
} |