Skip to content

Commit 510f272

Browse files
authored
Merge pull request #2232 from opensource-workshop/feature/faq-keyword-search
[FAQ] キーワード検索機能を追加しました
2 parents 6d4eee8 + a93cba4 commit 510f272

File tree

9 files changed

+160
-2
lines changed

9 files changed

+160
-2
lines changed

app/Enums/FaqFrameConfig.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ final class FaqFrameConfig extends EnumsBase
1212
// 定数メンバ
1313
const faq_display_created_name = 'faq_display_created_name';
1414
const faq_narrowing_down_type = 'faq_narrowing_down_type';
15+
const faq_keyword_search_display = 'faq_keyword_search_display';
1516

1617
// key/valueの連想配列
1718
const enum = [
1819
self::faq_display_created_name => '投稿者名',
1920
self::faq_narrowing_down_type => '絞り込み機能',
21+
self::faq_keyword_search_display => 'キーワード検索機能',
2022
];
2123
}

app/Plugins/User/Faqs/FaqsPlugin.php

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,23 @@ private function getPosts($faq_frame, $option_count = null)
242242
$faqs_posts->where('faqs_posts.categories_id', session('categories_id_'. $this->frame->id));
243243
}
244244

245+
// キーワード検索(タイトル、本文、カテゴリ、タグを対象)
246+
$search_keyword = session('search_keyword_'. $this->frame->id);
247+
if ($search_keyword) {
248+
$faqs_posts->where(function ($query) use ($search_keyword) {
249+
$query->where('faqs_posts.post_title', 'like', "%{$search_keyword}%")
250+
->orWhere('faqs_posts.post_text', 'like', "%{$search_keyword}%")
251+
->orWhere('categories.category', 'like', "%{$search_keyword}%")
252+
->orWhereExists(function ($subquery) use ($search_keyword) {
253+
$subquery->select(DB::raw(1))
254+
->from('faqs_posts_tags')
255+
->whereColumn('faqs_posts_tags.faqs_posts_id', 'faqs_posts.id')
256+
->where('faqs_posts_tags.tags', 'like', "%{$search_keyword}%")
257+
->whereNull('faqs_posts_tags.deleted_at');
258+
});
259+
});
260+
}
261+
245262
// 表示条件に対するソート条件追加
246263

247264
if ($faq_frame->sequence_conditions == 0) {
@@ -1177,19 +1194,39 @@ public function rss($request, $page_id, $frame_id, $id = null)
11771194
}
11781195

11791196
/**
1180-
* FAQの絞り込み
1197+
* FAQの絞り込み・検索
11811198
*/
11821199
public function search($request, $page_id, $frame_id)
11831200
{
1201+
// カテゴリ絞り込み処理
11841202
if ($request->filled('categories_id') && session('categories_id_'. $frame_id) != $request->categories_id) {
11851203
// 絞り込み条件あり
11861204
session(['categories_id_'. $frame_id => (int)$request->categories_id]);
1187-
} else {
1205+
} elseif (!$request->filled('categories_id') && !$request->filled('search_keyword')) {
11881206
// 絞り込み条件で空白を選択したとき、
11891207
// 選択中のものを再選択したときは絞り込みを解除する
11901208
session()->forget('categories_id_'. $this->frame->id);
11911209
}
11921210

1211+
// キーワード検索処理
1212+
if ($request->filled('search_keyword')) {
1213+
$search_keyword = trim($request->search_keyword);
1214+
if (!empty($search_keyword)) {
1215+
session(['search_keyword_'. $frame_id => $search_keyword]);
1216+
} else {
1217+
session()->forget('search_keyword_'. $frame_id);
1218+
}
1219+
} elseif ($request->has('search_keyword') && empty(trim($request->search_keyword))) {
1220+
// 空文字での検索時はキーワードクリア
1221+
session()->forget('search_keyword_'. $frame_id);
1222+
}
1223+
1224+
// 検索条件クリア
1225+
if ($request->filled('clear_search')) {
1226+
session()->forget('categories_id_'. $frame_id);
1227+
session()->forget('search_keyword_'. $frame_id);
1228+
}
1229+
11931230
return $this->index($request, $page_id, $frame_id);
11941231
}
11951232

@@ -1199,5 +1236,6 @@ public function search($request, $page_id, $frame_id)
11991236
private function forgetParams()
12001237
{
12011238
session()->forget('categories_id_'. $this->frame->id);
1239+
session()->forget('search_keyword_'. $this->frame->id);
12021240
}
12031241
}

