| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php /** @noinspection PhpUnhandledExceptionInspection */
- namespace App;
- use App\Enums\TicketStatuses;
- use RuntimeException;
- $core = Core::getInstance();
- $core->addBreadcrumb("/tickets", __("Tickets"));
- $core = Core::getInstance();
- $core->addScript("/js/ticket-modal.js");
- $request = Request::fromRequest();
- $batch_submit = $request->int("batch_submit");
- if($batch_submit) {
- $ticket_ids = $request->int("ticket_ids");
- $tickets = [];
- foreach($ticket_ids as $ticket_id) {
- $ticket = Ticket::get($ticket_id);
- if(!$ticket) {
- throw new RuntimeException(__("Ticket not found."));
- }
- $tickets[] = $ticket;
- }
- $assign_to_user = null;
- $assign_to_user_id = $request->int("assign_to");
- if($assign_to_user_id) {
- $assign_to_user = User::requireStaff($assign_to_user_id);
- }
- $status = $request->int("status");
- if($status !== null && !TicketStatuses::validate($status)) {
- throw new RuntimeException(__("Invalid status."));
- }
- foreach($tickets as $ticket) {
- if($assign_to_user_id) {
- $ticket->assign($assign_to_user);
- }
- if($status !== null) {
- $ticket->status = $status;
- $ticket->commit();
- }
- }
- Session::addAlert("success", __("Batch action applied successfully."));
- Http::redirect("/tickets");
- }
- $nvp = [
- "dts_deleted" => null
- ];
- $count = Ticket::count($nvp);
- $pagination = new Pagination($count);
- $pagination->setTerms(__("%s ticket"), __("%s tickets"));
- $tickets = Ticket::query($nvp, [
- "sort" => "dts_updated",
- "order" => "desc",
- "offset" => $pagination->getOffset(),
- "limit" => $pagination->getPageSize()
- ]);
- View::include("header");
- View::include("tickets", compact("tickets", "pagination"));
- View::include("modals/ticket");
- View::include("footer");
|