krgm.so-manager-dev.com/app/Models/Ope.php
2025-10-03 18:27:14 +09:00

181 lines
5.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Models;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use App\Utils;
/**
* オペレータ認証モデル
* Laravel 12変更点App\ModelsディレクトリからApp\Modelsディレクトリに移動
* Laravel 5.7: App直下に配置されていた
*/
class Ope extends Authenticatable
{
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
// オペレータタイプ定数(旧システムから継承)
const OPE_TYPE = [
'管理者',
'マネージャー',
'オペレーター',
'エリアマネージャー',
];
protected $table = 'ope'; // データベーステーブル名(旧システムと同じ)
protected $primaryKey = 'ope_id'; // プライマリキー(旧システムと同じ)
/**
* 一括代入可能な属性
* Laravel 5.7から引き継いだフィールド構成
*/
protected $fillable = [
'//TODO オペレータID not found in database specs',
'login_id', // ログインID
'password', // パスワード
'ope_name', // オペレータ名
'ope_type', // オペレータ種別
'ope_mail', // メールアドレス(複数可)
'ope_phone', // 電話番号
'ope_sendalart_que1',
'ope_sendalart_que2',
'ope_sendalart_que3',
'ope_sendalart_que4',
'ope_sendalart_que5',
'ope_sendalart_que6',
'ope_sendalart_que7',
'ope_sendalart_que8',
'ope_sendalart_que9',
'ope_sendalart_que10',
'ope_sendalart_que11',
'ope_sendalart_que12',
'ope_sendalart_que13',
'ope_auth1',
'ope_auth2',
'ope_auth3',
'ope_auth4',
'ope_quit_flag',
'ope_quitday',
];
/**
* 認証用パスワードを取得
* Laravel 12変更点ope_passフィールドを認証パスワードとして使用
*
* @return string
*/
public function getAuthPassword()
{
return $this->ope_pass;
}
/**
* passwordフィールドアクセサー読み取り用
* Laravel 12対応Laravel認証システムがpasswordフィールドを読み取る際にope_passの値を返す
* Laravel 5.7との差異:旧システムでは不要だった仮想フィールド対応
*
* @return string|null
*/
public function getPasswordAttribute()
{
// データベースのope_passフィールドの値を返す
return $this->attributes['ope_pass'] ?? null;
}
/**
* passwordフィールドミューテータ書き込み用
* Laravel 12対応Laravel認証システムがpasswordフィールドを更新する際にope_passフィールドに保存
* Laravel 5.7との差異:旧システムでは不要だった仮想フィールド対応
*
* @param string $value パスワード値
* @return void
*/
public function setPasswordAttribute($value)
{
// passwordフィールドへの書き込みをope_passフィールドにリダイレクト
$this->attributes['ope_pass'] = $value;
}
/**
* 属性設定のオーバーライド
* Remember Tokenの設定を無効化旧システムでは使用していない
*
* @param string $key
* @param mixed $value
*/
public function setAttribute($key, $value)
{
$isRememberTokenAttribute = $key == $this->getRememberTokenName();
if (!$isRememberTokenAttribute) {
parent::setAttribute($key, $value);
}
}
/**
* オペレータ検索機能
* Laravel 5.7から継承したメソッド(検索・ソート・ページネーション)
*
* @param array $inputs
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Database\Eloquent\Collection
*/
public static function search($inputs)
{
$list = self::query();
// POST検索条件の処理
if ($inputs['isMethodPost']) {
}
// ソート処理
if ($inputs['sort']) {
$list->orderBy($inputs['sort'], $inputs['sort_type']);
}
// エクスポート用かページネーション用かの判定
if ($inputs['isExport']) {
$list = $list->get();
} else {
// ページネーション件数を20に固定
$list = $list->paginate(20);
}
return $list;
}
/**
* プライマリキーでオペレータを取得
*
* @param mixed $pk
* @return \App\Models\Ope|null
*/
public static function getByPk($pk)
{
return self::find($pk);
}
/**
* プライマリキーでオペレータを削除
*
* @param array $arr
* @return int
*/
public static function deleteByPk($arr)
{
return self::whereIn('ope_id', $arr)->delete();
}
/**
* オペレータのリストを取得(セレクトボックス用)
* Laravel 5.7から継承したメソッド
*
* @return \Illuminate\Support\Collection
*/
public static function getList()
{
return self::pluck('ope_name', 'ope_id');
}
}