Преглед на файлове

Editable Ticket categories

1day2die преди 2 години
родител
ревизия
630ebc6b88

+ 120 - 0
app/Http/Controllers/Moderation/TicketCategoryController.php

@@ -0,0 +1,120 @@
+<?php
+
+namespace App\Http\Controllers\Moderation;
+
+use App\Http\Controllers\Controller;
+use App\Models\Ticket;
+use App\Models\TicketCategory;
+use Illuminate\Http\Request;
+
+class TicketCategoryController extends Controller
+{
+    /**
+     * Display a listing of the resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function index()
+    {
+
+        return view('moderator.ticket.category');
+    }
+
+    /**
+     * Store a newly created resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return \Illuminate\Http\Response
+     */
+    public function store(Request $request)
+    {
+        $request->validate([
+            'name' => 'required|string|max:191',
+        ]);
+
+        TicketCategory::create($request->all());
+
+
+        return redirect(route("moderator.ticket.category.index"))->with("success",__("Category created"));
+    }
+
+
+    /**
+     * Show the form for editing the specified resource.
+     *
+     * @param  int  $id
+     * @return \Illuminate\Http\Response
+     */
+    public function edit($id)
+    {
+        //
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  int  $id
+     * @return \Illuminate\Http\Response
+     */
+    public function update(Request $request, $id)
+    {
+        //
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  int  $id
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy($id)
+    {
+        $category = TicketCategory::where("id",$id)->firstOrFail();
+
+        if($category->id == 5 ){ //cannot delete "other" category
+            return back()->with("error","You cannot delete that category");
+        }
+
+        $tickets = Ticket::where("ticketcategory_id",$category->id)->get();
+
+        foreach($tickets as $ticket){
+            $ticket->ticketcategory_id = "5";
+            $ticket->save();
+        }
+
+        $category->delete();
+
+        return redirect()
+            ->route('moderator.ticket.category.index')
+            ->with('success', __('Category removed'));
+    }
+
+    public function datatable()
+    {
+        $query = TicketCategory::withCount("tickets");
+
+        return datatables($query)
+            ->addColumn('name', function ( TicketCategory $category) {
+                return $category->name;
+            })
+            ->editColumn('tickets', function ( TicketCategory $category) {
+                return $category->tickets_count;
+            })
+            ->addColumn('actions', function (TicketCategory $category) {
+                return '
+
+                           <form class="d-inline" onsubmit="return submitResult();" method="post" action="'.route('moderator.ticket.category.destroy', $category->id).'">
+                            '.csrf_field().'
+                            '.method_field('DELETE').'
+                           <button data-content="'.__('Delete').'" data-toggle="popover" data-trigger="hover" data-placement="top" class="btn btn-sm btn-danger mr-1"><i class="fas fa-trash"></i></button>
+                       </form>
+                ';
+            })
+            ->editColumn('created_at', function (TicketCategory $category) {
+                return $category->created_at ? $category->created_at->diffForHumans() : '';
+            })
+            ->rawColumns(['actions'])
+            ->make();
+    }
+}

+ 1 - 1
app/Models/TicketCategory.php

@@ -10,6 +10,6 @@ class TicketCategory extends Model
 
     public function tickets()
     {
-        return $this->hasMany(Ticket::class);
+        return $this->hasMany(Ticket::class,'ticketcategory_id');
     }
 }

+ 8 - 0
routes/web.php

@@ -21,6 +21,7 @@ use App\Http\Controllers\Admin\UserController;
 use App\Http\Controllers\Admin\VoucherController;
 use App\Http\Controllers\Auth\SocialiteController;
 use App\Http\Controllers\HomeController;
+use App\Http\Controllers\Moderation\TicketCategoryController;
 use App\Http\Controllers\Moderation\TicketsController as ModTicketsController;
 use App\Http\Controllers\NotificationController;
 use App\Http\Controllers\ProductController as FrontProductController;
@@ -218,6 +219,13 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () {
         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('ticket/category', [TicketCategoryController::class, 'index'])->name('ticket.category.index');
+        Route::get('ticket/category/datatable', [TicketCategoryController::class, 'datatable'])->name('ticket.category.datatable');
+        Route::post('ticket/category', [TicketCategoryController::class, 'store'])->name('ticket.category.store');
+        Route::delete('ticket/category/destroy/{id}', [TicketCategoryController::class, 'destroy'])->name('ticket.category.destroy');
+
     });
 
     Route::get('/home', [HomeController::class, 'index'])->name('home');

