Skip to content
Merged
26 changes: 26 additions & 0 deletions app/Enums/SpamBlockType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Enums;

/**
* スパムブロック種別
*
* @author 井上 雅人 <inoue@opensource-workshop.jp / masamasamasato0216@gmail.com>
* @copyright OpenSource-WorkShop Co.,Ltd. All Rights Reserved
* @category スパム管理
* @package Enum
*/
class SpamBlockType extends EnumsBase
{
// 定数メンバ
const email = 'email';
const domain = 'domain';
const ip_address = 'ip_address';

// key/valueの連想配列
const enum = [
self::email => 'メールアドレス',
self::domain => 'ドメイン',
self::ip_address => 'IPアドレス',
];
}
101 changes: 101 additions & 0 deletions app/Models/Common/SpamList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

namespace App\Models\Common;

use App\UserableNohistory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
* スパムリストモデル
*
* @author 井上 雅人 <inoue@opensource-workshop.jp / masamasamasato0216@gmail.com>
* @copyright OpenSource-WorkShop Co.,Ltd. All Rights Reserved
* @category スパム管理
* @package Model
*/
class SpamList extends Model
{
// 保存時のユーザー関連データの保持(履歴なしUserable)
use HasFactory;
use UserableNohistory;
use SoftDeletes;

/**
* create()やupdate()で入力を受け付ける ホワイトリスト
*/
protected $fillable = [
'target_plugin_name',
'target_id',
'block_type',
'block_value',
'memo',
];

/**
* フォームプラグイン用のスパムリストを取得
*
* @param int|null $forms_id フォームID(nullの場合は全体のみ)
* @return \Illuminate\Database\Eloquent\Collection
*/
public static function getFormsSpamLists($forms_id = null)
{
$query = self::where('target_plugin_name', 'forms');

if ($forms_id) {
$query->where(function ($q) use ($forms_id) {
$q->where('target_id', $forms_id)
->orWhereNull('target_id');
});
} else {
$query->whereNull('target_id');
}

return $query->orderBy('block_type')
->orderBy('created_at', 'desc')
->get();
}

/**
* 全体適用かどうか
*
* @return bool
*/
public function isGlobalScope()
{
return is_null($this->target_id);
}

/**
* 重複チェック付きでスパムリストに追加
*
* @param string $target_plugin_name 対象プラグイン名
* @param int|null $target_id 対象ID(nullの場合は全体適用)
* @param string $block_type ブロック種別
* @param string $block_value ブロック対象の値
* @param string|null $memo メモ
* @return bool 追加成功時true、重複時false
*/
public static function addIfNotExists($target_plugin_name, $target_id, $block_type, $block_value, $memo = null)
{
$exists = self::where('target_plugin_name', $target_plugin_name)
->where('target_id', $target_id)
->where('block_type', $block_type)
->where('block_value', $block_value)
->exists();

if ($exists) {
return false;
}

self::create([
'target_plugin_name' => $target_plugin_name,
'target_id' => $target_id,
'block_type' => $block_type,
'block_value' => $block_value,
'memo' => $memo,
]);
return true;
}
}
9 changes: 6 additions & 3 deletions app/Models/User/Forms/Forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace App\Models\User\Forms;

use Illuminate\Database\Eloquent\Model;

use App\UserableNohistory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Forms extends Model
{
// 保存時のユーザー関連データの保持(履歴なしUserable)
use HasFactory;
use UserableNohistory;

/**
Expand Down Expand Up @@ -45,7 +46,9 @@ class Forms extends Model
'data_save_flag',
'after_message',
'numbering_use_flag',
'numbering_prefix'
'numbering_prefix',
'use_spam_filter_flag',
'spam_filter_message',
];

/**
Expand Down
5 changes: 3 additions & 2 deletions app/Models/User/Forms/FormsColumns.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace App\Models\User\Forms;

use Illuminate\Database\Eloquent\Model;

use App\UserableNohistory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class FormsColumns extends Model
{
// 保存時のユーザー関連データの保持(履歴なしUserable)
use HasFactory;
use UserableNohistory;

// 更新する項目の定義
Expand Down
5 changes: 3 additions & 2 deletions app/Models/User/Forms/FormsInputCols.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace App\Models\User\Forms;

use Illuminate\Database\Eloquent\Model;

use App\UserableNohistory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class FormsInputCols extends Model
{
// 保存時のユーザー関連データの保持(履歴なしUserable)
use HasFactory;
use UserableNohistory;

// 更新する項目の定義
Expand Down
5 changes: 3 additions & 2 deletions app/Models/User/Forms/FormsInputs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace App\Models\User\Forms;

use Illuminate\Database\Eloquent\Model;

use App\UserableNohistory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class FormsInputs extends Model
{
// 保存時のユーザー関連データの保持(履歴なしUserable)
use HasFactory;
use UserableNohistory;

// 更新する項目の定義
Expand Down
Loading