ticket.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. namespace App;
  3. use RuntimeException;
  4. /**
  5. * @var int $id
  6. */
  7. $core = Core::getInstance();
  8. $core->addBreadcrumb("/tickets", __("Tickets"));
  9. $user = $core->getUser();
  10. $ticket = Ticket::get($id);
  11. if(!$ticket) {
  12. throw new RuntimeException(__("Ticket not found."));
  13. }
  14. $core->addBreadcrumb("/tickets/$id", $ticket->subject);
  15. $request = Request::fromRequest();
  16. $submit = $request->int("submit");
  17. if($submit) {
  18. $content = $request->string("content");
  19. $internal = (int) $request->int("internal");
  20. $status = $request->int("status");
  21. $attachments = Request::getFileArray("attachments", true);
  22. $comment = new TicketComment();
  23. $comment->ticket_id = $ticket->id;
  24. $comment->user_id = $user->id;
  25. $comment->content = $content;
  26. $comment->internal = $internal;
  27. $comment->dts_created = Database::dts();
  28. $comment->commit();
  29. $ticket->status = $status;
  30. $ticket->commit();
  31. foreach($attachments as $attachment) {
  32. $comment->addAttachment($attachment);
  33. }
  34. Session::addAlert("success", __("Comment added successfully."));
  35. Http::redirect($ticket->getUrl());
  36. }
  37. View::include("header");
  38. View::include("ticket", compact("ticket"));
  39. View::include("footer");