Skip to content

Commit 18b960f

Browse files
authored
Merge pull request #1967 from opensource-workshop/add-view-count-spectator
[データベース]閲覧者による表示件数の変更機能を追加しました
2 parents d6ae4dd + 187275c commit 18b960f

File tree

7 files changed

+114
-0
lines changed

7 files changed

+114
-0
lines changed

app/Enums/DatabaseFrameConfig.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ final class DatabaseFrameConfig extends EnumsBase
1515
const database_trend_words = 'database_trend_words';
1616
const database_trend_words_caption = 'database_trend_words_caption';
1717
const database_destination_frame = 'database_destination_frame';
18+
const database_view_count_spectator = 'database_view_count_spectator';
19+
const database_page_total_views = 'database_page_total_views';
1820

1921
// key/valueの連想配列
2022
const enum = [
@@ -23,5 +25,7 @@ final class DatabaseFrameConfig extends EnumsBase
2325
self::database_trend_words => '急上昇ワード',
2426
self::database_trend_words_caption => '急上昇ワード表示項目名',
2527
self::database_destination_frame => '検索後の遷移先',
28+
self::database_view_count_spectator => '表示件数リストの表示',
29+
self::database_page_total_views => '表示件数の表示',
2630
];
2731
}

app/Plugins/User/Databases/DatabasesPlugin.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public function getPublicFunctions()
110110
'cancel',
111111
'addPref',
112112
'search',
113+
'indexCount',
113114
];
114115
return $functions;
115116
}
@@ -767,6 +768,7 @@ public function index($request, $page_id, $frame_id)
767768
if ($databases_frames) {
768769
$get_count = $databases_frames->view_count;
769770
}
771+
$get_count = session("view_count_spectator_{$frame_id}", $get_count);
770772
$inputs = $inputs_query->paginate($get_count, ["*"], $this->pageName($frame_id));
771773

772774
// 登録データ行のタイトル取得
@@ -863,6 +865,7 @@ public function index($request, $page_id, $frame_id)
863865
'default_hide_list' => $default_hide_list,
864866
'frame_configs' => $this->frame_configs,
865867
'dest_frame' =>$this->getDestinationFrame(),
868+
'view_count' => $get_count ?? null,
866869
// change: 同ページに(a)データベースプラグイン,(b)フォームを配置して(b)フォームで入力エラーが起きても、入力値が復元しないバグ対応。
867870
// ])->withInput($request->all);
868871
]);
@@ -4506,4 +4509,14 @@ private function getDestinationFrame(): Frame
45064509
}
45074510
return $frame;
45084511
}
4512+
4513+
/**
4514+
* 件数指定
4515+
*/
4516+
public function indexCount($request, $page_id, $frame_id)
4517+
{
4518+
session(["view_count_spectator_{$frame_id}" => $request->input("view_count_spectator")]);
4519+
4520+
// リダイレクト先を指定しないため、画面から渡されたredirect_pathに飛ぶ
4521+
}
45094522
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
@if ($default_hide_list)
1919
@else
20+
{{-- データベースの表示件数変更セレクトボックス --}}
21+
@include('plugins.user.databases.default.databases_include_view_count')
22+
{{-- 現在表示している件数テキスト --}}
23+
@include('plugins.user.databases.default.databases_include_page_total_views')
2024
@forelse($inputs as $input)
2125
<div class="container @if(! $loop->first) mt-4 @endif">
2226
{{-- 行グループ ループ --}}