resources/views/plugins/user/faqs/category/faqs.blade.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* FAQ画面テンプレート(カテゴリー別表示)
33
*
44
* @author 石垣 佑樹 <[email protected]>
5+
* @author 井上 雅人 <[email protected]>
56
* @copyright OpenSource-WorkShop Co.,Ltd. All Rights Reserved
67
* @category FAQプラグイン
78
--}}
@@ -41,6 +42,15 @@
4142

4243
{{-- FAQ表示 --}}
4344
@if (isset($faqs_posts))
45+
{{-- 検索フォーム --}}
46+
@include('plugins.user.faqs.search_form')
47+
48+
{{-- 条件クリア --}}
49+
@include('plugins.user.faqs.clear_conditions')
50+
51+
{{-- 件数表示 --}}
52+
@include('plugins.user.faqs.count_display')
53+
4454
@php
4555
$sorted_posts = $faqs_posts;
4656
if ($faq_frame->sequence_conditions != 3) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{{--
2+
* FAQ条件クリア共通部品
3+
*
4+
* @author 井上 雅人 <[email protected]>
5+
* @copyright OpenSource-WorkShop Co.,Ltd. All Rights Reserved
6+
* @category FAQプラグイン
7+
--}}
8+
9+
{{-- 条件クリアボタン --}}
10+
@if(session('search_keyword_'. $frame_id) || session('categories_id_'. $frame_id))
11+
<div class="mb-3">
12+
<form action="{{url('/')}}/plugin/faqs/search/{{$page->id}}/{{$frame_id}}/#frame-{{$frame_id}}" method="GET" style="display: inline;">
13+
<button type="submit" name="clear_search" value="1" class="btn btn-secondary btn-sm">
14+
<i class="fas fa-times" role="presentation"></i> 条件クリア
15+
</button>
16+
</form>
17+
</div>
18+
@endif
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{--
2+
* FAQ件数表示共通部品
3+
*
4+
* @author 井上 雅人 <[email protected]>
5+
* @copyright OpenSource-WorkShop Co.,Ltd. All Rights Reserved
6+
* @category FAQプラグイン
7+
--}}
8+
9+
{{-- 件数表示 --}}
10+
<div class="row mb-3">
11+
<div class="col-md-9 d-flex align-items-center">
12+
<div>
13+
表示件数 {{ $faqs_posts->total() }}
14+
{{ $faqs_posts->total() > 0 ? ' (' . $faqs_posts->firstItem() . '-' . $faqs_posts->lastItem() . ')' : '' }}
15+
</div>
16+
</div>
17+
</div>

resources/views/plugins/user/faqs/default/faqs.blade.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* FAQ画面テンプレート。
33
*
44
* @author 永原 篤 <[email protected]>
5+
* @author 井上 雅人 <[email protected]>
56
* @copyright OpenSource-WorkShop Co.,Ltd. All Rights Reserved
67
* @category FAQプラグイン
78
--}}
@@ -41,9 +42,18 @@
4142

4243
{{-- FAQ表示 --}}
4344
@if (isset($faqs_posts))
45+
{{-- 検索フォーム --}}
46+
@include('plugins.user.faqs.search_form')
47+
4448
{{-- 絞り込み機能 --}}
4549
@include('plugins.user.faqs.default.faqs_narrowing_down')
4650

51+
{{-- 条件クリア --}}
52+
@include('plugins.user.faqs.clear_conditions')
53+
54+
{{-- 件数表示 --}}
55+
@include('plugins.user.faqs.count_display')
56+
4757
<div class="accordion" id="accordionFaq{{$frame_id}}">
4858
@foreach($faqs_posts as $post)
4959
{{-- FAQの要素呼び出し --}}

resources/views/plugins/user/faqs/default/faqs_edit_faq.blade.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* FAQ編集画面テンプレート。
33
*
44
* @author 永原 篤 <[email protected]>
5+
* @author 井上 雅人 <[email protected]>
56
* @copyright OpenSource-WorkShop Co.,Ltd. All Rights Reserved
67
* @category FAQプラグイン
78
--}}
@@ -202,6 +203,30 @@
202203
</div>
203204
</div>
204205

