tickets.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. namespace App;
  3. use App\Enums\TicketStatuses;
  4. use RuntimeException;
  5. $core = Core::getInstance();
  6. $core->addBreadcrumb("/tickets", __("Tickets"));
  7. $core = Core::getInstance();
  8. $core->addScript("/js/ticket-modal.js");
  9. $request = Request::fromRequest();
  10. $batch_submit = $request->int("batch_submit");
  11. if($batch_submit) {
  12. $ticket_ids = $request->int("ticket_ids");
  13. $tickets = [];
  14. foreach($ticket_ids as $ticket_id) {
  15. $ticket = Ticket::get($ticket_id);
  16. if(!$ticket) {
  17. throw new RuntimeException(__("Ticket not found."));
  18. }
  19. $tickets[] = $ticket;
  20. }
  21. $assign_to_user = null;
  22. $assign_to_user_id = $request->int("assign_to");
  23. if($assign_to_user_id) {
  24. $assign_to_user = User::requireStaff($assign_to_user_id);
  25. }
  26. $status = $request->int("status");
  27. if($status !== null && !TicketStatuses::validate($status)) {
  28. throw new RuntimeException(__("Invalid status."));
  29. }
  30. foreach($tickets as $ticket) {
  31. if($assign_to_user_id) {
  32. $ticket->assign($assign_to_user);
  33. }
  34. if($status !== null) {
  35. $ticket->status = $status;
  36. $ticket->commit();
  37. }
  38. }
  39. Session::addAlert("success", __("Batch action applied successfully."));
  40. Http::redirect("/tickets");
  41. }
  42. $nvp = [
  43. "dts_deleted" => null
  44. ];
  45. $tickets = Ticket::query($nvp, ["sort" => "dts_updated", "order" => "desc"]);
  46. View::include("header");
  47. View::include("tickets", compact("tickets"));
  48. View::include("modals/ticket");
  49. View::include("footer");