dbms/app/Models/Device/NetworkModel.php
2025-05-07 15:57:41 +09:00

63 lines
1.6 KiB
PHP

<?php
namespace App\Models\Device;
use App\Entities\Device\NetworkEntity;
class NetworkModel extends DeviceModel
{
const TABLE = "networkinfo";
const PK = "uid";
const TITLE = "title";
protected $table = self::TABLE;
protected $primaryKey = self::PK;
protected $returnType = NetworkEntity::class;
protected $allowedFields = [
"clientinfo_uid",
"status",
"title",
"amount",
];
public function __construct()
{
parent::__construct();
}
public function getFilterFields(): array
{
return ["clientinfo_uid", 'status'];
}
public function getBatchJobFields(): array
{
return ['status'];
}
public function getFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
}
switch ($field) {
case "clientinfo_uid":
case "amount":
$rule = "required|number";
break;
case "title":
$rule = "required|trim|string";
break;
case "status":
$rule = "required|in_list[in,out]";
break;
default:
$rule = parent::getFieldRule($action, $field);
break;
}
return $rule;
}
//List 검색용
public function setList_WordFilter(string $word): void
{
$this->orLike(self::TABLE . "." . self::TITLE, $word, 'both');
$this->orLike(self::TABLE . '.alias', $word, 'both');
}
}