Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions app/Enums/SearchsFrameSelect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Enums;

use App\Enums\EnumsBase;

/**
* フレームの選択
*
* @author 牟田口 満 <akagane99@gmail.com>
* @category サイト内検索
* @package Enums
*/
final class SearchsFrameSelect extends EnumsBase
{
// 定数メンバ
/** 全て表示する */
const all_frames = 0;
/** 選択したものだけ表示する */
const selected_only = 1;

/** key/valueの連想配列 */
const enum = [
self::all_frames => '全て表示する',
self::selected_only => '選択したものだけ表示する',
];
}
27 changes: 27 additions & 0 deletions app/Enums/SearchsPageSelect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Enums;

use App\Enums\EnumsBase;

/**
* ページの選択
*
* @author 牟田口 満 <akagane99@gmail.com>
* @category サイト内検索
* @package Enums
*/
final class SearchsPageSelect extends EnumsBase
{
// 定数メンバ
/** 全て表示する */
const all_pages = 0;
/** ページ管理のメニュー表示条件に従う */
const menu_visible_only = 1;

/** key/valueの連想配列 */
const enum = [
self::all_pages => '全て表示する',
self::menu_visible_only => 'ページ管理のメニュー表示条件に従う',
];
}
2 changes: 1 addition & 1 deletion app/Models/User/Searchs/Searchs.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Searchs extends Model
'frame_select',
'target_frame_ids',
'recieve_keyword',
'narrow_down_label',
'page_select',
];

