58 lines
1.8 KiB
PHP
58 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Cloudflare;
|
|
|
|
use App\Entities\Cloudflare\AccountEntity;
|
|
use CodeIgniter\Model;
|
|
use stdClass;
|
|
|
|
class AccountModel extends Model
|
|
{
|
|
protected $table = 'cloudflareaccount';
|
|
protected $primaryKey = 'uid';
|
|
protected $useAutoIncrement = false;
|
|
protected $returnType = AccountEntity::class; //object,array,entity명::class
|
|
protected $allowedFields = ['uid', 'auth_uid', 'title', 'type', 'status', 'updated_at', 'created_at'];
|
|
protected $useTimestamps = true;
|
|
public function getTitleField(): string
|
|
{
|
|
return 'title';
|
|
}
|
|
public function getFieldRule(string $field, array $rules): array
|
|
{
|
|
switch ($field) {
|
|
case "auth_uid":
|
|
$rules[$field] = $rules[$field] = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]";;
|
|
break;
|
|
case "type":
|
|
$rules[$field] = "if_exist|trim|string";
|
|
break;
|
|
default:
|
|
$rules = parent::getFieldRule($field, $rules);
|
|
break;
|
|
}
|
|
return $rules;
|
|
}
|
|
public function getEntityByPK(int $uid): null | AccountEntity
|
|
{
|
|
$this->where($this->getPKField(), $uid);
|
|
return $this->getEntity();
|
|
}
|
|
public function getEntityByID(string $id): null | AccountEntity
|
|
{
|
|
$this->where($this->getTitleField(), $id);
|
|
return $this->getEntity();
|
|
}
|
|
|
|
//create용
|
|
public function create(array $formDatas = []): AccountEntity
|
|
{
|
|
return $this->create_process(new AccountEntity(), $formDatas);
|
|
}
|
|
//modify용
|
|
public function modify(AccountEntity $entity, array $formDatas): AccountEntity
|
|
{
|
|
return $this->modify_process($entity, $formDatas);
|
|
}
|
|
}
|