| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- namespace App;
- use RuntimeException;
- /**
- * @var string $action
- */
- $controller = new class($action) {
- /** @var string */
- private $action;
- /** @var User */
- private $user;
- public function __construct(string $action) {
- $this->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();
|