tickets.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. $count = Ticket::count($nvp);
  46. $pagination = new Pagination($count);
  47. $pagination->setTerms(__("%s ticket"), __("%s tickets"));
  48. $tickets = Ticket::query($nvp, [
  49. "sort" => "dts_updated",
  50. "order" => "desc",
  51. "offset" => $pagination->getOffset(),
  52. "limit" => $pagination->getPageSize()
  53. ]);
  54. View::include("header");
  55. View::include("tickets", compact("tickets", "pagination"));
  56. View::include("modals/ticket");
  57. View::include("footer");