diff --git a/app/Controllers/EventController.php b/app/Controllers/EventController.php
index be3d08ebf332dbcf82368bf5ef45ce0fb6a44f72..ee0ac51ccf7718a274d55101d2e73018a4b3f9ca 100644
--- a/app/Controllers/EventController.php
+++ b/app/Controllers/EventController.php
@@ -3,6 +3,7 @@
ob_start();
require_once(__DIR__ . '/../Models/Event.php');
+require_once(__DIR__ . '/TicketController.php');
if (!isset($_SESSION["user_id"])) {
session_start();
@@ -20,18 +21,24 @@ class EventController {
$this->eventModel = new EventModel();
}
- public function createEvent($stock, $event_date, $event_name, $gambar, $event_location, $vid){
+ public function createEvent($event_name, $stock, $event_price, $event_date, $event_location, $gambar, $vid){
$eventModel = new EventModel();
- $eventModel->createEvent($stock, $event_date, $event_name, $gambar, $event_location, $vid);
+ $eventModel->createEvent($event_name, $stock, $event_price, $event_date, $event_location, $gambar, $vid);
+
+ $ticketController = new TicketController();
+ $event_id = $eventModel->getLastEventId();
+ for ($i = 0; $i < $stock; $i++) {
+ $ticketController->createTicket($event_name . " ticket", $event_id);
+ }
}
// public function getEvent($eventId) {
// return $this->eventModel->getEvent($eventId);
// }
- public function updateEvent($eventId, $stock, $event_date, $event_name, $event_location, $gambar, $vid){
+ public function updateEvent($eventId, $event_name, $event_price, $event_date, $event_location, $gambar, $vid){
$eventModel = new EventModel();
- $eventModel->updateEvent($eventId, $stock, $event_date, $event_name, $event_location, $gambar, $vid);
+ $eventModel->updateEvent($eventId, $event_name, $event_price, $event_date, $event_location, $gambar, $vid);
}
public function deleteEvent($eventId) {
diff --git a/app/Models/Event.php b/app/Models/Event.php
index cdfc2e1c9886d62b98451c50efe1465a12648055..4a8ee3d2a09f9e8550004588d384b064e498ef2c 100644
--- a/app/Models/Event.php
+++ b/app/Models/Event.php
@@ -5,7 +5,7 @@ require_once(__DIR__ . '/../../util.php');
class EventModel {
- public function createEvent($stock, $event_date, $event_name, $gambar, $event_location, $vid) {
+ public function createEvent($event_name, $stock, $event_price, $event_date, $event_location, $gambar, $vid) {
echo "createEvent method called<br>";
global $db;
@@ -39,20 +39,20 @@ class EventModel {
$vidFilePath = null; // Set to null if no file is uploaded
}
- $stmt = $db->prepare("INSERT INTO events (event_stock, event_date, event_name, gambar, event_location, vid) VALUES (?, ?, ?, ?, ?, ?)");
+ $stmt = $db->prepare("INSERT INTO events (event_name, event_stock, event_price, event_date, event_location, gambar, vid) VALUES (?, ?, ?, ?, ?, ?, ?)");
- if ($stmt->execute([$stock, $event_date, $event_name, $imageFilePath, $event_location, $vidFilePath])) {
+ if ($stmt->execute([$event_name, $stock, $event_price, $event_date, $event_location, $imageFilePath, $vidFilePath])) {
echo "Event created successfully";
} else {
echo "Error creating event: " . print_r($stmt->errorInfo(), true);
}
}
- public function updateEvent($event_id, $event_stock, $event_date, $event_name, $event_location, $gambar, $vid) {
+ public function updateEvent($event_id, $event_name, $event_price, $event_date, $event_location, $gambar, $vid) {
global $db;
$db->setAttribute(PDO::ATTR_AUTOCOMMIT, 1);
- echo "Updating Event with ID: $event_id, Stock: $event_stock, Date: $event_date, Name: $event_name, Location: $event_location";
+ echo "Updating Event with ID: $event_id, Name: $event_name, Price: $event_price, Date: $event_date, Location: $event_location";
if ($gambar !== null && isset($gambar['name']) && isset($gambar['tmp_name'])) {
$imageFilePath = 'assets/images/' . $gambar['name'];
@@ -91,7 +91,7 @@ class EventModel {
// $sql = "UPDATE events SET event_name = '$event_name', event_stock = '$event_stock', event_date = '$event_date', event_details = '$details', event_location = '$event_location', vid = '$vid' WHERE event_id = $event_id";
// }
- $sql = "UPDATE events SET event_stock = '$event_stock', event_date = '$event_date', event_name = '$event_name', gambar = '$imageFilePath', event_location = '$event_location', vid = '$vidFilePath' WHERE event_id = $event_id";
+ $sql = "UPDATE events SET event_name = '$event_name', event_price = '$event_price', event_date = '$event_date', event_location = '$event_location', gambar = '$imageFilePath', vid = '$vidFilePath' WHERE event_id = $event_id";
$rowCount = $db->exec($sql);
@@ -138,6 +138,12 @@ class EventModel {
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
+ public function getLastEventId() {
+ global $db;
+ $stmt = $db->prepare("SELECT event_id FROM events ORDER BY event_id DESC LIMIT 1");
+ $stmt->execute();
+ return $stmt->fetch(PDO::FETCH_ASSOC)['event_id'];
+ }
public function searchEvents($searchQuery, $sortKey, $minStock) {
global $db;