| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?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
- ];
- $tickets = Ticket::query($nvp, ["sort" => "dts_updated", "order" => "desc"]);
- View::include("header");
- View::include("tickets", compact("tickets"));
- View::include("modals/ticket");
- View::include("footer");
|