diff --git a/app/Http/Controllers/Admin/Data/FaqController.php b/app/Http/Controllers/Admin/Data/FaqController.php index 819c87cbe4..9a6d5fa510 100644 --- a/app/Http/Controllers/Admin/Data/FaqController.php +++ b/app/Http/Controllers/Admin/Data/FaqController.php @@ -26,14 +26,28 @@ class FaqController extends Controller { */ public function getFaqIndex(Request $request) { $query = Faq::query(); - $data = $request->only(['faq_category_id', 'name']); - if (isset($data['faq_category_id']) && $data['faq_category_id'] != 'none') { - $query->where('faq_category_id', $data['faq_category_id']); + $data = $request->only(['content', 'tags']); + if (isset($data['content'])) { + $content = $data['content']; + $query->where(function ($query) use ($content) { + $query->where('question', 'LIKE', '%'.$content.'%')->orWhere('answer', 'LIKE', '%'.$content.'%'); + }); } - if (isset($data['name'])) { - $query->where('name', 'LIKE', '%'.$data['name'].'%'); + + if (isset($data['tags'])) { + foreach ($data['tags'] as $tag) { + // json decode the tag column + $query->whereJsonContains('tags', $tag); + } } + $tags = Config::get('lorekeeper.faq'); + // tags is an array of names, make it so their key is their name also + $tags = array_combine($tags, $tags); + $tags = array_map(function ($tag) { + return ucwords($tag); + }, $tags); + ksort($tags); return view('admin.faq.faq', [ 'faqs' => $query->paginate(20)->appends($request->query()), 'tags' => Config::get('lorekeeper.faq'), @@ -49,10 +63,13 @@ public function getCreateFaqQuestion() { $tags = Config::get('lorekeeper.faq'); // tags is an array of names, make it so their key is their name also $tags = array_combine($tags, $tags); + $tags = array_map(function ($tag) { + return ucwords($tag); + }, $tags); + ksort($tags); return view('admin.faq.create_edit_question', [ 'faq' => new Faq, 'tags' => $tags, - ]); } @@ -71,6 +88,10 @@ public function getEditFaqQuestion($id) { $tags = Config::get('lorekeeper.faq'); // tags is an array of names, make it so their key is their name also $tags = array_combine($tags, $tags); + $tags = array_map(function ($tag) { + return ucwords($tag); + }, $tags); + ksort($tags); return view('admin.faq.create_edit_question', [ 'faq' => $faq, 'tags' => $tags, @@ -115,7 +136,7 @@ public function postCreateEditFaqQuestion(Request $request, FaqService $service, public function getDeleteFaqQuestion($id) { $faq = Faq::find($id); - return view('admin.faqs._delete_faq', [ + return view('admin.faq._delete_question', [ 'faq' => $faq, ]); } @@ -137,6 +158,6 @@ public function postDeleteFaqQuestion(Request $request, FaqService $service, $id } } - return redirect()->to('admin/data/faqs'); + return redirect()->to('admin/data/faq'); } } diff --git a/app/Http/Controllers/BrowseController.php b/app/Http/Controllers/BrowseController.php index 124eb61a9c..72737b284a 100644 --- a/app/Http/Controllers/BrowseController.php +++ b/app/Http/Controllers/BrowseController.php @@ -645,8 +645,12 @@ public function getFaq(Request $request) { $tags = Config::get('lorekeeper.faq'); // tags is an array of names, make it so their key is their name also $tags = array_combine($tags, $tags); + $tags = array_map(function ($tag) { + return ucwords($tag); + }, $tags); + ksort($tags); return view('browse.faq', [ - 'faqs' => Faq::visible(Auth::check() ? Auth::user() : null)->get(), + 'faqs' => Faq::visible(Auth::check() ? Auth::user() : null)->orderBy('created_at', 'DESC')->get(), 'tags' => $tags, ]); } @@ -673,7 +677,7 @@ public function getFaqSearch(Request $request) { $query->where('question', 'LIKE', '%'.$content.'%')->orWhere('answer', 'LIKE', '%'.$content.'%'); }); } - })->get(), + })->orderBy('created_at', 'DESC')->get(), ]); } } diff --git a/config/lorekeeper/faq.php b/config/lorekeeper/faq.php index 34badf9701..82f55211e9 100644 --- a/config/lorekeeper/faq.php +++ b/config/lorekeeper/faq.php @@ -8,6 +8,11 @@ 'lorekeeper', 'world', 'species', - 'guidelines' + 'guidelines', + 'redesigns', + 'myos', + 'items', + 'prompts', + 'events' ]; diff --git a/resources/views/admin/faq/_delete_question.blade.php b/resources/views/admin/faq/_delete_question.blade.php new file mode 100644 index 0000000000..38ae0cd842 --- /dev/null +++ b/resources/views/admin/faq/_delete_question.blade.php @@ -0,0 +1,20 @@ +@if ($faq) + {!! Form::open(['url' => 'admin/data/faq/delete/' . $faq->id]) !!} + +

+ You are about to delete the question +
+ {{ $faq->question }} +
+ This is not reversible. +

+

Are you sure you want to delete it?

+ +
+ {!! Form::submit('Delete Question', ['class' => 'btn btn-danger']) !!} +
+ + {!! Form::close() !!} +@else + Invalid question selected. +@endif diff --git a/resources/views/admin/faq/faq.blade.php b/resources/views/admin/faq/faq.blade.php index f2b9876bc8..6c8acc0592 100644 --- a/resources/views/admin/faq/faq.blade.php +++ b/resources/views/admin/faq/faq.blade.php @@ -14,12 +14,12 @@
- {!! Form::open(['method' => 'GET', 'class' => 'form-inline justify-content-end']) !!} + {!! Form::open(['method' => 'GET', 'class' => 'text-right justify-content-end']) !!}
- {!! Form::text('name', Request::get('name'), ['class' => 'form-control', 'placeholder' => 'Name']) !!} + {!! Form::text('content', Request::get('content'), ['class' => 'form-control col-md-6 ml-auto', 'placeholder' => 'Question or Answer Content']) !!}
- {!! Form::select('tags', $tags, Request::get('tags'), ['class' => 'form-control']) !!} + {!! Form::select('tags[]', $tags, Request::get('tags'), ['class' => 'form-control selectize col-md-6 ml-auto', 'multiple', 'placeholder' => 'Select Tags']) !!}
{!! Form::submit('Search', ['class' => 'btn btn-primary']) !!} @@ -82,3 +82,10 @@ {!! $faqs->render() !!} @endif @endsection +@section('scripts') + +@endsection diff --git a/resources/views/browse/_faq_question.blade.php b/resources/views/browse/_faq_question.blade.php index 5df2b775ae..7b9b9746c0 100644 --- a/resources/views/browse/_faq_question.blade.php +++ b/resources/views/browse/_faq_question.blade.php @@ -5,7 +5,8 @@ @endif {{ $faq->question }} @if ($faq->tags) - @foreach (json_decode($faq->tags) as $tag) + @php $question_tags = json_decode($faq->tags); ksort($question_tags); @endphp + @foreach ($question_tags as $tag)
{{ $tag }}
@endforeach @endif diff --git a/resources/views/browse/faq.blade.php b/resources/views/browse/faq.blade.php index a196d97907..4960b96357 100644 --- a/resources/views/browse/faq.blade.php +++ b/resources/views/browse/faq.blade.php @@ -27,7 +27,7 @@