cfmgrv4 init...1

This commit is contained in:
최준흠 2024-09-24 19:18:05 +09:00
parent 531d0d3384
commit a2f641edd0
18 changed files with 142 additions and 773 deletions

View File

@ -30,7 +30,7 @@ class AccountController extends CloudflareController
} }
protected function create_init(): void protected function create_init(): void
{ {
$this->fields = [$this->getMyLibrary()->getMyStorage()::TITLE, 'apikey', 'status']; $this->fields = [$this->getMyLibrary()->getMyStorage()::TITLE, 'authkey', 'status'];
$this->filter_fields = ['status']; $this->filter_fields = ['status'];
$this->action = DB_ACTION['CREATE']; $this->action = DB_ACTION['CREATE'];
$this->getMyLibrary()->getMyStorage()->setAction($this->action); $this->getMyLibrary()->getMyStorage()->setAction($this->action);
@ -56,8 +56,8 @@ class AccountController extends CloudflareController
protected function index_init(): void protected function index_init(): void
{ {
$this->fields = [$this->getMyLibrary()->getMyStorage()::TITLE, 'apikey', 'status']; $this->fields = [$this->getMyLibrary()->getMyStorage()::TITLE, 'authkey', 'oldkey', 'title', 'type', 'status', 'updated_at', 'created_at'];
$this->filter_fields = ['status']; $this->filter_fields = ['type', 'status'];
$this->action = DB_ACTION['CREATE']; $this->action = DB_ACTION['CREATE'];
$this->getMyLibrary()->getMyStorage()->setAction($this->action); $this->getMyLibrary()->getMyStorage()->setAction($this->action);
helper(['form']); helper(['form']);
@ -65,7 +65,7 @@ class AccountController extends CloudflareController
} }
public function index(): string public function index(): string
{ {
$this->create_init(); $this->index_init();
return parent::list_process(); return parent::list_process();
} }
} }

View File

