krgm.so-manager-dev.com/app/Models/Ope.php

177 lines
5.8 KiB
PHP
Raw Permalink 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',
'ope_name', // オペレータ名
'ope_type', // オペレータ種別
'ope_mail', // メールアドレス
'ope_phone', // 電話番号
'ope_sendalart_que1', // キュー1アラート送信
'ope_sendalart_que2', // キュー2アラート送信
'ope_sendalart_que3', // キュー3アラート送信
'ope_sendalart_que4', // キュー4アラート送信
'ope_sendalart_que5', // キュー5アラート送信
'ope_sendalart_que6', // キュー6アラート送信
'ope_sendalart_que7', // キュー7アラート送信
'ope_sendalart_que8', // キュー8アラート送信
'ope_sendalart_que9', // キュー9アラート送信
'ope_sendalart_que10', // キュー10アラート送信
'ope_sendalart_que11', // キュー11アラート送信
'ope_sendalart_que12', // キュー12アラート送信
'ope_sendalart_que13', // キュー13アラート送信
'ope_auth1', // 権限1
'ope_auth2', // 権限2
'ope_auth3', // 権限3
'ope_auth4', // 権限4
'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 {
$list = $list->paginate(Utils::item_per_page);
}
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');
}
}