action = $action; $core = Core::getInstance(); $this->user = $core->getUser(); } public function run(): void { switch($this->action) { case "create": $this->create(); break; default: throw new RuntimeException(__("Invalid action.")); } } private function create(): void { $attachments = Request::getFileArray("attachments", true); $request = Request::fromRequest(); $ticket = new Ticket(); $ticket->location_id = $request->int("location_id"); $ticket->creator_user_id = $this->user->id; $ticket->subject = $request->string("subject"); $ticket->contact_name = $request->string("contact_name"); $ticket->dts_created = Database::dts(); $ticket->commit(); $comment = new TicketComment(); $comment->ticket_id = $ticket->id; $comment->user_id = $this->user->id; $comment->content = $request->string("content"); $comment->dts_created = Database::dts(); $comment->commit(); foreach($attachments as $attachment) { $comment->addAttachment($attachment); } Session::addAlert("success", __("Ticket created successfully.")); Json::success([ "id" => $ticket->id ]); } }; $controller->run();