@ -240,17 +240,22 @@ abstract class MVController extends CommonController
protected function list_pagination($pager_group = 'default', int $segment = 0, $template = 'bootstrap_full'): string protected function list_pagination($pager_group = 'default', int $segment = 0, $template = 'bootstrap_full'): string
{ {
//Page, Per_page필요부분 //Page, Per_page필요부분
$this->page = (int)$this->request->getVar('page') ?: 1; $this->page = (int)$this->request->getVar('page') ?? 1;
$this->per_page = (int)$this->request->getVar('per_page') ?: $this->_per_page; $this->per_page = (int)$this->request->getVar('per_page') ?? $this->_per_page;
//줄수 처리용 //줄수 처리용
$this->pageOptions = array("" => "줄수선택"); $page_options = array("" => "줄수선택");
for ($i = 10; $i <= $this->total_count + $this->per_page; $i += 10) { for ($i = 10; $i <= $this->total_count + $this->per_page; $i += 10) {
$this->pageOptions[$i] = $i; $page_options[$i] = $i;
} }
$this->page_options = form_dropdown(
'per_page',
$page_options,
$this->per_page
);
// 1.Views/Pagers/에 bootstrap_full.php,bootstrap_simple.php 생성 // 1.Views/Pagers/에 bootstrap_full.php,bootstrap_simple.php 생성
// 2.app/Config/Pager.php/$templates에 'bootstrap_full => 'Pagers\bootstrap_full', // 2.app/Config/Pager.php/$templates에 'bootstrap_full => 'Pagers\bootstrap_full',
// 'bootstrap_simple' => 'Pagers\bootstrap_simple', 추가 // 'bootstrap_simple' => 'Pagers\bootstrap_simple', 추가
$pager = \Config\Services::pager(); $pager = service("pager");
// $this->getMyLibrary()->getMyStorage()->paginate($this->per_page, $pager_group, $this->page, $segment); // $this->getMyLibrary()->getMyStorage()->paginate($this->per_page, $pager_group, $this->page, $segment);
$pager->makeLinks( $pager->makeLinks(
$this->page, $this->page,

24
app/Database/update.txt Normal file
View File

@ -0,0 +1,24 @@
1. 필드추가
alter table cloudflareaccount add column id varchar(30) not null after auth_uid;
alter table cloudflareaccount add column authkey varchar(255) not null after id;
alter table cloudflareaccount add column oldkey varchar(255) null after apikey;
2. 내용복사
update cloudflareaccount
join cloudflareauth on cloudflareaccount.auth_uid = cloudflareauth.uid
set cloudflareaccount.id=cloudflareauth.id,
cloudflareaccount.apikey=cloudflareauth.authkey,
cloudflareaccount.oldkey=cloudflareauth.oldkey
3. foreign key 삭제 , index key 삭제
show table cloudflareaccount;
ALTER TABLE cloudflareaccount DROP FOREIGN KEY cloudflareaccount_ibfk_1;
ALTER TABLE cloudflareaccount DROP KEY cloudflareaccount_ibfk_1;
4. auth_uid column 삭제
show table cloudflareaccount;
ALTER TABLE cloudflareaccount DROP column auth_uid;
5. id unique key 추가
ALTER TABLE cloudflareaccount ADD UNIQUE key cloudflareaccount_ibuk_1 (id);
ALTER TABLE cloudflareaccount ADD UNIQUE key cloudflareaccount_ibuk_2 (authkey);

View File

@ -9,7 +9,7 @@ class AccountEntity extends CommonEntity
{ {
public function __toString() public function __toString()
{ {
return "{$this->getPK()}|{$this->getTitle()}|{$this->getAPIKey()}|{$this->attributes['type']}|{$this->attributes['status']}"; return "{$this->getPK()}|{$this->getTitle()}|{$this->getAuthKey()}|{$this->attributes['type']}|{$this->attributes['status']}";
} }
public function getPK(): int public function getPK(): int
{ {
@ -24,8 +24,12 @@ class AccountEntity extends CommonEntity
$this->attributes[AccountModel::TITLE] = $title; $this->attributes[AccountModel::TITLE] = $title;
} }
//Common Function //Common Function
public function getAPIKey(): string public function getID(): string
{ {
return $this->attributes['apikey']; return $this->attributes['id'];
}
public function getAuthKey(): string
{
return $this->attributes['authkey'];
} }
} }

View File

@ -1,22 +1,22 @@
<?php <?php
return [ return [
'title' => "Account정보", 'title' => "Account정보",
'label' => [ 'label' => [
'uid' => "번호", 'uid' => "번호",
'id' => "인증ID", 'id' => "인증ID",
'apikey' => "인증Key", 'authkey' => "인증Key",
'oldkey' => "이전인증Key", 'oldkey' => "이전인증Key",
'type' => "가입방식", 'type' => "가입방식",
'status' => "상태", 'status' => "상태",
'updated_at' => "수정일", 'updated_at' => "수정일",
'created_at' => "작성일" 'created_at' => "작성일",
], ],
"TYPE" => [ "TYPE" => [
"standard" => "standard", "standard" => "standard",
"enterprise" => "enterprise" "enterprise" => "enterprise",
], ],
"STATUS" => [ "STATUS" => [
"use" => "사용", "use" => "사용",
"unuse" => "사용않함", "unuse" => "사용않함",
] ],
]; ];

View File

@ -1,38 +1,38 @@
<?php <?php
return [ return [
'title' => "Zone정보", 'title' => "Zone정보",
'label' => [ 'label' => [
'uid' => "번호", 'uid' => "번호",
'account_uid' => "계정", 'account_uid' => "계정",
'domain' => "도메인", 'domain' => "도메인",
'name_servers' => "네임서버", 'name_servers' => "네임서버",
'original_name_servers' => "이전네임서버", 'original_name_servers' => "이전네임서버",
'plan' => "plan", 'plan' => "plan",
'development_mode' => "개발모드", 'development_mode' => "개발모드",
'ipv6' => "ipv6", 'ipv6' => "ipv6",
'security_level' => "공격방어", 'security_level' => "공격방어",
'status' => "서비스", 'status' => "서비스",
'updated_at' => "수정일", 'updated_at' => "수정일",
'created_at' => "작성일" 'created_at' => "작성일",
], ],
"ACCOUNT_UID" => [ "ACCOUNT_UID" => [
], ],
"DEVELOPMENT_MODE" => [ "DEVELOPMENT_MODE" => [
"on" => "사용", "on" => "사용",
"off" => "사용않함", "off" => "사용않함",
], ],
"IPV6" => [ "IPV6" => [
"on" => "사용", "on" => "사용",
"off" => "사용않함", "off" => "사용않함",
], ],
"SECURITY_LEVEL" => [ "SECURITY_LEVEL" => [
"under_attack" => "under_attack", "under_attack" => "under_attack",
"medium" => "medium", "medium" => "medium",
"low" => "low", "low" => "low",
"essentially_off" => "essentially_off" "essentially_off" => "essentially_off",
], ],
"STATUS" => [ "STATUS" => [
"active" => "active", "active" => "active",
"pending" => "pending", "pending" => "pending",
], ],
]; ];

View File

@ -1,16 +1,16 @@
<?php <?php
return [ return [
'title' => "URL Mapping 정보", 'title' => "URL Mapping 정보",
'label' => [ 'label' => [
'uid' => "번호", 'uid' => "번호",
'oldurl' => "기존URL", 'oldurl' => "기존URL",
'newurl' => "신규URL", 'newurl' => "신규URL",
'status' => "상태", 'status' => "상태",
'updated_at' => "수정일", 'updated_at' => "수정일",
'created_at' => "작성일" 'created_at' => "작성일",
], ],
"STATUS" => [ "STATUS" => [
"use" => "사용", "use" => "사용",
"unuse" => "사용않함", "unuse" => "사용않함",
] ],
]; ];

View File

@ -1,27 +1,27 @@
<?php <?php
return [ return [
'title' => "계정정보", 'title' => "계정정보",
'label' => [ 'label' => [
'uid' => "번호", 'uid' => "번호",
'id' => "계정", 'id' => "계정",
'passwd' => "암호", 'passwd' => "암호",
'confirmpassword' => "암호확인", 'confirmpassword' => "암호확인",
'email' => "메일", 'email' => "메일",
'role' => "권한", 'role' => "권한",
'name' => "이름", 'name' => "이름",
'status' => "상태", 'status' => "상태",
'updated_at' => "수정일", 'updated_at' => "수정일",
'created_at' => "작성일" 'created_at' => "작성일",
], ],
"ROLE" => [ "ROLE" => [
"member" => "회원", "member" => "회원",
"manager" => "관리자", "manager" => "관리자",
"cloudflare" => "Cloudflare관리자", "cloudflare" => "Cloudflare관리자",
"director" => "감독자", "director" => "감독자",
"master" => "마스터" "master" => "마스터",
], ],
"STATUS" => [ "STATUS" => [
"use" => "사용", "use" => "사용",
"unuse" => "사용않함", "unuse" => "사용않함",
] ],
]; ];

View File

@ -35,7 +35,7 @@ class Account extends MyCloudflare
// "legacy_flags":{"enterprise_zone_quota":{"maximum":0,"current":0,"available":0}}, // "legacy_flags":{"enterprise_zone_quota":{"maximum":0,"current":0,"available":0}},
// "created_on":"2017-06-26T05:44:49.470184Z"} // "created_on":"2017-06-26T05:44:49.470184Z"}
// ] // ]
protected function getArrayByResult($result): array protected function getArrayByResult($result, array $formDatas = []): array
{ {
$formDatas[$this->getMyStorage()->getPKField()] = $result->id; $formDatas[$this->getMyStorage()->getPKField()] = $result->id;
$formDatas[$this->getMyStorage()->getTitleField()] = $result->name; $formDatas[$this->getMyStorage()->getTitleField()] = $result->name;
@ -48,7 +48,7 @@ class Account extends MyCloudflare
public function create(array $formDatas): AccountEntity public function create(array $formDatas): AccountEntity
{ {
//Socket용 //Socket용
$cf = $this->getMySocket()->request($formDatas['apikey']) $cf = $this->getMySocket()->request($formDatas['authkey'])
->post('accounts', [ ->post('accounts', [
'name' => $formDatas[$this->getMyStorage()->getTitleField()], 'name' => $formDatas[$this->getMyStorage()->getTitleField()],
'type' => $formDatas['type'], 'type' => $formDatas['type'],
@ -58,7 +58,7 @@ class Account extends MyCloudflare
throw new \Exception(__FUNCTION__ . "에서 실패:\n" . var_export($cf, true)); throw new \Exception(__FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
} }
//Storage용 //Storage용
$formDatas = $this->getArrayByResult($cf->result); $formDatas = $this->getArrayByResult($cf->result, $formDatas);
$entity = $this->getMyStorage()->create($formDatas); $entity = $this->getMyStorage()->create($formDatas);
log_message("notice", "Account::" . __FUNCTION__ . "=> 작업을 완료하였습니다."); log_message("notice", "Account::" . __FUNCTION__ . "=> 작업을 완료하였습니다.");
return $entity; return $entity;

View File

@ -13,7 +13,7 @@ abstract class MyCloudflare extends CommonLibrary
{ {
parent::__construct(); parent::__construct();
} }
abstract protected function getArrayByResult($result): array; abstract protected function getArrayByResult($result, array $formDatas = []): array;
abstract protected function reload_entity($cf): mixed; abstract protected function reload_entity($cf): mixed;
abstract public function getMyStorage(): mixed; abstract public function getMyStorage(): mixed;
final protected function getMySocket(): CloudflareSocket final protected function getMySocket(): CloudflareSocket

View File

@ -22,7 +22,7 @@ class Record extends MyCloudflare
} }
protected function getRequest(): Guzzle protected function getRequest(): Guzzle
{ {
return $this->getMySocket()->request($this->_account_entity->getAPIKey()); return $this->getMySocket()->request($this->_account_entity->getAuthKey());
} }
final public function getMyStorage(): RecordModel final public function getMyStorage(): RecordModel
{ {
@ -31,7 +31,7 @@ class Record extends MyCloudflare
} }
return $this->_myStorage; return $this->_myStorage;
} }
protected function getArrayByResult($result): array protected function getArrayByResult($result, array $formDatas = []): array
{ {
$formDatas[$this->getMyStorage()->getPKField()] = $result->id; $formDatas[$this->getMyStorage()->getPKField()] = $result->id;
$formDatas[$this->getMyStorage()::PARENT] = $result->zone_id; $formDatas[$this->getMyStorage()::PARENT] = $result->zone_id;

View File

@ -20,7 +20,7 @@ class Zone extends MyCloudflare
} }
private function getRequest(): Guzzle private function getRequest(): Guzzle
{ {
return $this->getMySocket()->request($this->_account_entity->getAPIKey()); return $this->getMySocket()->request($this->_account_entity->getAuthKey());
} }
final public function getMyStorage(): ZoneModel final public function getMyStorage(): ZoneModel
{ {
@ -29,7 +29,7 @@ class Zone extends MyCloudflare
} }
return $this->_myStorage; return $this->_myStorage;
} }
protected function getArrayByResult($result): array protected function getArrayByResult($result, array $formDatas = []): array
{ {
$formDatas[$this->getMyStorage()->getPKField()] = $result->id; $formDatas[$this->getMyStorage()->getPKField()] = $result->id;
$formDatas[$this->getMyStorage()::PARENT] = $result->account->id; $formDatas[$this->getMyStorage()::PARENT] = $result->account->id;

View File

@ -25,25 +25,25 @@ class CloudflareSocket extends CommonLibrary
$this->initAdapters(); $this->initAdapters();
self::$_request_max = getenv("cfmgr.request.max"); self::$_request_max = getenv("cfmgr.request.max");
} }
final protected function getAccountModel(): AccountModel private function getAccountModel(): AccountModel
{ {
if ($this->_accountModel === null) { if ($this->_accountModel === null) {
$this->_accountModel = new AccountModel(); $this->_accountModel = new AccountModel();
} }
return $this->_accountModel; return $this->_accountModel;
} }
final public function initAdapters(): void private function initAdapters(): void
{ {
foreach ($this->getAccountModel()->getEntitys() as $entity) { foreach ($this->getAccountModel()->getEntitys() as $entity) {
$this->_clients[$entity->getAPIKey()] = new Guzzle( $this->_clients[$entity->getAuthKey()] = new Guzzle(
new APIKey($entity->getTitle(), $entity->getAPIKey()) new APIKey($entity->getTitle(), $entity->getAuthKey())
); );
} }
} }
public function request(string $apikey): Guzzle final public function request(string $authkey): Guzzle
{ {
if (!array_key_exists($apikey, $this->_clients)) { if (!array_key_exists($authkey, $this->_clients)) {
throw new \Exception(+__FUNCTION__ . " => {$apikey}에 해당하는 Adapter를 찾을수 없습니다."); throw new \Exception(+__FUNCTION__ . " => {$authkey}에 해당하는 Adapter를 찾을수 없습니다.");
} }
if (self::$_request >= self::$_request_max) { if (self::$_request >= self::$_request_max) {
log_message('warning', sprintf("--Cloudflare API Call %s초 대기 시작--", self::$_request_timewait)); log_message('warning', sprintf("--Cloudflare API Call %s초 대기 시작--", self::$_request_timewait));
@ -52,18 +52,18 @@ class CloudflareSocket extends CommonLibrary
log_message('warning', sprintf("--Cloudflare API Call %s초 대기 종료--", self::$_request_timewait)); log_message('warning', sprintf("--Cloudflare API Call %s초 대기 종료--", self::$_request_timewait));
} }
self::$_request++; self::$_request++;
return $this->_clients[$apikey]; return $this->_clients[$authkey];
} }
// public function getAccount(string $apikey): Accounts // public function getAccount(string $authkey): Accounts
// { // {
// return new Accounts($this->request($apikey)); // return new Accounts($this->request($authkey));
// } // }
// public function getZone(string $apikey): Zones // public function getZone(string $authkey): Zones
// { // {
// return new Zones($this->request($apikey)); // return new Zones($this->request($authkey));
// } // }
// public function getRecord(string $apikey): DNS // public function getRecord(string $authkey): DNS
// { // {
// return new DNS($this->request($apikey)); // return new DNS($this->request($authkey));
// } // }
} }

View File

@ -9,12 +9,12 @@ class AccountModel extends CommonModel
{ {
const TABLE = "cloudflarerecord"; const TABLE = "cloudflarerecord";
const PK = "uid"; const PK = "uid";
const TITLE = "id"; const TITLE = "title";
protected $table = self::TABLE; protected $table = self::TABLE;
protected $primaryKey = self::PK; protected $primaryKey = self::PK;
protected $useAutoIncrement = false; protected $useAutoIncrement = false;
protected $returnType = AccountEntity::class; //object,array,entity명::class protected $returnType = AccountEntity::class; //object,array,entity명::class
protected $allowedFields = [self::PK, self::TITLE, 'apikey', 'oldkey', 'type', 'status', 'updated_at', 'created_at']; protected $allowedFields = [self::PK, self::TITLE, 'authkey', 'oldkey', 'title', 'type', 'status', 'updated_at', 'created_at'];
protected $useTimestamps = true; protected $useTimestamps = true;
public function __construct() public function __construct()
{ {
@ -29,13 +29,16 @@ class AccountModel extends CommonModel
switch ($field) { switch ($field) {
case self::TITLE: case self::TITLE:
$rules[$field] = "required|valid_emailvalid_email|is_unique[cloudflareauth.id]"; $rules[$field] = "required|valid_emailvalid_email|is_unique[cloudflareauth.id]";
case "apikey": break;
case 'id':
$rules[$field] = "required|valid_emailvalid_email|is_unique[cloudflareauth.id]";
break;
case "authkey":
$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}/]"; $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; break;
case "oldkey": case "oldkey":
$rules[$field] = $rules[$field] = "if_exist|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]"; $rules[$field] = $rules[$field] = "if_exist|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]";
;
break; break;
case "type": case "type":
$rules[$field] = "if_exist|in_list[standard,enterprise]"; $rules[$field] = "if_exist|in_list[standard,enterprise]";
@ -63,7 +66,7 @@ class AccountModel extends CommonModel
} }
public function getEntityByID(string $id): null|AccountEntity public function getEntityByID(string $id): null|AccountEntity
{ {
$this->where($this->getTitleField(), $id); $this->where('id', $id);
return $this->getEntity(); return $this->getEntity();
} }
//create용 //create용

View File

@ -1,158 +0,0 @@
<?php
namespace App\Models\Mangboard;
use App\Entities\Mangboard\BoardEntity;
use App\Models\CommonModel;
// +-----------------+---------------------+------+-----+---------------------+----------------+
// | Field | Type | Null | Key | Default | Extra |
// +-----------------+---------------------+------+-----+---------------------+----------------+
// | pid | int(10) unsigned | NO | PRI | NULL | auto_increment |
// | gid | int(10) unsigned | NO | MUL | 0 | |
// | reply | int(10) unsigned | NO | | 0 | |
// | depth | int(10) unsigned | NO | | 0 | |
// | user_id | varchar(150) | NO | MUL | | |
// | user_name | varchar(100) | NO | MUL | | |
// | title | varchar(255) | NO | MUL | | |
// | passwd | varchar(100) | NO | | | |
// | homepage | varchar(255) | NO | | | |
// | email | varchar(255) | NO | | | |
// | address | varchar(255) | NO | | | |
// | phone | varchar(50) | NO | | | |
// | reg_date | datetime | NO | MUL | 0000-00-00 00:00:00 | |
// | modify_date | datetime | NO | MUL | 0000-00-00 00:00:00 | |
// | calendar_date | datetime | NO | MUL | 0000-00-00 00:00:00 | |
// | hit | int(10) unsigned | NO | MUL | 0 | |
// | user_pid | int(10) unsigned | NO | MUL | 0 | |
// | parent_pid | int(10) unsigned | NO | MUL | 0 | |
// | parent_user_pid | int(10) unsigned | NO | MUL | 0 | |
// | level | tinyint(3) unsigned | NO | | 0 | |
// | file_count | int(10) unsigned | NO | | 0 | |
// | comment_count | int(10) unsigned | NO | | 0 | |
// | vote_good_count | int(10) unsigned | NO | | 0 | |
// | vote_bad_count | int(10) unsigned | NO | | 0 | |
// | vote_type | int(10) unsigned | NO | | 0 | |
// | ip | varchar(40) | NO | | | |
// | agent | varchar(30) | NO | | | |
// | is_notice | tinyint(3) unsigned | NO | MUL | 0 | |
// | is_secret | tinyint(3) unsigned | NO | | 0 | |
// | status | varchar(30) | NO | MUL | publish | |
// | is_show | tinyint(3) unsigned | NO | MUL | 1 | |
// | reply_email | tinyint(3) | NO | | 0 | |
// | text | mediumtext | NO | | NULL | |
// | content | mediumtext | NO | | NULL | |
// | content_type | varchar(20) | NO | | | |
// | data_type | varchar(20) | NO | | text | |
// | editor_type | varchar(10) | NO | | N | |
// | tag | varchar(255) | NO | | | |
// | category1 | varchar(100) | NO | MUL | | |
// | category2 | varchar(100) | NO | | | |
// | category3 | varchar(100) | NO | | | |
// | image_path | varchar(255) | NO | | | |
// | site_link1 | varchar(255) | NO | | | |
// | site_link2 | varchar(255) | NO | | | |
// | gps_latitude | decimal(10,8) | NO | MUL | 0.00000000 | |
// | gps_longitude | decimal(11,8) | NO | | 0.00000000 | |
// | ext1 | varchar(255) | NO | | | |
// | ext2 | varchar(255) | NO | | | |
// | ext3 | varchar(255) | NO | | | |
// | ext4 | varchar(255) | NO | | | |
// | ext5 | varchar(255) | NO | | | |
// | ext6 | varchar(255) | NO | | | |
// | ext7 | varchar(255) | NO | | | |
// | ext8 | varchar(255) | NO | | | |
// | ext9 | varchar(255) | NO | | | |
// | ext10 | varchar(255) | NO | | | |
// +-----------------+---------------------+------+-----+---------------------+----------------+
class BoardModel extends CommonModel
{
// const TABLE = "";
const PK = "pid";
const TITLE = "title";
// protected $table = self::TABLE;
protected $primaryKey = self::PK;
protected $returnType = BoardEntity::class;
protected $allowedFields = [
"gid",
self::TITLE,
"user_pid",
"user_id",
"user_name",
"level",
"data_type",
"editor_type",
"image_path",
"reg_date",
"hit",
"content"
];
public function __construct(string $table)
{
$this->table = $table;
parent::__construct();
}
public function getTable(): string
{
return $this->table;
}
public function getTitleField(): string
{
return self::TITLE;
}
public function getFieldRule(string $field, array $rules): array
{
switch ($field) {
case 'gid':
$rules[$field] = "if_exist|numeric";
break;
case "data_type":
$rules[$field] = "if_exist|trim|in_list[html,text]";
break;
case "editor_type":
$rules[$field] = "if_exist|trim|in_list[N,S]";
break;
case "reg_date":
$rules[$field] = "if_exist|valid_date";
break;
case "content":
case "image_path":
$rules[$field] = "if_exist|trim|string";
break;
case 'hit':
case 'level':
case 'user_pid':
$rules[$field] = "if_exist|numeric";
break;
default:
$rules = parent::getFieldRule($field, $rules);
break;
}
return $rules;
}
public function getEntityByPK(int $uid): null | BoardEntity
{
$this->where($this->getPKField(), $uid);
return $this->getEntity();
}
public function getEntityByID(string $id): null | BoardEntity
{
$this->where($this->getTitleField(), $id);
return $this->getEntity();
}
//create용
public function create(array $formDatas = []): BoardEntity
{
$entity = $this->create_process(new BoardEntity(), $formDatas);
//입력후 PID값을 GID값에 넣어주기 위함
return $this->modify($entity, ['gid' => intval($entity->getPK())]);
}
//modify용
public function modify(BoardEntity $entity, array $formDatas): BoardEntity
{
return $this->modify_process($entity, $formDatas);
}
}

View File

@ -1,146 +0,0 @@
<?php
namespace App\Models\Mangboard;
use App\Models\CommonModel;
use App\Entities\Mangboard\BoardsEntity;
// +-----------------------+----------------------+------+-----+---------------------+----------------+
// | Field | Type | Null | Key | Default | Extra |
// +-----------------------+----------------------+------+-----+---------------------+----------------+
// | pid | int(10) unsigned | NO | PRI | NULL | auto_increment |
// | board_name | varchar(50) | NO | MUL | | |
// | description | varchar(255) | NO | | | |
// | image_path | varchar(255) | NO | | | |
// | skin_name | varchar(100) | NO | MUL | | |
// | model_name | varchar(100) | NO | MUL | | |
// | table_link | varchar(100) | NO | MUL | | |
// | mobile_skin_name | varchar(100) | NO | MUL | | |
// | post_id | bigint(20) | NO | | 0 | |
// | board_header | text | NO | | NULL | |
// | board_footer | text | NO | | NULL | |
// | board_content_form | text | NO | | NULL | |
// | editor_type | varchar(50) | NO | | N | |
// | api_type | varchar(50) | NO | | mb | |
// | page_size | smallint(5) unsigned | NO | | 20 | |
// | comment_size | smallint(5) unsigned | NO | | 50 | |
// | block_size | tinyint(3) unsigned | NO | | 10 | |
// | category_type | varchar(50) | NO | | NONE | |
// | category_data | text | NO | | NULL | |
// | use_board_vote_good | tinyint(3) unsigned | NO | | 0 | |
// | use_board_vote_bad | tinyint(3) unsigned | NO | | 0 | |
// | use_comment | tinyint(3) unsigned | NO | | 0 | |
// | use_comment_vote_good | tinyint(3) unsigned | NO | | 0 | |
// | use_comment_vote_bad | tinyint(3) unsigned | NO | | 0 | |
// | use_secret | tinyint(3) unsigned | NO | | 0 | |
// | use_notice | tinyint(3) unsigned | NO | | 0 | |
// | use_list_title | tinyint(3) unsigned | NO | | 1 | |
// | use_list_search | tinyint(3) unsigned | NO | | 1 | |
// | list_level | tinyint(3) unsigned | NO | | 0 | |
// | view_level | tinyint(3) unsigned | NO | | 0 | |
// | write_level | tinyint(3) unsigned | NO | | 0 | |
// | reply_level | tinyint(3) unsigned | NO | | 0 | |
// | delete_level | tinyint(3) unsigned | NO | | 8 | |
// | modify_level | tinyint(3) unsigned | NO | | 8 | |
// | secret_level | tinyint(3) unsigned | NO | | 8 | |
// | manage_level | tinyint(3) unsigned | NO | | 8 | |
// | comment_level | tinyint(3) unsigned | NO | | 0 | |
// | point_board_read | int(10) | NO | | 0 | |
// | point_board_write | int(10) | NO | | 0 | |
// | point_board_reply | int(10) | NO | | 0 | |
// | point_comment_write | int(10) | NO | | 0 | |
// | board_type | varchar(50) | NO | MUL | board | |
// | reg_date | datetime | NO | MUL | 0000-00-00 00:00:00 | |
// | is_show | tinyint(3) unsigned | NO | MUL | 1 | |
// | ext1 | varchar(255) | NO | | | |
// | ext2 | varchar(255) | NO | | | |
// | ext3 | varchar(255) | NO | | | |
// | ext4 | varchar(255) | NO | | | |
// | ext5 | varchar(255) | NO | | | |
// +-----------------------+----------------------+------+-----+---------------------+----------------+
class BoardsModel extends CommonModel
{
const TABLE = "mb_boards";
const PK = "pid";
const TITLE = "board_name";
protected $table = self::TABLE;
protected $primaryKey = self::PK;
protected $returnType = BoardsEntity::class;
protected $allowedFields = [
self::TITLE,
"board_type",
"description",
"list_level",
"write_level",
"modify_level",
"view_level",
"reply_level",
"delete_level",
"secret_level",
"manage_level",
"comment_level",
"is_show",
"reg_date",
];
public function __construct()
{
parent::__construct();
}
public function getTitleField(): string
{
return self::TITLE;
}
public function getFieldRule(string $field, array $rules): array
{
switch ($field) {
case "board_type":
$rules[$field] = "if_exist|trim|in_list[board,admin,user]";
break;
case "description":
$rules[$field] = "if_exist|trim|string";
break;
case "list_level":
case "write_level":
case "modify_level":
case "view_level":
case "reply_level":
case "delete_level":
case "secret_level":
case "manage_level":
case "comment_level":
case 'is_show':
$rules[$field] = "if_exist|numeric";
break;
case "reg_date":
$rules[$field] = "if_exist|valid_date";
break;
default:
$rules = parent::getFieldRule($field, $rules);
break;
}
return $rules;
}
public function getEntityByPK(int $uid): null | BoardsEntity
{
$this->where($this->getPKField(), $uid);
return $this->getEntity();
}
public function getEntityByID(string $id): null | BoardsEntity
{
$this->where($this->getTitleField(), $id);
return $this->getEntity();
}
//create용
public function create(array $formDatas = []): BoardsEntity
{
return $this->create_process(new BoardsEntity(), $formDatas);
}
//modify용
public function modify(BoardsEntity $entity, array $formDatas): BoardsEntity
{
return $this->modify_process($entity, $formDatas);
}
}

View File

@ -1,127 +0,0 @@
<?php
namespace App\Models\Mangboard;
use App\Entities\Mangboard\FileEntity;
use App\Models\CommonModel;
// +------------------+----------------------+------+-----+---------------------+----------------+
// | Field | Type | Null | Key | Default | Extra |
// +------------------+----------------------+------+-----+---------------------+----------------+
// | pid | int(10) unsigned | NO | PRI | NULL | auto_increment |
// | user_pid | int(10) unsigned | NO | | 0 | |
// | user_name | varchar(100) | NO | MUL | | |
// | board_name | varchar(50) | NO | MUL | | |
// | table_name | varchar(100) | NO | MUL | | |
// | board_pid | int(10) unsigned | NO | MUL | 0 | |
// | file_name | varchar(255) | NO | MUL | | |
// | file_path | varchar(255) | NO | MUL | | |
// | file_type | varchar(255) | NO | MUL | | |
// | file_caption | varchar(255) | NO | | | |
// | file_alt | varchar(255) | NO | | | |
// | file_description | text | NO | | NULL | |
// | file_size | int(10) unsigned | NO | MUL | 0 | |
// | link_count | int(10) unsigned | NO | | 0 | |
// | download_count | int(10) unsigned | NO | | 0 | |
// | file_sequence | smallint(5) unsigned | NO | MUL | 1 | |
// | is_download | tinyint(3) unsigned | NO | | 0 | |
// | reg_date | datetime | NO | MUL | 0000-00-00 00:00:00 | |
// | ip | varchar(40) | NO | | | |
// | agent | varchar(30) | NO | | | |
// +------------------+----------------------+------+-----+---------------------+----------------+
class FileModel extends CommonModel
{
const TABLE = "mb_files";
const PK = "pid";
const TITLE = "file_name";
protected $table = self::TABLE;
protected $primaryKey = self::PK;
protected $returnType = FileEntity::class;
protected $allowedFields = [
"user_pid",
"user_name",
"board_pid",
"board_name",
"table_name",
self::TITLE,
"file_path",
"file_type",
"file_caption",
"file_alt",
"file_description",
"file_size",
"file_sequence",
"reg_date"
];
public function __construct()
{
parent::__construct();
}
public function getTitleField(): string
{
return self::TITLE;
}
public function getFieldRule(string $field, array $rules): array
{
switch ($field) {
case "board_pid":
case "user_pid":
case "file_sequence":
case "file_size":
$rules[$field] = "if_exist|numeric";
break;
case "board_name":
case "table_name":
case "file_name":
case "file_path":
case "file_type":
$rules[$field] = "required|string";
break;
case "file_description":
case "file_caption":
case "file_alt":
$rules[$field] = "if_exist|string";
break;
case "reg_date":
$rules[$field] = "if_exist|valid_date";
break;
default:
$rules = parent::getFieldRule($field, $rules);
break;
}
return $rules;
}
public function getEntityByPK(int $uid): null | FileEntity
{
$this->where($this->getPKField(), $uid);
return $this->getEntity();
}
public function getEntityByID(string $id): null | FileEntity
{
$this->where($this->getTitleField(), $id);
return $this->getEntity();
}
// protected function convertEntityData(string $field, array $formDatas): string|int
// {
// switch ($field) {
// default:
// $value = parent::convertEntityData($field, $formDatas);
// break;
// }
// return $value;
// }
//create용
public function create(array $formDatas = []): FileEntity
{
return $this->create_process(new FileEntity(), $formDatas);
}
//modify용
public function modify(FileEntity $entity, array $formDatas): FileEntity
{
return $this->modify_process($entity, $formDatas);
}
}

View File

@ -1,236 +0,0 @@
<?php
namespace App\Models\Mangboard;
use App\Entities\Mangboard\UserEntity;
use App\Models\CommonModel;
// +-------------------+----------------------+------+-----+---------------------+----------------+
// | Field | Type | Null | Key | Default | Extra |
// +-------------------+----------------------+------+-----+---------------------+----------------+
// | pid | int(10) unsigned | NO | PRI | NULL | auto_increment |
// | wp_user_pid | int(10) unsigned | NO | | 0 | |
// | user_id | varchar(150) | NO | UNI | | |
// | passwd | varchar(255) | NO | | | |
// | user_name | varchar(100) | NO | | | |
// | user_state | varchar(255) | NO | | | |
// | user_level | tinyint(3) unsigned | NO | | 1 | |
// | user_group | varchar(255) | NO | MUL | home | |
// | user_platform | varchar(100) | NO | | mb | |
// | user_email | varchar(255) | NO | | | |
// | user_point | int(10) unsigned | NO | | 0 | |
// | user_money | int(10) unsigned | NO | | 0 | |
// | user_coin | int(10) unsigned | NO | | 0 | |
// | payment_count | smallint(5) unsigned | NO | | 0 | |
// | payment_total | int(10) unsigned | NO | | 0 | |
// | user_birthday | varchar(50) | NO | | | |
// | user_phone | varchar(50) | NO | | | |
// | user_picture | varchar(255) | NO | | | |
// | user_icon | varchar(255) | NO | | | |
// | user_messenger | varchar(255) | NO | | | |
// | user_homepage | varchar(255) | NO | | | |
// | user_blog | varchar(255) | NO | | | |
// | user_sex | tinyint(3) | NO | | 0 | |
// | home_postcode | varchar(20) | NO | | | |
// | home_address1 | varchar(255) | NO | | | |
// | home_address2 | varchar(255) | NO | | | |
// | home_tel | varchar(50) | NO | | | |
// | office_postcode | varchar(20) | NO | | | |
// | office_address1 | varchar(255) | NO | | | |
// | office_address2 | varchar(255) | NO | | | |
// | office_tel | varchar(50) | NO | | | |
// | office_fax | varchar(50) | NO | | | |
// | company_name | varchar(255) | NO | | | |
// | job_title | varchar(255) | NO | | | |
// | gps_latitude | decimal(10,8) | NO | | 0.00000000 | |
// | gps_longitude | decimal(11,8) | NO | | 0.00000000 | |
// | allow_mailing | tinyint(3) unsigned | NO | MUL | 1 | |
// | allow_message | tinyint(3) unsigned | NO | | 1 | |
// | allow_push | tinyint(3) unsigned | NO | | 1 | |
// | allow_sms | tinyint(3) unsigned | NO | | 1 | |
// | followers | int(10) unsigned | NO | | 0 | |
// | following | int(10) unsigned | NO | | 0 | |
// | new_memo | smallint(5) unsigned | NO | | 0 | |
// | login_count | int(10) unsigned | NO | | 0 | |
// | write_count | int(10) unsigned | NO | | 0 | |
// | reply_count | int(10) unsigned | NO | | 0 | |
// | comment_count | int(10) unsigned | NO | | 0 | |
// | send_count | int(10) unsigned | NO | | 0 | |
// | api_count | int(10) unsigned | NO | | 0 | |
// | item1_count | int(10) unsigned | NO | | 0 | |
// | item2_count | int(10) unsigned | NO | | 0 | |
// | item3_count | int(10) unsigned | NO | | 0 | |
// | review_count | int(10) unsigned | NO | | 0 | |
// | review_star_sum | int(10) unsigned | NO | | 0 | |
// | reg_mail | tinyint(3) | NO | | 0 | |
// | reg_phone | tinyint(3) | NO | | 0 | |
// | push_pid | int(10) unsigned | NO | | 0 | |
// | reg_date | datetime | NO | MUL | 0000-00-00 00:00:00 | |
// | last_login | datetime | NO | MUL | 0000-00-00 00:00:00 | |
// | user_memo | varchar(255) | NO | | | |
// | admin_memo | varchar(255) | NO | | | |
// | recommender_id | varchar(255) | NO | | | |
// | user_auth_key | varchar(255) | NO | | | |
// | user_access_token | varchar(255) | NO | | | |
// | ext1 | varchar(255) | NO | | | |
// | ext2 | varchar(255) | NO | | | |
// | ext3 | varchar(255) | NO | | | |
// | ext4 | varchar(255) | NO | | | |
// | ext5 | varchar(255) | NO | | | |
// | ext6 | varchar(255) | NO | | | |
// | ext7 | varchar(255) | NO | | | |
// | ext8 | varchar(255) | NO | | | |
// | ext9 | varchar(255) | NO | | | |
// | ext10 | varchar(255) | NO | | | |
// | ext11 | varchar(255) | NO | | | |
// | ext12 | varchar(255) | NO | | | |
// | ext13 | varchar(255) | NO | | | |
// | ext14 | varchar(255) | NO | | | |
// | ext15 | varchar(255) | NO | | | |
// | ext16 | varchar(255) | NO | | | |
// | ext17 | varchar(255) | NO | | | |
// | ext18 | varchar(255) | NO | | | |
// | ext19 | varchar(255) | NO | | | |
// | ext20 | varchar(255) | NO | | | |
// +-------------------+----------------------+------+-----+---------------------+----------------+
class UserModel extends CommonModel
{
const TABLE = "mb_users";
const PK = "pid";
const TITLE = "user_name";
protected $table = self::TABLE;
protected $primaryKey = self::PK;
protected $returnType = UserEntity::class;
protected $allowedFields = [
"user_id",
"passwd",
self::TITLE,
"user_email",
"user_state",
"user_level",
"user_point"
];
public function __construct()
{
parent::__construct();
}
public function getTitleField(): string
{
return self::TITLE;
}
public function getFieldRule(string $field, array $rules): array
{
switch ($field) {
case "user_id":
case "passwd":
$rules[$field] = "required|trim|string";
break;
case "user_state":
$rules[$field] = "if_exist|trim|string";
break;
case "user_email":
$rules[$field] = "if_exist|trim|valid_email";
break;
case "user_level":
case "user_point":
$rules[$field] = "if_exist|numeric";
break;
default:
$rules = parent::getFieldRule($field, $rules);
break;
}
return $rules;
}
public function getEntityByPK(int $uid): null|UserEntity
{
$this->where($this->getPKField(), $uid);
return $this->getEntity();
}
public function getEntityByID(string $id): null|UserEntity
{
$this->where('user_id', $id);
return $this->getEntity();
}
//create용
public function create(array $formDatas = []): UserEntity
{
return $this->create_process(new UserEntity(), $formDatas);
}
//modify용
public function modify(UserEntity $entity, array $formDatas): UserEntity
{
return $this->modify_process($entity, $formDatas);
}
public function getEntityByLoginCheck(string $id, string $password): null|UserEntity
{
$this->where('user_id', $id);
$this->where('passwd', password_hash($password, PASSWORD_DEFAULT));
return $this->getEntity();
}
private function getLevelByPoint(UserEntity $entity): int
{
//Admin용 Level로는 변경불가
if ($entity->getLevel() == getenv('mangboard.admin.level')) {
log_message("notice", "Admin용 Level을 변경하실수 없습니다.");
return $entity->getLevel();
}
//사용자 Point별 Level 계산
$levelup_point = getenv('mangboard.level.up.point.unit');
$level = intval($entity->getPoint() / $levelup_point * $levelup_point / $levelup_point);
//운영자면 7~9
if (getenv('mangboard.level.manager.min') <= $level && $level <= getenv('mangboard.level.manager.max')) {
$level = $level < getenv('mangboard.level.manager.min') ? getenv('mangboard.level.manager.min') : $level;
$level = getenv('mangboard.level.manager.max') < $level ? getenv('mangboard.level.manager.max') : $level;
}
// echo "point:" . $entity->getPoint() . ",level:" . $level . "\n";
//사용자 Level 1~5;
if (getenv('mangboard.level.user.min') <= $level && $level <= getenv('mangboard.level.user.max')) {
$level = $level < getenv('mangboard.level.user.min') ? getenv('mangboard.level.user.min') : $level;
$level = getenv('mangboard.level.user.max') < $level ? getenv('mangboard.level.user.max') : $level;
}
// echo "point:" . $entity->getPoint() . ",level:" . $level . "\n";
return $level;
}
public function setPoint(UserEntity $entity, int $point, $sign = '+'): UserEntity
{
switch ($sign) {
case '-':
if ($point < $point) {
throw new \Exception("기존포인트:{$point}가 감소 포인트:-{$point} 작습니다.\n");
}
$point = $point - $point;
break;
case '+':
$point = $point + $point;
break;
default:
throw new \Exception(__FUNCTION__ . "에서는 {$sign}은 사용할수 없습니다.\n");
// break;
}
//기존정보와 Point값이 다르면 저장
if ($entity->getPoint() != $point) {
$formDatas = ["point" => $point];
$entity = $this->modify($entity, $formDatas);
log_message("notice", __FUNCTION__ . "=>{$entity->getTitle()}님의 Point가 {$entity->getPoint()}에서 {$point}로 변경되었습니다.");
}
return $this->setLevel($entity, $this->getLevelByPoint($entity));
}
public function setLevel(UserEntity $entity, int $level): UserEntity
{
//기존정보와 Level값이 다르면 저장
if ($entity->getLevel() != $level) {
$formDatas = ["level" => $level];
$entity = $this->modify($entity, $formDatas);
log_message("notice", __FUNCTION__ . "=>{$entity->getTitle()}님의 Level이 {$entity->getLevel()}에서 {$level}로 변경되었습니다.");
}
return $entity;
}
}