From a2f641edd096fe832b2c884f87b2add7dec8e90e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Tue, 24 Sep 2024 19:18:05 +0900 Subject: [PATCH] cfmgrv4 init...1 --- .../Cloudflare/AccountController.php | 8 +- app/Controllers/MVController.php | 15 +- app/Database/update.txt | 24 ++ app/Entities/Cloudflare/AccountEntity.php | 10 +- app/Language/en/Cloudflare/Account.php | 28 +-- app/Language/en/Cloudflare/Zone.php | 52 ++-- app/Language/en/Mapurl.php | 18 +- app/Language/en/User.php | 36 +-- app/Libraries/MyCloudflare/Account.php | 6 +- app/Libraries/MyCloudflare/MyCloudflare.php | 2 +- app/Libraries/MyCloudflare/Record.php | 4 +- app/Libraries/MyCloudflare/Zone.php | 4 +- app/Libraries/MySocket/CloudflareSocket.php | 28 +-- app/Models/Cloudflare/AccountModel.php | 13 +- app/Models/Mangboard/BoardModel.php | 158 ------------ app/Models/Mangboard/BoardsModel.php | 146 ----------- app/Models/Mangboard/FileModel.php | 127 ---------- app/Models/Mangboard/UserModel.php | 236 ------------------ 18 files changed, 142 insertions(+), 773 deletions(-) create mode 100644 app/Database/update.txt delete mode 100644 app/Models/Mangboard/BoardModel.php delete mode 100644 app/Models/Mangboard/BoardsModel.php delete mode 100644 app/Models/Mangboard/FileModel.php delete mode 100644 app/Models/Mangboard/UserModel.php diff --git a/app/Controllers/Cloudflare/AccountController.php b/app/Controllers/Cloudflare/AccountController.php index 3bece86..49c5f76 100644 --- a/app/Controllers/Cloudflare/AccountController.php +++ b/app/Controllers/Cloudflare/AccountController.php @@ -30,7 +30,7 @@ class AccountController extends CloudflareController } 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->action = DB_ACTION['CREATE']; $this->getMyLibrary()->getMyStorage()->setAction($this->action); @@ -56,8 +56,8 @@ class AccountController extends CloudflareController protected function index_init(): void { - $this->fields = [$this->getMyLibrary()->getMyStorage()::TITLE, 'apikey', 'status']; - $this->filter_fields = ['status']; + $this->fields = [$this->getMyLibrary()->getMyStorage()::TITLE, 'authkey', 'oldkey', 'title', 'type', 'status', 'updated_at', 'created_at']; + $this->filter_fields = ['type', 'status']; $this->action = DB_ACTION['CREATE']; $this->getMyLibrary()->getMyStorage()->setAction($this->action); helper(['form']); @@ -65,7 +65,7 @@ class AccountController extends CloudflareController } public function index(): string { - $this->create_init(); + $this->index_init(); return parent::list_process(); } } diff --git a/app/Controllers/MVController.php b/app/Controllers/MVController.php index 1e63fbd..d3e4174 100644 --- a/app/Controllers/MVController.php +++ b/app/Controllers/MVController.php @@ -240,17 +240,22 @@ abstract class MVController extends CommonController protected function list_pagination($pager_group = 'default', int $segment = 0, $template = 'bootstrap_full'): string { //Page, Per_page필요부분 - $this->page = (int)$this->request->getVar('page') ?: 1; - $this->per_page = (int)$this->request->getVar('per_page') ?: $this->_per_page; + $this->page = (int)$this->request->getVar('page') ?? 1; + $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) { - $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 생성 // 2.app/Config/Pager.php/$templates에 'bootstrap_full => 'Pagers\bootstrap_full', // 'bootstrap_simple' => 'Pagers\bootstrap_simple', 추가 - $pager = \Config\Services::pager(); + $pager = service("pager"); // $this->getMyLibrary()->getMyStorage()->paginate($this->per_page, $pager_group, $this->page, $segment); $pager->makeLinks( $this->page, diff --git a/app/Database/update.txt b/app/Database/update.txt new file mode 100644 index 0000000..c5d3098 --- /dev/null +++ b/app/Database/update.txt @@ -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); \ No newline at end of file diff --git a/app/Entities/Cloudflare/AccountEntity.php b/app/Entities/Cloudflare/AccountEntity.php index 5092cb1..3281565 100644 --- a/app/Entities/Cloudflare/AccountEntity.php +++ b/app/Entities/Cloudflare/AccountEntity.php @@ -9,7 +9,7 @@ class AccountEntity extends CommonEntity { 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 { @@ -24,8 +24,12 @@ class AccountEntity extends CommonEntity $this->attributes[AccountModel::TITLE] = $title; } //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']; } } diff --git a/app/Language/en/Cloudflare/Account.php b/app/Language/en/Cloudflare/Account.php index 0253a2d..176d379 100644 --- a/app/Language/en/Cloudflare/Account.php +++ b/app/Language/en/Cloudflare/Account.php @@ -1,22 +1,22 @@ "Account정보", - 'label' => [ - 'uid' => "번호", - 'id' => "인증ID", - 'apikey' => "인증Key", - 'oldkey' => "이전인증Key", - 'type' => "가입방식", - 'status' => "상태", + 'title' => "Account정보", + 'label' => [ + 'uid' => "번호", + 'id' => "인증ID", + 'authkey' => "인증Key", + 'oldkey' => "이전인증Key", + 'type' => "가입방식", + 'status' => "상태", 'updated_at' => "수정일", - 'created_at' => "작성일" + 'created_at' => "작성일", ], - "TYPE" => [ - "standard" => "standard", - "enterprise" => "enterprise" + "TYPE" => [ + "standard" => "standard", + "enterprise" => "enterprise", ], "STATUS" => [ - "use" => "사용", + "use" => "사용", "unuse" => "사용않함", - ] + ], ]; diff --git a/app/Language/en/Cloudflare/Zone.php b/app/Language/en/Cloudflare/Zone.php index 2a077b5..64815ea 100644 --- a/app/Language/en/Cloudflare/Zone.php +++ b/app/Language/en/Cloudflare/Zone.php @@ -1,38 +1,38 @@ "Zone정보", - 'label' => [ - 'uid' => "번호", - 'account_uid' => "계정", - 'domain' => "도메인", - 'name_servers' => "네임서버", - 'original_name_servers' => "이전네임서버", - 'plan' => "plan", - 'development_mode' => "개발모드", - 'ipv6' => "ipv6", - 'security_level' => "공격방어", - 'status' => "서비스", - 'updated_at' => "수정일", - 'created_at' => "작성일" + 'title' => "Zone정보", + 'label' => [ + 'uid' => "번호", + 'account_uid' => "계정", + 'domain' => "도메인", + 'name_servers' => "네임서버", + 'original_name_servers' => "이전네임서버", + 'plan' => "plan", + 'development_mode' => "개발모드", + 'ipv6' => "ipv6", + 'security_level' => "공격방어", + 'status' => "서비스", + 'updated_at' => "수정일", + 'created_at' => "작성일", ], - "ACCOUNT_UID" => [ + "ACCOUNT_UID" => [ ], "DEVELOPMENT_MODE" => [ - "on" => "사용", + "on" => "사용", "off" => "사용않함", ], - "IPV6" => [ - "on" => "사용", + "IPV6" => [ + "on" => "사용", "off" => "사용않함", ], - "SECURITY_LEVEL" => [ - "under_attack" => "under_attack", - "medium" => "medium", - "low" => "low", - "essentially_off" => "essentially_off" + "SECURITY_LEVEL" => [ + "under_attack" => "under_attack", + "medium" => "medium", + "low" => "low", + "essentially_off" => "essentially_off", ], - "STATUS" => [ - "active" => "active", + "STATUS" => [ + "active" => "active", "pending" => "pending", - ], + ], ]; \ No newline at end of file diff --git a/app/Language/en/Mapurl.php b/app/Language/en/Mapurl.php index 32648f2..b2ebc5d 100644 --- a/app/Language/en/Mapurl.php +++ b/app/Language/en/Mapurl.php @@ -1,16 +1,16 @@ "URL Mapping 정보", - 'label' => [ - 'uid' => "번호", - 'oldurl' => "기존URL", - 'newurl' => "신규URL", - 'status' => "상태", + 'title' => "URL Mapping 정보", + 'label' => [ + 'uid' => "번호", + 'oldurl' => "기존URL", + 'newurl' => "신규URL", + 'status' => "상태", 'updated_at' => "수정일", - 'created_at' => "작성일" + 'created_at' => "작성일", ], "STATUS" => [ - "use" => "사용", + "use" => "사용", "unuse" => "사용않함", - ] + ], ]; diff --git a/app/Language/en/User.php b/app/Language/en/User.php index 4647d0d..0223490 100644 --- a/app/Language/en/User.php +++ b/app/Language/en/User.php @@ -1,27 +1,27 @@ "계정정보", - 'label' => [ - 'uid' => "번호", - 'id' => "계정", - 'passwd' => "암호", + 'title' => "계정정보", + 'label' => [ + 'uid' => "번호", + 'id' => "계정", + 'passwd' => "암호", 'confirmpassword' => "암호확인", - 'email' => "메일", - 'role' => "권한", - 'name' => "이름", - 'status' => "상태", - 'updated_at' => "수정일", - 'created_at' => "작성일" + 'email' => "메일", + 'role' => "권한", + 'name' => "이름", + 'status' => "상태", + 'updated_at' => "수정일", + 'created_at' => "작성일", ], - "ROLE" => [ - "member" => "회원", - "manager" => "관리자", + "ROLE" => [ + "member" => "회원", + "manager" => "관리자", "cloudflare" => "Cloudflare관리자", - "director" => "감독자", - "master" => "마스터" + "director" => "감독자", + "master" => "마스터", ], "STATUS" => [ - "use" => "사용", + "use" => "사용", "unuse" => "사용않함", - ] + ], ]; diff --git a/app/Libraries/MyCloudflare/Account.php b/app/Libraries/MyCloudflare/Account.php index 151ca22..beab6e4 100644 --- a/app/Libraries/MyCloudflare/Account.php +++ b/app/Libraries/MyCloudflare/Account.php @@ -35,7 +35,7 @@ class Account extends MyCloudflare // "legacy_flags":{"enterprise_zone_quota":{"maximum":0,"current":0,"available":0}}, // "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()->getTitleField()] = $result->name; @@ -48,7 +48,7 @@ class Account extends MyCloudflare public function create(array $formDatas): AccountEntity { //Socket용 - $cf = $this->getMySocket()->request($formDatas['apikey']) + $cf = $this->getMySocket()->request($formDatas['authkey']) ->post('accounts', [ 'name' => $formDatas[$this->getMyStorage()->getTitleField()], 'type' => $formDatas['type'], @@ -58,7 +58,7 @@ class Account extends MyCloudflare throw new \Exception(__FUNCTION__ . "에서 실패:\n" . var_export($cf, true)); } //Storage용 - $formDatas = $this->getArrayByResult($cf->result); + $formDatas = $this->getArrayByResult($cf->result, $formDatas); $entity = $this->getMyStorage()->create($formDatas); log_message("notice", "Account::" . __FUNCTION__ . "=> 작업을 완료하였습니다."); return $entity; diff --git a/app/Libraries/MyCloudflare/MyCloudflare.php b/app/Libraries/MyCloudflare/MyCloudflare.php index 29f29e8..224fd6c 100644 --- a/app/Libraries/MyCloudflare/MyCloudflare.php +++ b/app/Libraries/MyCloudflare/MyCloudflare.php @@ -13,7 +13,7 @@ abstract class MyCloudflare extends CommonLibrary { parent::__construct(); } - abstract protected function getArrayByResult($result): array; + abstract protected function getArrayByResult($result, array $formDatas = []): array; abstract protected function reload_entity($cf): mixed; abstract public function getMyStorage(): mixed; final protected function getMySocket(): CloudflareSocket diff --git a/app/Libraries/MyCloudflare/Record.php b/app/Libraries/MyCloudflare/Record.php index 6174ef1..776450a 100644 --- a/app/Libraries/MyCloudflare/Record.php +++ b/app/Libraries/MyCloudflare/Record.php @@ -22,7 +22,7 @@ class Record extends MyCloudflare } 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 { @@ -31,7 +31,7 @@ class Record extends MyCloudflare } return $this->_myStorage; } - protected function getArrayByResult($result): array + protected function getArrayByResult($result, array $formDatas = []): array { $formDatas[$this->getMyStorage()->getPKField()] = $result->id; $formDatas[$this->getMyStorage()::PARENT] = $result->zone_id; diff --git a/app/Libraries/MyCloudflare/Zone.php b/app/Libraries/MyCloudflare/Zone.php index 8a6431c..49a979e 100644 --- a/app/Libraries/MyCloudflare/Zone.php +++ b/app/Libraries/MyCloudflare/Zone.php @@ -20,7 +20,7 @@ class Zone extends MyCloudflare } 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 { @@ -29,7 +29,7 @@ class Zone extends MyCloudflare } return $this->_myStorage; } - protected function getArrayByResult($result): array + protected function getArrayByResult($result, array $formDatas = []): array { $formDatas[$this->getMyStorage()->getPKField()] = $result->id; $formDatas[$this->getMyStorage()::PARENT] = $result->account->id; diff --git a/app/Libraries/MySocket/CloudflareSocket.php b/app/Libraries/MySocket/CloudflareSocket.php index c16d7f6..11d34af 100644 --- a/app/Libraries/MySocket/CloudflareSocket.php +++ b/app/Libraries/MySocket/CloudflareSocket.php @@ -25,25 +25,25 @@ class CloudflareSocket extends CommonLibrary $this->initAdapters(); self::$_request_max = getenv("cfmgr.request.max"); } - final protected function getAccountModel(): AccountModel + private function getAccountModel(): AccountModel { if ($this->_accountModel === null) { $this->_accountModel = new AccountModel(); } return $this->_accountModel; } - final public function initAdapters(): void + private function initAdapters(): void { foreach ($this->getAccountModel()->getEntitys() as $entity) { - $this->_clients[$entity->getAPIKey()] = new Guzzle( - new APIKey($entity->getTitle(), $entity->getAPIKey()) + $this->_clients[$entity->getAuthKey()] = new Guzzle( + 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)) { - throw new \Exception(+__FUNCTION__ . " => {$apikey}에 해당하는 Adapter를 찾을수 없습니다."); + if (!array_key_exists($authkey, $this->_clients)) { + throw new \Exception(+__FUNCTION__ . " => {$authkey}에 해당하는 Adapter를 찾을수 없습니다."); } if (self::$_request >= self::$_request_max) { 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)); } 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)); // } } diff --git a/app/Models/Cloudflare/AccountModel.php b/app/Models/Cloudflare/AccountModel.php index b42526f..4bd37e2 100644 --- a/app/Models/Cloudflare/AccountModel.php +++ b/app/Models/Cloudflare/AccountModel.php @@ -9,12 +9,12 @@ class AccountModel extends CommonModel { const TABLE = "cloudflarerecord"; const PK = "uid"; - const TITLE = "id"; + const TITLE = "title"; protected $table = self::TABLE; protected $primaryKey = self::PK; protected $useAutoIncrement = false; 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; public function __construct() { @@ -29,13 +29,16 @@ class AccountModel extends CommonModel switch ($field) { case self::TITLE: $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}/]"; ; break; 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}/]"; - ; break; case "type": $rules[$field] = "if_exist|in_list[standard,enterprise]"; @@ -63,7 +66,7 @@ class AccountModel extends CommonModel } public function getEntityByID(string $id): null|AccountEntity { - $this->where($this->getTitleField(), $id); + $this->where('id', $id); return $this->getEntity(); } //create용 diff --git a/app/Models/Mangboard/BoardModel.php b/app/Models/Mangboard/BoardModel.php deleted file mode 100644 index fe72b7a..0000000 --- a/app/Models/Mangboard/BoardModel.php +++ /dev/null @@ -1,158 +0,0 @@ -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); - } -} diff --git a/app/Models/Mangboard/BoardsModel.php b/app/Models/Mangboard/BoardsModel.php deleted file mode 100644 index cec01e4..0000000 --- a/app/Models/Mangboard/BoardsModel.php +++ /dev/null @@ -1,146 +0,0 @@ -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); - } -} diff --git a/app/Models/Mangboard/FileModel.php b/app/Models/Mangboard/FileModel.php deleted file mode 100644 index 4bb7d52..0000000 --- a/app/Models/Mangboard/FileModel.php +++ /dev/null @@ -1,127 +0,0 @@ -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); - } -} diff --git a/app/Models/Mangboard/UserModel.php b/app/Models/Mangboard/UserModel.php deleted file mode 100644 index a3ce736..0000000 --- a/app/Models/Mangboard/UserModel.php +++ /dev/null @@ -1,236 +0,0 @@ -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; - } -}