98 lines
3.4 KiB
PHP
98 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Cloudflare\Magictransit;
|
|
|
|
use App\Entities\Cloudflare\Magictransit\AllowListEntity;
|
|
use CodeIgniter\Model;
|
|
|
|
class AllowListModel extends Model
|
|
{
|
|
protected $DBGroup = 'default';
|
|
protected $table = 'cloudflareallowlist';
|
|
protected $primaryKey = 'uid';
|
|
protected $useAutoIncrement = false;
|
|
protected $insertID = 0;
|
|
protected $returnType = 'array'; //object,array,entity명::class
|
|
protected $useSoftDeletes = false;
|
|
protected $protectFields = true;
|
|
protected $allowedFields = ['uid', 'account_uid', 'uid', 'domain', 'name_servers', 'original_name_servers', 'plan', 'development_mode', 'ipv6', 'security_level', 'status', 'updated_at', 'crated_at'];
|
|
|
|
// Dates
|
|
protected $useTimestamps = true;
|
|
protected $dateFormat = 'datetime';
|
|
protected $createdField = 'created_at';
|
|
protected $updatedField = 'updated_at';
|
|
protected $deletedField = 'deleted_at';
|
|
|
|
// Validation
|
|
protected $validationRules = [
|
|
'uid' => 'if_exist|min_length[10]|max_length[200]',
|
|
'account_uid' => 'if_exist|min_length[10]|max_length[200]',
|
|
'domain' => 'if_exist|string',
|
|
'name_servers' => 'if_exist|string',
|
|
'plan' => 'if_exist|string',
|
|
'development_mode' => 'if_exist|in_list[on,off]',
|
|
'ipv6' => 'if_exist|in_list[on,off]',
|
|
'security_level' => 'if_exist|string',
|
|
'status' => 'if_exist|string',
|
|
'updated_at' => 'if_exist|valid_date',
|
|
'created_at' => 'if_exist|valid_date',
|
|
];
|
|
// 'security_level' => 'if_exist|in_list[essentially_off,low,medium,under_attack]',
|
|
// 'status' => 'if_exist|in_list[active,pending]',
|
|
protected $validationMessages = [];
|
|
protected $skipValidation = false;
|
|
protected $cleanValidationRules = true;
|
|
|
|
// Callbacks
|
|
protected $allowCallbacks = true;
|
|
protected $beforeInsert = [];
|
|
protected $afterInsert = [];
|
|
protected $beforeUpdate = [];
|
|
protected $afterUpdate = [];
|
|
protected $beforeFind = [];
|
|
protected $afterFind = [];
|
|
protected $beforeDelete = [];
|
|
protected $afterDelete = [];
|
|
|
|
public function getTableName()
|
|
{
|
|
return $this->table;
|
|
}
|
|
|
|
public function getEntity(string $uid): null|AllowListEntity
|
|
{
|
|
$entity = $this->asObject(AllowListEntity::class)->first($uid);
|
|
if (is_null($entity)) {
|
|
throw new \Exception("해당 정보가 없습니다.");
|
|
}
|
|
return $entity;
|
|
}
|
|
|
|
public function getFilterFields(string $type = '', array $fields = array())
|
|
{
|
|
$filterFields = ['account_uid', 'development_mode', 'ipv6', 'security_level', 'status'];
|
|
switch ($type) {
|
|
case 'only':
|
|
return array_diff_assoc($filterFields, $fields);
|
|
break;
|
|
case 'except':
|
|
return array_diff_uassoc($filterFields, $fields);
|
|
break;
|
|
default:
|
|
return $filterFields;
|
|
break;
|
|
}
|
|
}
|
|
|
|
public function setIndexWordFilter(string $word)
|
|
{
|
|
$this->like('domain', $word, 'both'); //befor , after , both
|
|
}
|
|
public function setIndexDateFilter($start, $end)
|
|
{
|
|
$this->where('created_at >=', $start);
|
|
$this->where('created_at <=', $end);
|
|
}
|
|
}
|