| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php /** @noinspection PhpUnhandledExceptionInspection */
- namespace App;
- use App\Enums\TicketPriorities;
- use RuntimeException;
- /**
- * @var int $id
- */
- $core = Core::getInstance();
- $core->addBreadcrumb("/tickets", __("Tickets"));
- $user = $core->getUser();
- $ticket = Ticket::get($id);
- if(!$ticket) {
- throw new RuntimeException(__("Ticket not found."));
- }
- $core->addBreadcrumb("/tickets/$id", $ticket->subject);
- $request = Request::fromRequest();
- $ticket_submit = $request->int("ticket_submit");
- if($ticket_submit) {
- $assign_to_user_id = $request->int("assignee");
- $assign_to_user = null;
- if($assign_to_user_id) {
- $assign_to_user = User::requireStaff($assign_to_user_id);
- }
- $priority = $request->int("priority");
- if(!TicketPriorities::validate($priority)) {
- throw new RuntimeException(__("Invalid priority."));
- }
- if($assign_to_user) {
- if(!$assign_to_user->is($ticket->assigned_user_id)) {
- $ticket->assign($assign_to_user);
- }
- }
- else {
- $ticket->unassign();
- }
- $ticket->priority = $priority;
- $ticket->commit();
- Session::addAlert("success", __("Ticket updated successfully."));
- Http::redirect($ticket->getUrl());
- }
- $comment_submit = $request->int("comment_submit");
- if($comment_submit) {
- $content = $request->string("content");
- $internal = (int) $request->int("internal");
- $status = $request->int("status");
- $attachments = Request::getFileArray("attachments", true);
- $comment = new TicketComment();
- $comment->ticket_id = $ticket->id;
- $comment->user_id = $user->id;
- $comment->content = $content;
- $comment->internal = $internal;
- $comment->dts_created = Database::dts();
- $comment->commit();
- $ticket->status = $status;
- $ticket->commit();
- foreach($attachments as $attachment) {
- $comment->addAttachment($attachment);
- }
- Session::addAlert("success", __("Comment added successfully."));
- Http::redirect($ticket->getUrl());
- }
- View::include("header");
- View::include("ticket", compact("ticket"));
- View::include("footer");
|