/**
Expand Down
31 changes: 27 additions & 4 deletions app/Plugins/User/Searchs/SearchsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use App\Plugins\User\UserPluginBase;
use App\Traits\ConnectCommonTrait;

use App\Enums\SearchsFrameSelect;
use App\Enums\SearchsPageSelect;
use App\Enums\SearchsTargetPlugin;

/**
Expand Down Expand Up @@ -163,13 +165,13 @@ private function searchContents($request, $searchs_frame, $method = null, $narro

// 各プラグインのSQL をUNION
// 公開されているページ、フレームを検索対象とする
$searchable_page_ids = $this->fetchSearchablePageIds($request);
$searchable_page_ids = $this->fetchSearchablePageIds($request, $searchs_frame);
$searchable_frame_ids = Frame::visible()->get()->pluck('id');

foreach ($union_sqls as $union_sql) {
// フレームの選択が行われる場合
// 選択したものだけ表示する
if ($searchs_frame->frame_select == 1) {
if ($searchs_frame->frame_select == SearchsFrameSelect::selected_only) {
$union_sql->whereIn('frames.id', explode(',', $searchs_frame->target_frame_ids));
}

Expand Down Expand Up @@ -427,6 +429,7 @@ public function saveBuckets($request, $page_id, $frame_id, $id = null)
$searchs->frame_select = intval($request->frame_select);
$searchs->target_frame_ids = empty($request->target_frame_ids) ? "": implode(',', $request->target_frame_ids);
$searchs->recieve_keyword = intval($request->recieve_keyword);
$searchs->page_select = intval($request->page_select);

// データ保存
$searchs->save();
Expand Down Expand Up @@ -474,9 +477,29 @@ public function changeBuckets($request, $page_id = null, $frame_id = null, $id =
/**
* 検索対象のページIDを取得する
*/
private function fetchSearchablePageIds($request)
private function fetchSearchablePageIds($request, $searchs_frame)
{
$pages = Page::get();
// ページの選択「ページ管理のメニュー表示条件に従う」
if ($searchs_frame->page_select == SearchsPageSelect::menu_visible_only) {
// 表示ページのみをDBレベルで絞り込む
$pages = Page::where('base_display_flag', 1)->get();

// フレームの選択「選択したものだけ表示する」
if ($searchs_frame->frame_select == SearchsFrameSelect::selected_only) {
// 選択したフレームに紐づくページ を追加取得してマージ
$pages_frame = Page::whereIn('id', function ($query) use ($searchs_frame) {
$query->select('page_id')
->from('frames')
->whereIn('id', explode(',', $searchs_frame->target_frame_ids));
})->get();

$pages = $pages->merge($pages_frame)->unique('id');
}
} else {
// 全ページを検索対象とする
$pages = Page::get();
}

// 見れないページ除外
$visible_page_ids = [];
foreach ($pages as $page) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Enums\SearchsFrameSelect;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
Expand All @@ -21,7 +22,7 @@ public function up()
$table->integer('view_posted_name')->default('0');
$table->integer('view_posted_at')->default('0');
$table->text('target_plugins');
$table->integer('frame_select')->default('0');
$table->integer('frame_select')->default(SearchsFrameSelect::all_frames);
$table->text('target_frame_ids')->nullable();
$table->timestamps();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use App\Enums\SearchsPageSelect;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddSelectPageFromSearchs extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('searchs', function (Blueprint $table) {
$table->integer('page_select')->default(SearchsPageSelect::all_pages)->comment('ページの選択フラグ')->after('recieve_keyword');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('searchs', function (Blueprint $table) {
$table->dropColumn('page_select');
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* @copyright OpenSource-WorkShop Co.,Ltd. All Rights Reserved
* @category 検索プラグイン
--}}
@php
use App\Enums\SearchsFrameSelect;
use App\Enums\SearchsPageSelect;
@endphp
@extends('core.cms_frame_base_setting')

@section("core.cms_frame_edit_tab_$frame->id")
Expand Down Expand Up @@ -147,32 +151,45 @@
</div>
</div>

<div class="form-group row">
<label class="{{$frame->getSettingLabelClass()}}">ページの選択</label><br />
<div class="{{$frame->getSettingInputClass(true)}}">
@foreach (SearchsPageSelect::enum as $key => $item)
<div class="custom-control custom-radio custom-control-inline">
@if(old('page_select', $searchs->page_select) == $key)
<input type="radio" value="{{$key}}" id="page_select_{{$key}}" name="page_select" class="custom-control-input" checked="checked">
@else
<input type="radio" value="{{$key}}" id="page_select_{{$key}}" name="page_select" class="custom-control-input">
@endif
<label class="custom-control-label" for="page_select_{{$key}}">{{ SearchsPageSelect::getDescription($key) }}</label>
</div>
@endforeach
</div>
</div>

<div class="form-group row mb-0">
<label class="{{$frame->getSettingLabelClass()}}">フレームの選択</label>
<div class="{{$frame->getSettingInputClass(true)}}">
<div class="custom-control custom-radio custom-control-inline">
@if(old('frame_select', $searchs->frame_select) == 0)
<input type="radio" value="0" id="frame_select_0" name="frame_select" class="custom-control-input" checked="checked">
@else
<input type="radio" value="0" id="frame_select_0" name="frame_select" class="custom-control-input">
@endif
<label class="custom-control-label" for="frame_select_0">全て表示する</label>
</div>
<div class="custom-control custom-radio custom-control-inline">
@if(old('frame_select', $searchs->frame_select) == 1)
<input type="radio" value="1" id="frame_select_1" name="frame_select" class="custom-control-input" checked="checked">
@else
<input type="radio" value="1" id="frame_select_1" name="frame_select" class="custom-control-input">
@endif
<label class="custom-control-label" for="frame_select_1">選択したものだけ表示する</label>
</div>
@foreach (SearchsFrameSelect::enum as $key => $item)
<div class="custom-control custom-radio custom-control-inline">
@if(old('frame_select', $searchs->frame_select) == $key)
<input type="radio" value="{{$key}}" id="frame_select_{{$key}}" name="frame_select" class="custom-control-input" checked="checked">
@else
<input type="radio" value="{{$key}}" id="frame_select_{{$key}}" name="frame_select" class="custom-control-input">
@endif
<label class="custom-control-label" for="frame_select_{{$key}}">{{ SearchsFrameSelect::getDescription($key) }}</label>
</div>
@endforeach
</div>
</div>

<div class="form-group row">
<div class="{{$frame->getSettingLabelClass()}}"></div>
<div class="{{$frame->getSettingInputClass()}}">
<small class="text-muted">※ 「選択したものだけ表示する」を選択した場合、「固定記事」は検索対象外になります。</small><br>
<small class="text-muted">
※ 「選択したものだけ表示する」を選択した場合、「固定記事」は検索対象外になります。<br>
  また、メニュー非表示ページでも、選択したフレームは検索対象になります。<br>
</small>
</div>
</div>

Expand Down
Loading