206+
{{-- キーワード検索機能の表示 --}}
207+
<div class="form-group row">
208+
<label class="{{$frame->getSettingLabelClass(true)}}">{{FaqFrameConfig::getDescription('faq_keyword_search_display')}}</label>
209+
<div class="{{$frame->getSettingInputClass(true)}}">
210+
<div class="custom-control custom-radio custom-control-inline">
211+
@if (FrameConfig::getConfigValueAndOld($frame_configs, FaqFrameConfig::faq_keyword_search_display) === '' ||
212+
FrameConfig::getConfigValueAndOld($frame_configs, FaqFrameConfig::faq_keyword_search_display) == ShowType::not_show)
213+
<input type="radio" value="{{ShowType::not_show}}" id="{{FaqFrameConfig::faq_keyword_search_display}}_0" name="{{FaqFrameConfig::faq_keyword_search_display}}" class="custom-control-input" checked="checked">
214+
@else
215+
<input type="radio" value="{{ShowType::not_show}}" id="{{FaqFrameConfig::faq_keyword_search_display}}_0" name="{{FaqFrameConfig::faq_keyword_search_display}}" class="custom-control-input">
216+
@endif
217+
<label class="custom-control-label text-nowrap" for="{{FaqFrameConfig::faq_keyword_search_display}}_0" id="label_{{FaqFrameConfig::faq_keyword_search_display}}_0">{{ShowType::getDescription(ShowType::not_show)}}</label>
218+
</div>
219+
<div class="custom-control custom-radio custom-control-inline">
220+
@if (FrameConfig::getConfigValueAndOld($frame_configs, FaqFrameConfig::faq_keyword_search_display) == ShowType::show)
221+
<input type="radio" value="{{ShowType::show}}" id="{{FaqFrameConfig::faq_keyword_search_display}}_1" name="{{FaqFrameConfig::faq_keyword_search_display}}" class="custom-control-input" checked="checked">
222+
@else
223+
<input type="radio" value="{{ShowType::show}}" id="{{FaqFrameConfig::faq_keyword_search_display}}_1" name="{{FaqFrameConfig::faq_keyword_search_display}}" class="custom-control-input">
224+
@endif
225+
<label class="custom-control-label text-nowrap" for="{{FaqFrameConfig::faq_keyword_search_display}}_1" id="label_{{FaqFrameConfig::faq_keyword_search_display}}_1">{{ShowType::getDescription(ShowType::show)}}</label>
226+
</div>
227+
</div>
228+
</div>
229+
205230

206231
{{-- Submitボタン --}}
207232
<div class="form-group text-center">

resources/views/plugins/user/faqs/full_display/faqs.blade.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* FAQ画面テンプレート(Q&A全表示)
33
*
44
* @author 永原 篤 <[email protected]>
5+
* @author 井上 雅人 <[email protected]>
56
* @copyright OpenSource-WorkShop Co.,Ltd. All Rights Reserved
67
* @category FAQプラグイン
78
--}}
@@ -41,9 +42,18 @@
4142

4243
{{-- FAQ表示 --}}
4344
@if (isset($faqs_posts))
45+
{{-- 検索フォーム --}}
46+
@include('plugins.user.faqs.search_form')
47+
4448
{{-- 絞り込み機能 --}}
4549
@include('plugins.user.faqs.default.faqs_narrowing_down')
4650

51+
{{-- 条件クリア --}}
52+
@include('plugins.user.faqs.clear_conditions')
53+
54+
{{-- 件数表示 --}}
55+
@include('plugins.user.faqs.count_display')
56+
4757
<div class="faq-list-full-display">
4858
@foreach($faqs_posts as $post)
4959
{{-- FAQの要素呼び出し --}}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{{--
2+
* FAQ検索フォーム共通部品
3+
*
4+
* @author 井上 雅人 <[email protected]>
5+
* @copyright OpenSource-WorkShop Co.,Ltd. All Rights Reserved
6+
* @category FAQプラグイン
7+
--}}
8+
9+
@if (FrameConfig::getConfigValue($frame_configs, FaqFrameConfig::faq_keyword_search_display) == ShowType::show)
10+
<div class="faq-search-form mb-3">
11+
<form action="{{url('/')}}/plugin/faqs/search/{{$page->id}}/{{$frame_id}}/#frame-{{$frame_id}}" method="GET" name="search_form{{$frame_id}}" role="search" aria-label="FAQ検索">
12+
<div class="input-group mb-2">
13+
<input type="text"
14+
class="form-control"
15+
name="search_keyword"
16+
value="{{session('search_keyword_'. $frame_id)}}"
17+
placeholder="検索はキーワードを入力してください。"
18+
title="検索キーワード"
19+
id="search_keyword_{{$frame_id}}">
20+
<div class="input-group-append">
21+
<button type="submit" class="btn btn-primary" title="検索">
22+
<i class="fas fa-search" role="presentation"></i>
23+
</button>
24+
</div>
25+
</div>
26+
</form>
27+
</div>
28+
@endif

0 commit comments

Comments
 (0)