+ 100 - 0
themes/default/views/moderator/ticket/category.blade.php

@@ -0,0 +1,100 @@
+@extends('layouts.main')
+
+@section('content')
+    <!-- CONTENT HEADER -->
+    <section class="content-header">
+        <div class="container-fluid">
+            <div class="row mb-2">
+                <div class="col-sm-6">
+                    <h1>{{ __('Ticket Categories') }}</h1>
+                </div>
+                <div class="col-sm-6">
+                    <ol class="breadcrumb float-sm-right">
+                        <li class="breadcrumb-item"><a href="{{ route('home') }}">{{ __('Dashboard') }}</a></li>
+                        <li class="breadcrumb-item"><a class="text-muted"
+                                                       href="{{ route("moderator.ticket.category.index") }}">{{ __('Ticket Categories') }}</a>
+                        </li>
+                    </ol>
+                </div>
+            </div>
+        </div>
+    </section>
+    <!-- END CONTENT HEADER -->
+
+    <!-- MAIN CONTENT -->
+    <section class="content">
+        <div class="container-fluid">
+            <div class="row">
+                <div class="col-lg-8">
+                    <div class="card">
+                        <div class="card-header">
+                            <div class="d-flex justify-content-between">
+                                <h5 class="card-title"><i class="fas fas fa-users mr-2"></i>{{__('Categories')}}</h5>
+                            </div>
+                        </div>
+                        <div class="card-body table-responsive">
+
+                            <table id="datatable" class="table table-striped">
+                                <thead>
+                                <tr>
+                                    <th>{{__('ID')}}</th>
+                                    <th>{{__('Name')}}</th>
+                                    <th>{{__('Tickets')}}</th>
+                                    <th>{{__('Created At')}}</th>
+                                    <th>{{__('Actions')}}</th>
+                                </tr>
+                                </thead>
+                                <tbody>
+                                </tbody>
+                            </table>
+                        </div>
+                    </div>
+                </div>
+                <div class="col-lg-4">
+                    <div class="card">
+                        <div class="card-header">
+                            <h5 class="card-title">{{__('Add Category')}}
+                        </div>
+                        <div class="card-body">
+                            <form action="{{route("moderator.ticket.category.store")}}" method="POST" class="ticket-form">
+                            @csrf
+                                <div class="form-group ">
+                                    <label for="name" class="control-label">{{__("Name")}}</label>
+                                    <input id="name" type="text" class="form-control" name="name" required>
+                                </div>
+                                <button type="submit" class="btn btn-primary">
+                                    {{__('Submit')}}
+                                </button>
+                            </form>
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </section>
+    <!-- END CONTENT -->
+    <script>
+        document.addEventListener("DOMContentLoaded", function () {
+            $('#datatable').DataTable({
+                language: {
+                    url: '//cdn.datatables.net/plug-ins/1.11.3/i18n/{{config("SETTINGS::LOCALE:DATATABLES")}}.json'
+                },
+                processing: true,
+                serverSide: true,
+                stateSave: true,
+                ajax: "{{route('moderator.ticket.category.datatable')}}",
+                columns: [
+                    {data: 'id'},
+                    {data: 'name'},
+                    {data: 'tickets'},
+                    {data: 'created_at', sortable: false},
+                    {data: 'actions', sortable: false},
+                ],
+                fnDrawCallback: function( oSettings ) {
+                    $('[data-toggle="popover"]').popover();
+                }
+            });
+        });
+    </script>
+@endsection
+

+ 3 - 0
themes/default/views/moderator/ticket/index.blade.php

@@ -30,8 +30,11 @@
                     <div class="d-flex justify-content-between">
                         <h5 class="card-title"><i class="fas fa-ticket-alt mr-2"></i>{{__('Ticket List')}}</h5>
                     </div>
+                    <a href="{{route("moderator.ticket.category.index")}}"><button class="btn btn-primary float-right">+ {{__("Add Category")}}</button></a>
                 </div>
 
+
+
                 <div class="card-body table-responsive">
 
                     <table id="datatable" class="table table-striped">