resources/views/plugins/user/databases/default/databases_edit_view.blade.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,44 @@ class="custom-control-input" @if(old('database_destination_frame', $database_des
362362
</div>
363363
</div>
364364

365+
{{-- 表示件数リストの表示 --}}
366+
@php
367+
$view_count_spectator = FrameConfig::getConfigValueAndOld($frame_configs, DatabaseFrameConfig::database_view_count_spectator, ShowType::not_show);
368+
@endphp
369+
<div class="form-group row">
370+
<label class="{{$frame->getSettingLabelClass(true)}}">{{DatabaseFrameConfig::getDescription('database_view_count_spectator')}}</label>
371+
<div class="{{$frame->getSettingInputClass()}}">
372+
@foreach (ShowType::getMembers() as $key => $type)
373+
<div class="custom-control custom-radio custom-control-inline">
374+
<input type="radio" value="{{$key}}" id="view_count_spectator{{$key}}" name="database_view_count_spectator" class="custom-control-input" @if ($view_count_spectator == $key) checked="checked" @endif>
375+
<label class="custom-control-label" for="view_count_spectator{{$key}}" id="view_count_spectator{{$key}}">{{$type}}</label>
376+
</div>
377+
@endforeach
378+
<small class="form-text text-muted">
379+
表示する場合、閲覧者が表示件数を変更できます。
380+
</small>
381+
</div>
382+
</div>
383+
384+
{{-- 表示件数の表示 --}}
385+
@php
386+
$page_total_views = FrameConfig::getConfigValueAndOld($frame_configs, DatabaseFrameConfig::database_page_total_views, ShowType::not_show);
387+
@endphp
388+
<div class="form-group row">
389+
<label class="{{$frame->getSettingLabelClass(true)}}">{{DatabaseFrameConfig::getDescription('database_page_total_views')}}</label>
390+
<div class="{{$frame->getSettingInputClass()}}">
391+
@foreach (ShowType::getMembers() as $key => $type)
392+
<div class="custom-control custom-radio custom-control-inline">
393+
<input type="radio" value="{{$key}}" id="page_total_views{{$key}}" name="database_page_total_views" class="custom-control-input" @if ($page_total_views == $key) checked="checked" @endif>
394+
<label class="custom-control-label" for="page_total_views{{$key}}" id="page_total_views{{$key}}">{{$type}}</label>
395+
</div>
396+
@endforeach
397+
<small class="form-text text-muted">
398+
表示している一覧の件数と総件数を表示します。
399+
</small>
400+
</div>
401+
</div>
402+
365403
{{-- Submitボタン --}}
366404
<div class="form-group text-center">
367405
<div class="row">
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{{--
2+
* 現在表示している件数テキスト
3+
*
4+
* @author 石垣 佑樹 <ishigaki@opensource-workshop.jp>
5+
* @copyright OpenSource-WorkShop Co.,Ltd. All Rights Reserved
6+
* @category データベース・プラグイン
7+
--}}
8+
{{-- 現在表示している件数 --}}
9+
@php
10+
$page_total_views = FrameConfig::getConfigValueAndOld($frame_configs, DatabaseFrameConfig::database_page_total_views, ShowType::not_show);
11+
@endphp
12+
@if ($page_total_views == ShowType::show && $inputs->isNotEmpty())
13+
<div class="text-right mb-2 database-page-total-views">
14+
<span class="database-page-total-views-text">{{$inputs->firstItem()}}{{$inputs->lastItem()}} 件を表示 / 全 {{$inputs->total()}} 件</span>
15+
</div>
16+
@endif
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{{--
2+
* データベースの表示件数変更セレクトボックス
3+
*
4+
* @author 石垣 佑樹 <ishigaki@opensource-workshop.jp>
5+
* @copyright OpenSource-WorkShop Co.,Ltd. All Rights Reserved
6+
* @category データベース・プラグイン
7+
--}}
8+
{{-- 件数変更 --}}
9+
@php
10+
$view_count_spectator = FrameConfig::getConfigValueAndOld($frame_configs, DatabaseFrameConfig::database_view_count_spectator, ShowType::not_show);
11+
@endphp
12+
@if ($view_count_spectator == ShowType::show && $inputs->isNotEmpty())
13+
<div class="float-right mb-2 database-view-count-select">
14+
<form action="{{url('/')}}/redirect/plugin/databases/indexCount/{{$dest_frame->page->id}}/{{$dest_frame->id}}#frame-{{$dest_frame->id}}" method="POST" role="indexCount" aria-label="{{$database_frame->databases_name}}" name="view_count_spectator_{{$frame_id}}">
15+
{{ csrf_field() }}
16+
<input type="hidden" name="redirect_path" value="{{$dest_frame->page->getLinkUrl()}}?frame_{{$dest_frame->id}}_page=1#frame-{{$dest_frame->id}}">
17+
{{-- 表示件数リスト --}}
18+
@php
19+
// 1,5,10,20+表示件数でリストを作成する
20+
$view_count_options = [1, 5, 10, 20];
21+
if ($databases_frames->view_count) {
22+
$view_count_options[] = $databases_frames->view_count;
23+
}
24+
$view_count_options = collect($view_count_options)->unique()->sort();
25+
@endphp
26+
27+
<select class="form-control form-control-sm" name="view_count_spectator" onchange="document.forms.view_count_spectator_{{$frame_id}}.submit();">
28+
@foreach ($view_count_options as $num)
29+
<option value="{{$num}}" @if($view_count == $num) selected @endif>{{$num}}件</option>
30+
@endforeach
31+
</select>
32+
</form>
33+
</div>
34+
<div class="clearfix"></div>
35+
@endif

resources/views/plugins/user/databases/design-table-dl/databases.blade.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
@if ($default_hide_list)
1818
@else
19+
{{-- データベースの表示件数変更セレクトボックス --}}
20+
@include('plugins.user.databases.default.databases_include_view_count')
21+
{{-- 現在表示している件数テキスト --}}
22+
@include('plugins.user.databases.default.databases_include_page_total_views')
1923
@if($inputs->isNotEmpty())
2024
{{-- データのループ --}}
2125
<table class="table table-bordered">

0 commit comments

Comments
 (0)