fix: 🚑️ Harmonize formatting and merge some try catch
This commit is contained in:
parent
371a37df7a
commit
e78bd37da0
|
@ -39,7 +39,7 @@ class TicketsController extends Controller
|
|||
}
|
||||
|
||||
public function changeStatus($ticket_id)
|
||||
{
|
||||
{
|
||||
try {
|
||||
$ticket = Ticket::where('ticket_id', $ticket_id)->firstOrFail();
|
||||
} catch(Exception $e)
|
||||
|
@ -66,7 +66,6 @@ class TicketsController extends Controller
|
|||
} catch (Exception $e)
|
||||
{
|
||||
return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier'));
|
||||
|
||||
}
|
||||
|
||||
TicketComment::where('ticket_id', $ticket->id)->delete();
|
||||
|
@ -80,11 +79,8 @@ class TicketsController extends Controller
|
|||
$this->validate($request, ['ticketcomment' => 'required']);
|
||||
try {
|
||||
$ticket = Ticket::where('id', $request->input('ticket_id'))->firstOrFail();
|
||||
|
||||
}
|
||||
catch (Exception $e){
|
||||
} catch (Exception $e){
|
||||
return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier'));
|
||||
|
||||
}
|
||||
$ticket->status = 'Answered';
|
||||
$ticket->update();
|
||||
|
@ -176,13 +172,12 @@ class TicketsController extends Controller
|
|||
public function blacklistAdd(Request $request)
|
||||
{
|
||||
try {
|
||||
$user = User::where('id', $request->user_id)->first();
|
||||
$user = User::where('id', $request->user_id)->firstOrFail();
|
||||
$check = TicketBlacklist::where('user_id', $user->id)->first();
|
||||
}
|
||||
catch (Exception $e){
|
||||
return redirect()->back()->with('warning', __('User not found on the server. Check the admin database or try again later.'));
|
||||
|
||||
}
|
||||
$check = TicketBlacklist::where('user_id', $user->id)->first();
|
||||
if ($check) {
|
||||
$check->reason = $request->reason;
|
||||
$check->status = 'True';
|
||||
|
@ -209,7 +204,12 @@ class TicketsController extends Controller
|
|||
|
||||
public function blacklistChange($id)
|
||||
{
|
||||
$blacklist = TicketBlacklist::where('id', $id)->first();
|
||||
try {
|
||||
$blacklist = TicketBlacklist::where('id', $id)->first();
|
||||
}
|
||||
catch (Exception $e){
|
||||
return redirect()->back()->with('warning', __('User not found on the server. Check the admin database or try again later.'));
|
||||
}
|
||||
if ($blacklist->status == 'True') {
|
||||
$blacklist->status = 'False';
|
||||
} else {
|
||||
|
|
|
@ -26,58 +26,50 @@ class TicketsController extends Controller
|
|||
return view('ticket.index', compact('tickets', 'ticketcategories'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
//check in blacklist
|
||||
$check = TicketBlacklist::where('user_id', Auth::user()->id)->first();
|
||||
if ($check && $check->status == 'True') {
|
||||
return redirect()->route('ticket.index')->with('error', __("You can't make a ticket because you're on the blacklist for a reason: '".$check->reason."', please contact the administrator"));
|
||||
}
|
||||
$ticketcategories = TicketCategory::all();
|
||||
$servers = Auth::user()->servers;
|
||||
|
||||
return view('ticket.create', compact('ticketcategories', 'servers'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'title' => 'required',
|
||||
'ticketcategory' => 'required',
|
||||
'priority' => 'required',
|
||||
'message' => 'required', ]
|
||||
'title' => 'required',
|
||||
'ticketcategory' => 'required',
|
||||
'priority' => 'required',
|
||||
'message' => 'required',]
|
||||
);
|
||||
$ticket = new Ticket([
|
||||
'title' => $request->input('title'),
|
||||
'user_id' => Auth::user()->id,
|
||||
'ticket_id' => strtoupper(Str::random(8)),
|
||||
'ticketcategory_id' => $request->input('ticketcategory'),
|
||||
'priority' => $request->input('priority'),
|
||||
'message' => $request->input('message'),
|
||||
'status' => 'Open',
|
||||
'server' => $request->input('server'), ]
|
||||
'title' => $request->input('title'),
|
||||
'user_id' => Auth::user()->id,
|
||||
'ticket_id' => strtoupper(Str::random(8)),
|
||||
'ticketcategory_id' => $request->input('ticketcategory'),
|
||||
'priority' => $request->input('priority'),
|
||||
'message' => $request->input('message'),
|
||||
'status' => 'Open',
|
||||
'server' => $request->input('server'),]
|
||||
);
|
||||
$ticket->save();
|
||||
$user = Auth::user();
|
||||
if(config('SETTINGS::TICKET:NOTIFY') == "all"){ $admin = User::where('role', 'admin')->orWhere('role', 'mod')->get();}
|
||||
if(config('SETTINGS::TICKET:NOTIFY') == "admin"){ $admin = User::where('role', 'admin')->get();}
|
||||
if(config('SETTINGS::TICKET:NOTIFY') == "moderator"){ $admin = User::where('role', 'mod')->get();}
|
||||
if (config('SETTINGS::TICKET:NOTIFY') == "all") {
|
||||
$admin = User::where('role', 'admin')->orWhere('role', 'mod')->get();
|
||||
}
|
||||
if (config('SETTINGS::TICKET:NOTIFY') == "admin") {
|
||||
$admin = User::where('role', 'admin')->get();
|
||||
}
|
||||
if (config('SETTINGS::TICKET:NOTIFY') == "moderator") {
|
||||
$admin = User::where('role', 'mod')->get();
|
||||
}
|
||||
$user->notify(new CreateNotification($ticket));
|
||||
if(config('SETTINGS::TICKET:NOTIFY') != "none"){
|
||||
if (config('SETTINGS::TICKET:NOTIFY') != "none") {
|
||||
Notification::send($admin, new AdminCreateNotification($ticket, $user));
|
||||
}
|
||||
|
||||
return redirect()->route('ticket.index')->with('success', __('A ticket has been opened, ID: #').$ticket->ticket_id);
|
||||
return redirect()->route('ticket.index')->with('success', __('A ticket has been opened, ID: #') . $ticket->ticket_id);
|
||||
}
|
||||
|
||||
public function show($ticket_id)
|
||||
{
|
||||
try {
|
||||
$ticket = Ticket::where('ticket_id', $ticket_id)->firstOrFail();
|
||||
} catch (Exception $e)
|
||||
{
|
||||
return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier'));
|
||||
}
|
||||
try {
|
||||
$ticket = Ticket::where('ticket_id', $ticket_id)->firstOrFail();
|
||||
} catch (Exception $e) {
|
||||
return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier'));
|
||||
}
|
||||
$ticketcomments = $ticket->ticketcomments;
|
||||
$ticketcategory = $ticket->ticketcategory;
|
||||
$server = Server::where('id', $ticket->server)->first();
|
||||
|
@ -90,13 +82,12 @@ class TicketsController extends Controller
|
|||
//check in blacklist
|
||||
$check = TicketBlacklist::where('user_id', Auth::user()->id)->first();
|
||||
if ($check && $check->status == 'True') {
|
||||
return redirect()->route('ticket.index')->with('error', __("You can't reply a ticket because you're on the blacklist for a reason: '".$check->reason."', please contact the administrator"));
|
||||
return redirect()->route('ticket.index')->with('error', __("You can't reply a ticket because you're on the blacklist for a reason: '" . $check->reason . "', please contact the administrator"));
|
||||
}
|
||||
$this->validate($request, ['ticketcomment' => 'required']);
|
||||
try {
|
||||
$ticket = Ticket::where('id', $request->input('ticket_id'))->firstOrFail();
|
||||
} catch (Exception $e)
|
||||
{
|
||||
$ticket = Ticket::where('id', $request->input('ticket_id'))->firstOrFail();
|
||||
} catch (Exception $e) {
|
||||
return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier'));
|
||||
}
|
||||
$ticket->status = 'Client Reply';
|
||||
|
@ -114,15 +105,28 @@ class TicketsController extends Controller
|
|||
|
||||
return redirect()->back()->with('success', __('Your comment has been submitted'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
//check in blacklist
|
||||
$check = TicketBlacklist::where('user_id', Auth::user()->id)->first();
|
||||
if ($check && $check->status == 'True') {
|
||||
return redirect()->route('ticket.index')->with('error', __("You can't make a ticket because you're on the blacklist for a reason: '" . $check->reason . "', please contact the administrator"));
|
||||
}
|
||||
$ticketcategories = TicketCategory::all();
|
||||
$servers = Auth::user()->servers;
|
||||
|
||||
return view('ticket.create', compact('ticketcategories', 'servers'));
|
||||
}
|
||||
|
||||
public function changeStatus($ticket_id)
|
||||
{
|
||||
{
|
||||
try {
|
||||
$ticket = Ticket::where('user_id', Auth::user()->id)->where("ticket_id", $ticket_id)->firstOrFail();
|
||||
} catch (Exception $e)
|
||||
{
|
||||
$ticket = Ticket::where('user_id', Auth::user()->id)->where("ticket_id", $ticket_id)->firstOrFail();
|
||||
} catch (Exception $e) {
|
||||
return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier'));
|
||||
}
|
||||
if($ticket->status == "Closed"){
|
||||
if ($ticket->status == "Closed") {
|
||||
$ticket->status = "Reopened";
|
||||
$ticket->save();
|
||||
return redirect()->back()->with('success', __('A ticket has been reopened, ID: #') . $ticket->ticket_id);
|
||||
|
@ -141,7 +145,7 @@ class TicketsController extends Controller
|
|||
return $tickets->ticketcategory->name;
|
||||
})
|
||||
->editColumn('title', function (Ticket $tickets) {
|
||||
return '<a class="text-info" href="'.route('ticket.show', ['ticket_id' => $tickets->ticket_id]).'">'.'#'.$tickets->ticket_id.' - '.htmlspecialchars($tickets->title).'</a>';
|
||||
return '<a class="text-info" href="' . route('ticket.show', ['ticket_id' => $tickets->ticket_id]) . '">' . '#' . $tickets->ticket_id . ' - ' . htmlspecialchars($tickets->title) . '</a>';
|
||||
})
|
||||
->editColumn('status', function (Ticket $tickets) {
|
||||
switch ($tickets->status) {
|
||||
|
@ -160,7 +164,7 @@ class TicketsController extends Controller
|
|||
break;
|
||||
}
|
||||
|
||||
return '<span class="badge '.$badgeColor.'">'.$tickets->status.'</span>';
|
||||
return '<span class="badge ' . $badgeColor . '">' . $tickets->status . '</span>';
|
||||
})
|
||||
->editColumn('priority', function (Ticket $tickets) {
|
||||
return __($tickets->priority);
|
||||
|
@ -175,11 +179,11 @@ class TicketsController extends Controller
|
|||
$statusButtonText = ($tickets->status == "Closed") ? __('Reopen') : __('Close');
|
||||
|
||||
return '
|
||||
<a data-content="'.__('View').'" data-toggle="popover" data-trigger="hover" data-placement="top" href="'.route('ticket.show', ['ticket_id' => $tickets->ticket_id]).'" class="btn btn-sm text-white btn-info mr-1"><i class="fas fa-eye"></i></a>
|
||||
<form class="d-inline" method="post" action="'.route('ticket.changeStatus', ['ticket_id' => $tickets->ticket_id]).'">
|
||||
'.csrf_field().'
|
||||
'.method_field('POST').'
|
||||
<button data-content="'.__($statusButtonText).'" data-toggle="popover" data-trigger="hover" data-placement="top" class="btn btn-sm text-white '.$statusButtonColor.' mr-1"><i class="fas '.$statusButtonIcon.'"></i></button>
|
||||
<a data-content="' . __('View') . '" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('ticket.show', ['ticket_id' => $tickets->ticket_id]) . '" class="btn btn-sm text-white btn-info mr-1"><i class="fas fa-eye"></i></a>
|
||||
<form class="d-inline" method="post" action="' . route('ticket.changeStatus', ['ticket_id' => $tickets->ticket_id]) . '">
|
||||
' . csrf_field() . '
|
||||
' . method_field('POST') . '
|
||||
<button data-content="' . __($statusButtonText) . '" data-toggle="popover" data-trigger="hover" data-placement="top" class="btn btn-sm text-white ' . $statusButtonColor . ' mr-1"><i class="fas ' . $statusButtonIcon . '"></i></button>
|
||||
</form>
|
||||
|
||||
</form>
|
||||
|
|
Loading…
Reference in a new issue