97 lines
3.1 KiB
PHP
97 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Cloudflare;
|
|
|
|
use App\Entities\Cloudflare\ZoneEntity;
|
|
use App\Entities\Cloudflare\AuditLogEntity;
|
|
use App\Models\CommonModel;
|
|
|
|
class AuditLogModel extends CommonModel
|
|
{
|
|
const TABLE = "cloudflareauditlog";
|
|
const PK = "uid";
|
|
const TITLE = "action";
|
|
protected $table = self::TABLE;
|
|
protected $primaryKey = self::PK;
|
|
protected $useAutoIncrement = false;
|
|
protected $returnType = AuditLogEntity::class; //object,array,entity명::class
|
|
protected $allowedFields = [self::PK, self::TITLE, 'action_info', 'actor', 'interface', 'zone_id', 'zone_name', 'resource_id', 'resource_name', 'resource_type', 'status', 'updated_at', 'created_at'];
|
|
protected $useTimestamps = true;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
public function getTitleField(): string
|
|
{
|
|
return self::TITLE;
|
|
}
|
|
public function getFieldRule(string $action, string $field): string
|
|
{
|
|
switch ($field) {
|
|
case self::PK:
|
|
$rule = "required|trim|string";
|
|
$rule .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : "";
|
|
break;
|
|
case self::TITLE:
|
|
case 'actor':
|
|
case 'zone_id':
|
|
case 'resource_id':
|
|
$rule = "required|trim|string";
|
|
break;
|
|
case 'interface':
|
|
case 'action_info':
|
|
case 'zone_name':
|
|
case 'resource_name':
|
|
case 'resource_type':
|
|
$rule = "if_exist|trim|string";
|
|
break;
|
|
case "status":
|
|
$rule = "if_exist|in_list[true,false]";
|
|
break;
|
|
default:
|
|
$rule = parent::getFieldRule($action, $field);
|
|
break;
|
|
}
|
|
return $rule;
|
|
}
|
|
public function getFormFieldInputOption(string $field, array $options = []): array
|
|
{
|
|
switch ($field) {
|
|
default:
|
|
$this->orderBy('zone_name', 'asc');
|
|
$options = parent::getFormFieldInputOption($field, $options);
|
|
break;
|
|
}
|
|
return $options;
|
|
}
|
|
public function getEntityByPK(string $uid): null|AuditLogEntity
|
|
{
|
|
$this->where(self::PK, $uid);
|
|
return $this->getEntity();
|
|
}
|
|
public function getEntityByID(string $id): null|AuditLogEntity
|
|
{
|
|
$this->where(self::TITLE, $id);
|
|
return $this->getEntity();
|
|
}
|
|
//create용
|
|
public function create(array $formDatas = []): AuditLogEntity
|
|
{
|
|
return $this->create_process(new AuditLogEntity(), $formDatas);
|
|
}
|
|
//modify용
|
|
public function modify(AuditLogEntity $entity, array $formDatas): AuditLogEntity
|
|
{
|
|
return $this->modify_process($entity, $formDatas);
|
|
}
|
|
//List 검색용
|
|
public function setList_WordFilter(string $word, $field = null): void
|
|
{
|
|
parent::setList_WordFilter($word, $field);
|
|
$this->orLike(self::TABLE . '.zone_name', $word, 'both');
|
|
$this->orLike(self::TABLE . '.resource_name', $word, 'both');
|
|
}
|
|
}
|
|
}
|