From 9b3fce280883fcead401a76e4faca0f5bc6b58a7 Mon Sep 17 00:00:00 2001 From: SahrulGnwn Date: Fri, 12 Aug 2022 16:01:51 +0700 Subject: [PATCH] Ticket Blacklist --- .../Moderation/TicketsController.php | 90 ++++++++++++- app/Http/Controllers/TicketsController.php | 11 ++ app/Models/TicketBlacklist.php | 17 +++ ...1_151039_create_ticket_blacklist_table.php | 35 +++++ resources/views/layouts/main.blade.php | 8 +- .../moderator/ticket/blacklist.blade.php | 122 ++++++++++++++++++ routes/web.php | 6 + 7 files changed, 286 insertions(+), 3 deletions(-) create mode 100644 app/Models/TicketBlacklist.php create mode 100644 database/migrations/2022_08_11_151039_create_ticket_blacklist_table.php create mode 100644 resources/views/moderator/ticket/blacklist.blade.php diff --git a/app/Http/Controllers/Moderation/TicketsController.php b/app/Http/Controllers/Moderation/TicketsController.php index 4ef25bd0..a5ef8e78 100644 --- a/app/Http/Controllers/Moderation/TicketsController.php +++ b/app/Http/Controllers/Moderation/TicketsController.php @@ -7,6 +7,7 @@ use App\Models\Ticket; use App\Models\Server; use App\Models\TicketCategory; use App\Models\TicketComment; +use App\Models\TicketBlacklist; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Cache; @@ -44,12 +45,13 @@ class TicketsController extends Controller return redirect()->back()->with('success', __('A ticket has been deleted, ID: #') . $ticket_id); } + public function reply(Request $request) { $this->validate($request, array("ticketcomment" => "required")); $ticket = Ticket::where('id', $request->input("ticket_id"))->firstOrFail(); $ticket->status = "Answered"; $ticket->update(); - $ticketcomment = TicketComment::create(array( + TicketComment::create(array( "ticket_id" => $request->input("ticket_id"), "user_id" => Auth::user()->id, "ticketcomment" => $request->input("ticketcomment"), @@ -59,7 +61,7 @@ class TicketsController extends Controller $user->notify(new ReplyNotification($ticket, $user, $newmessage)); return redirect()->back()->with('success', __('Your comment has been submitted')); } - + public function dataTable() { $query = Ticket::query(); @@ -113,4 +115,88 @@ class TicketsController extends Controller ->rawColumns(['category', 'title', 'user_id', 'status', 'updated_at', 'actions']) ->make(true); } + + public function blacklist() { + $users = User::get(); + $ticketcategories = TicketCategory::all(); + return view("moderator.ticket.blacklist", compact("users", "ticketcategories")); + } + + public function blacklistAdd(Request $request) { + $user = User::where('id', $request->user_id)->first(); + $check = TicketBlacklist::where('user_id', $user->id)->first(); + if($check){ + return redirect()->back()->with('error', __('Target User already in blacklist')); + } + TicketBlacklist::create(array( + "user_id" => $user->id, + "status" => "True", + "reason" => $request->reason, + )); + return redirect()->back()->with('success', __('Successfully add User to blacklist, User name: ' . $user->name)); + } + + public function blacklistDelete($id) { + $blacklist = TicketBlacklist::where('id', $id)->first(); + $blacklist->delete(); + return redirect()->back()->with('success', __('Successfully remove User from blacklist, User name: ' . $blacklist->user->name)); + } + + public function blacklistChange($id) { + $blacklist = TicketBlacklist::where('id', $id)->first(); + if($blacklist->status == "True") + { + $blacklist->status = "False"; + + } else { + $blacklist->status = "True"; + } + $blacklist->update(); + return redirect()->back()->with('success', __('Successfully change status blacklist from, User name: ' . $blacklist->user->name)); + + } + public function dataTableBlacklist() + { + $query = TicketBlacklist::with(['user']); + + return datatables($query) + ->editColumn('user', function (TicketBlacklist $blacklist) { + return '' . $blacklist->user->name . ''; + }) + ->editColumn('status', function (TicketBlacklist $blacklist) { + switch ($blacklist->status) { + case 'True': + $badgeColor = 'badge-success'; + break; + default: + $badgeColor = 'badge-danger'; + break; + } + + return '' . $blacklist->status . ''; + }) + ->editColumn('reason', function (TicketBlacklist $blacklist) { + return $blacklist->reason; + }) + ->addColumn('actions', function (TicketBlacklist $blacklist) { + return ' +
+ ' . csrf_field() . ' + ' . method_field("POST") . ' + +
+
+ ' . csrf_field() . ' + ' . method_field("POST") . ' + +
+ '; + }) + ->editColumn('created_at', function (TicketBlacklist $blacklist) { + return $blacklist->created_at ? $blacklist->created_at->diffForHumans() : ''; + }) + ->rawColumns(['user', 'status', 'reason', 'created_at', 'actions']) + ->make(true); + } + } diff --git a/app/Http/Controllers/TicketsController.php b/app/Http/Controllers/TicketsController.php index 8f4391ce..f764da11 100644 --- a/app/Http/Controllers/TicketsController.php +++ b/app/Http/Controllers/TicketsController.php @@ -13,6 +13,7 @@ use App\Models\Ticket; use App\Models\Server; use App\Models\TicketComment; use App\Models\TicketCategory; +use App\Models\TicketBlacklist; use App\Notifications\Ticket\User\CreateNotification; use App\Notifications\Ticket\Admin\AdminCreateNotification; use App\Notifications\Ticket\Admin\AdminReplyNotification; @@ -28,6 +29,11 @@ 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->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")); @@ -65,6 +71,11 @@ class TicketsController extends Controller return view("ticket.show", compact("ticket", "ticketcategory", "ticketcomments", "server")); } public function reply(Request $request) { + #check in blacklist + $check = TicketBlacklist::where('user_id', Auth::user()->id)->first(); + if($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")); + } $this->validate($request, array("ticketcomment" => "required")); $ticket = Ticket::where('id', $request->input("ticket_id"))->firstOrFail(); $ticket->status = "Client Reply"; diff --git a/app/Models/TicketBlacklist.php b/app/Models/TicketBlacklist.php new file mode 100644 index 00000000..21ea1ff4 --- /dev/null +++ b/app/Models/TicketBlacklist.php @@ -0,0 +1,17 @@ +belongsTo(User::class, 'user_id', 'id'); + } +} + \ No newline at end of file diff --git a/database/migrations/2022_08_11_151039_create_ticket_blacklist_table.php b/database/migrations/2022_08_11_151039_create_ticket_blacklist_table.php new file mode 100644 index 00000000..d410e7fa --- /dev/null +++ b/database/migrations/2022_08_11_151039_create_ticket_blacklist_table.php @@ -0,0 +1,35 @@ +id(); + $table->unsignedBigInteger('user_id')->unsigned(); + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');; + $table->string('status'); + $table->string('reason'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('ticket_blacklists'); + } +} diff --git a/resources/views/layouts/main.blade.php b/resources/views/layouts/main.blade.php index 458a2398..11eeabbc 100644 --- a/resources/views/layouts/main.blade.php +++ b/resources/views/layouts/main.blade.php @@ -238,11 +238,17 @@ + @endif @if (Auth::user()->role == 'admin') diff --git a/resources/views/moderator/ticket/blacklist.blade.php b/resources/views/moderator/ticket/blacklist.blade.php new file mode 100644 index 00000000..8c96dbe0 --- /dev/null +++ b/resources/views/moderator/ticket/blacklist.blade.php @@ -0,0 +1,122 @@ +@extends('layouts.main') + +@section('content') + +
+
+
+
+

{{ __('Ticket Blacklist') }}

+
+ +
+
+
+ + + +
+
+
+
+
+
+
+
{{__('Blacklist List')}}
+
+
+
+ + + + + + + + + + + + + +
{{__('User')}}{{__('Status')}}{{__('Reason')}}{{__('Created At')}}{{__('Actions')}}
+
+
+
+
+
+
+
{{__('Add To Blacklist')}} +
+
+
+
+ @csrf +
+ + +
+
+ + +
+ +
+
+
+
+
+
+
+ + + +@endsection + diff --git a/routes/web.php b/routes/web.php index 7a0f85c4..5ece4b0b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -186,6 +186,12 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () { Route::post('ticket/reply', [ModTicketsController::class, 'reply'])->name('ticket.reply'); Route::post('ticket/close/{ticket_id}', [ModTicketsController::class, 'close'])->name('ticket.close'); Route::post('ticket/delete/{ticket_id}', [ModTicketsController::class, 'delete'])->name('ticket.delete'); + #ticket moderation blacklist + Route::get('ticket/blacklist', [ModTicketsController::class, 'blacklist'])->name('ticket.blacklist'); + Route::post('ticket/blacklist', [ModTicketsController::class, 'blacklistAdd'])->name('ticket.blacklist.add'); + Route::post('ticket/blacklist/delete/{id}', [ModTicketsController::class, 'blacklistDelete'])->name('ticket.blacklist.delete'); + Route::post('ticket/blacklist/change/{id}', [ModTicketsController::class, 'blacklistChange'])->name('ticket.blacklist.change'); + Route::get('ticket/blacklist/datatable', [ModTicketsController::class, 'dataTableBlacklist'])->name('ticket.blacklist.datatable'); }); Route::get('/home', [HomeController::class, 'index'])->name('home');