From 0ead124c338efe99d68a1be59f9c3a6c232f7253 Mon Sep 17 00:00:00 2001 From: "choi.jh" Date: Mon, 25 Aug 2025 14:13:34 +0900 Subject: [PATCH] dbmsv2 init...1 --- .../Admin/Equipment/ServerController.php | 2 +- app/Controllers/CommonController.php | 223 ++++++++++-------- app/Services/CommonService.php | 28 ++- app/Services/Customer/ClientService.php | 6 +- app/Services/Customer/ServiceService.php | 4 +- app/Services/Equipment/ServerService.php | 3 +- app/Services/UserService.php | 6 +- app/Views/admin/create_form.php | 2 +- app/Views/admin/popup/create_form.php | 2 +- .../templates/admin/index_content_top.php | 2 +- 10 files changed, 148 insertions(+), 130 deletions(-) diff --git a/app/Controllers/Admin/Equipment/ServerController.php b/app/Controllers/Admin/Equipment/ServerController.php index f5e5f71..51a699c 100644 --- a/app/Controllers/Admin/Equipment/ServerController.php +++ b/app/Controllers/Admin/Equipment/ServerController.php @@ -59,7 +59,7 @@ class ServerController extends EquipmentController throw new \Exception(__METHOD__ . "에서 code의 format이 정의되지 않았습니다."); } $default = (int)env("Server.Default.code", 0); - $this->setDefaultValue('code', $this->getService()->getLastestCode($format, $default)); + $this->setFormDatasDefault('code', $this->getService()->getLastestCode($format, $default)); parent::create_form_process(); } } diff --git a/app/Controllers/CommonController.php b/app/Controllers/CommonController.php index 7bf2026..a798baa 100644 --- a/app/Controllers/CommonController.php +++ b/app/Controllers/CommonController.php @@ -89,10 +89,6 @@ abstract class CommonController extends BaseController } return $action; } - final protected function setDefaultValue(string $field, mixed $value) - { - $this->_control['default_values'][$field] = $value; - } final protected function initAction(string $action, ?array $actionFields = null): void { $this->setAction($action); @@ -127,17 +123,6 @@ abstract class CommonController extends BaseController $this->_control['filter_optons'][$field][$option->getPK()] = $option; } } - //Paramter로 전달되거나 해당 필드의 기본값 정의용 - $this->_control['default_values'] = []; - foreach ($this->getControlDatas('actionFilters') as $field) { - $this->setDefaultValue($field, $this->request->getVar($field)); - } - // echo var_dump($actionFields); - // echo var_dump($fields); - // echo var_dump($filters); - // echo var_dump($this->getControlDatas('actionFields')); - // echo var_dump($this->getControlDatas('field_rules')); - // exit; } //전체 FormDatas 전달값받기 final protected function getFormDatas(array $fields, array $formDatas = []): array @@ -153,6 +138,13 @@ abstract class CommonController extends BaseController } return $formDatas; } + final protected function setFormDatasDefault(string $field, mixed $default): void + { + if (array_key_exists('form_data_defaults', $this->_control)) { + $this->_control['form_data_defaults'] = []; + } + $this->_control['form_data_defaults'][$field] = $default; + } //FormDatas 검증 final protected function doValidate(array $rules, array $formDatas, ?Validation $validation = null): array { @@ -300,7 +292,11 @@ abstract class CommonController extends BaseController } //각 Field 초기화: 일괄작업은 선택된 조건항목 Field만 존재하므로 Field와 Rule을 정의 $this->initAction(__FUNCTION__, ['fields' => [$selectedFields], 'filters' => [$selectedFields]]); - $this->batchjob_process($uids, $formDatas); + $entities = []; + foreach ($uids as $uid) { + $entities = $this->batchjob_process($uid, $formDatas, $entities); + } + $this->entities = $entities; $this->_db->transCommit(); LogCollector::debug(sprintf("%s에서 총 %s개중 %s개 일괄작업을 완료하였습니다.", __METHOD__, count($uids), count($this->entities))); return $this->getResultSuccess(); @@ -342,7 +338,11 @@ abstract class CommonController extends BaseController } //각 Field 초기화:삭제는 다른 초기화 필요없음 $this->setAction(__FUNCTION__); - $this->batchjob_delete_process($uids); + $entities = []; + foreach ($uids as $uid) { + $entities = $this->batchjob_delete_process($uid, $entities); + } + $this->entities = $entities; $this->_db->transCommit(); LogCollector::debug(sprintf("%s에서 총 %s개중 %s개 일괄삭제를 완료하였습니다.", __METHOD__, count($uids), count($this->entities))); return $this->getResultSuccess(); @@ -369,53 +369,6 @@ abstract class CommonController extends BaseController return $this->getResultFail($e->getMessage()); } } - //리스트 기능 - //조건절 처리 - final protected function index_process_condition(): void - { - //Filter 조건절 처리 - foreach ($this->_control['actionFilters'] as $field) { - $default_value = $this->request->getVar($field); - if ($default_value !== null && $default_value !== '') { - $this->getService()->setList_FormFilter($field, $default_value); - } - } - //검색어조건절 처리 - $this->word = $this->request->getVar('word'); - if ($this->word !== null && $this->word !== '') { - $this->getService()->setList_WordFilter($this->word); - } - //날자검색 - $this->start = $this->request->getVar('start'); - $this->end = $this->request->getVar('end'); - if ($this->start !== null && $this->start !== '' && $this->end !== null && $this->end !== '') { - $this->getService()->setList_DateFilter($this->start, $this->end); - } - } - //PageNation 처리 - final protected function getPageOptiosForList(): array - { - $page_options = ["" => "줄수선택"]; - for ($i = $this->per_page; $i <= $this->total_count; $i += $this->per_page) { - $page_options[$i] = $i; - } - $page_options[$this->total_count] = $this->total_count; - return $page_options; - } - final protected function getPaginationForList($pager_group = 'default', int $segment = 0, $template = 'bootstrap_full') - { - //Page, Per_page필요부분 - $this->page = (int) $this->request->getVar('page') ?: 1; - $this->per_page = (int) $this->request->getVar('per_page') ?: intval(DEFAULT_LIST_PERPAGE ?? 20); - // 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 = service("pager"); - $pager->makeLinks($this->page, $this->per_page, $this->total_count, $template, $segment, $pager_group); - $this->page = $pager->getCurrentPage($pager_group); - $this->total_page = $pager->getPageCount($pager_group); - return $pager->links($pager_group, $template); - } //OUPUT Document 관련 private function download_document(string $document_type, mixed $loaded_data): array { @@ -475,11 +428,15 @@ abstract class CommonController extends BaseController //공통 기본 기능 //추가 개별 처리 기능 - //Field별 전달값받기 + //FormData Field별 전달값 처리 protected function getFormData_process(string $field, array $formDatas): array { return $formDatas; } + protected function getFormDataDefault_process(string $field, array $formDatas): array + { + return $formDatas; + } protected function doValidation_process(Validation $validation, string $field, string $rule): Validation { switch ($field) { @@ -558,21 +515,18 @@ abstract class CommonController extends BaseController $this->entity = $this->getService()->modify($entity, $validDatas); } //일괄처리작업기능 - protected function batchjob_process(array $uids, array $formDatas): void + protected function batchjob_process(string|int $uid, array $formDatas, array $entities = []): array { - $entities = []; - foreach ($uids as $uid) { - //기존 Entity 가져오기 - $entity = $this->getService()->getEntity($uid); - if (!$entity) { - LogCollector::debug(__METHOD__ . "에서 {$uid}에 대한 정보를 찾을수 없습니다."); - } else { - //데이터 검증 - $validDatas = $this->doValidate($this->getControlDatas('field_rules'), $formDatas); - $entities[] = $this->getService()->modify($entity, $validDatas); - } + //기존 Entity 가져오기 + $entity = $this->getService()->getEntity($uid); + if (!$entity) { + LogCollector::debug(__METHOD__ . "에서 {$uid}에 대한 정보를 찾을수 없습니다."); + } else { + //데이터 검증 + $validDatas = $this->doValidate($this->getControlDatas('field_rules'), $formDatas); + $entities[] = $this->getService()->modify($entity, $validDatas); } - $this->entities = $entities; + return $entities; } //삭제관련 protected function delete_process(mixed $entity): void @@ -580,19 +534,16 @@ abstract class CommonController extends BaseController $this->entity = $this->getService()->delete($entity); } //일괄삭제관련 - protected function batchjob_delete_process(array $uids): void + protected function batchjob_delete_process(string|int $uid, array $entities = []): array { - $entities = []; - foreach ($uids as $uid) { - //기존 Entity 가져오기 - $entity = $this->getService()->getEntity($uid); - if (!$entity) { - LogCollector::debug(__METHOD__ . "에서 {$uid}에 대한 정보를 찾을수 없습니다."); - } else { - $entities[] = $this->getService()->delete($entity); - } + //기존 Entity 가져오기 + $entity = $this->getService()->getEntity($uid); + if (!$entity) { + LogCollector::debug(__METHOD__ . "에서 {$uid}에 대한 정보를 찾을수 없습니다."); + } else { + $entities[] = $this->getService()->delete($entity); } - $this->entities = $entities; + return $entities; } //View 관련 protected function view_process(mixed $entity): void @@ -600,16 +551,73 @@ abstract class CommonController extends BaseController $this->entity = $entity; } //리스트관련 - protected function index_process(): void + //조건절 처리 + //Filter Field별 전달값 처리 + protected function index_condition_filter_process(string $field, $default = null): mixed { - //조건절 , OrcerBy , Limit 처리 - $this->index_process_condition(); - $this->order_field = $this->request->getVar('order_field'); - $this->order_value = $this->request->getVar('order_value'); - $this->getService()->setOrderBy($this->order_field, $this->order_value); - $this->getService()->setLimit($this->per_page); - $this->getService()->setOffset(($this->page - 1) * $this->per_page); - $this->entities = $this->getService()->getEntities(); + switch ($field) { + default: + $filter_value = $this->request->getVar($field); + break; + } + return $filter_value; + } + protected function index_condition_process(): void + { + //Paramter로 전달된 Filter값을 정의용 + $filter_values = []; + foreach ($this->_control['actionFilters'] as $field) { + $filter_value = $this->index_condition_filter_process($field); + if ($filter_value !== null && $filter_value !== '') { + $this->getService()->setList_FormFilter($field, $filter_value); + $filter_values[] = $filter_value; + } + } + $this->_control['filter_values'][$field] = $filter_values; + //검색어조건절 처리 + $this->word = $this->request->getVar('word'); + if ($this->word !== null && $this->word !== '') { + $this->getService()->setList_WordFilter($this->word); + } + //날자검색 + $this->start = $this->request->getVar('start'); + $this->end = $this->request->getVar('end'); + if ($this->start !== null && $this->start !== '' && $this->end !== null && $this->end !== '') { + $this->getService()->setList_DateFilter($this->start, $this->end); + } + } + //PageNation 처리 + protected function index_pagenation_process($pager_group = 'default', int $segment = 0, $template = 'bootstrap_full') + { + //Page, Per_page필요부분 + $this->page = (int) $this->request->getVar('page') ?: 1; + $this->per_page = (int) $this->request->getVar('per_page') ?: intval(DEFAULT_LIST_PERPAGE ?? 20); + // 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 = service("pager"); + $pager->makeLinks($this->page, $this->per_page, $this->total_count, $template, $segment, $pager_group); + $this->page = $pager->getCurrentPage($pager_group); + $this->total_page = $pager->getPageCount($pager_group); + return $pager->links($pager_group, $template); + } + //Page출력 처리 + protected function index_pageOptions_process(): array + { + $page_options = ["" => "줄수선택"]; + for ($i = $this->per_page; $i <= $this->total_count; $i += $this->per_page) { + $page_options[$i] = $i; + } + $page_options[$this->total_count] = $this->total_count; + return $page_options; + } + //Entities처리 + protected function index_process(array $entities = []): array + { + foreach ($this->getService()->getEntities() as $entity) { + $entities[] = $entity; + } + return $entities; } public function index(): RedirectResponse|string { @@ -617,19 +625,26 @@ abstract class CommonController extends BaseController //FieldRule정의 //각 Field 초기화 $this->initAction(__FUNCTION__); + helper(['form']); //Return Url정의 $this->getMyAuth()->pushCurrentUrl($this->request->getUri()->getPath() . ($this->request->getUri()->getQuery() ? "?" . $this->request->getUri()->getQuery() : "")); - // 현재 URL을 스택에 저장 - helper(['form']); //조건절 처리 - $this->index_process_condition(); + $this->index_condition_process(); //TotalCount (SoftDelete적용이 되려면 countAllResults를 사용해야함) $this->total_count = $this->getService()->getTotalCount(); //Pagination 처리 - $this->pagination = $this->getPaginationForList(); + $this->pagination = $this->index_pagenation_process(); //줄수 처리용 - $this->page_options = $this->getPageOptiosForList(); - $this->index_process(); + $this->page_options = $this->index_pageOptions_process(); + //조건절 처리 + //OrcerBy , Limit 처리 + $this->order_field = $this->request->getVar('order_field'); + $this->order_value = $this->request->getVar('order_value'); + $this->getService()->setOrderBy($this->order_field, $this->order_value); + $this->getService()->setLimit($this->per_page); + $this->getService()->setOffset(($this->page - 1) * $this->per_page); + $this->index_condition_process(); + $this->entities = $this->index_process(); return $this->getResultSuccess(); } catch (\Exception $e) { return $e->getMessage(); diff --git a/app/Services/CommonService.php b/app/Services/CommonService.php index 938e467..66af0d8 100644 --- a/app/Services/CommonService.php +++ b/app/Services/CommonService.php @@ -48,6 +48,11 @@ abstract class CommonService } return $this->_model; } + //Entity별로 작업처리시 + protected function getEntity_process(mixed $entity): mixed + { + return $entity; + } final public function getEntity(mixed $where, ?string $message = null): mixed { try { @@ -55,7 +60,7 @@ abstract class CommonService if (!$entity) { throw new \Exception($message ?? __METHOD__ . "에서 해당 정보가 존재하지 않습니다"); } - return $entity; + return $this->getEntity_process($entity); } catch (\Exception $e) { $message = sprintf( "\n------%s SQL오류-----\n%s\n------------------------------\n", @@ -65,21 +70,20 @@ abstract class CommonService throw new \Exception($message); } } - protected function findAllDatas_process(array $columns = ['*']): array + //entities를 가져오는 조건 + protected function getEntities_process(mixed $where = null, array $columns = ['*']): array { - $entities = $this->getModel()->select(implode(',', $columns))->findAll(); - // dd($entities); - return $entities; + if ($where) { + $this->getModel()->where($where); + } + return $this->getModel()->select(implode(',', $columns))->findAll(); } final public function getEntities(mixed $where = null, array $columns = ['*']): array { try { - if ($where) { - $this->getModel()->where($where); - } $entities = []; - foreach ($this->findAllDatas_process($columns) as $entity) { - $entities[$entity->getPK()] = $entity; + foreach ($this->getEntities_process($where, $columns) as $entity) { + $entities[$entity->getPK()] = $this->getEntity_process($entity); } return $entities; } catch (\Exception $e) { @@ -187,12 +191,12 @@ abstract class CommonService $this->getModel()->offset($offset); } //FormFilter 조건절 처리 - public function setList_FormFilter(string $field, mixed $default_value): void + public function setList_FormFilter(string $field, mixed $filter_value): void { switch ($field) { default: //일반검색 - $this->getModel()->where("{$this->getModel()->getTable()}.{$field}", $default_value); + $this->getModel()->where("{$this->getModel()->getTable()}.{$field}", $filter_value); break; } } diff --git a/app/Services/Customer/ClientService.php b/app/Services/Customer/ClientService.php index bd072d1..4d77515 100644 --- a/app/Services/Customer/ClientService.php +++ b/app/Services/Customer/ClientService.php @@ -138,16 +138,16 @@ class ClientService extends CustomerService //List 검색용 //FormFilter 조건절 처리 - public function setList_FormFilter(string $field, mixed $default_value): void + public function setList_FormFilter(string $field, mixed $filter_value): void { switch ($field) { case 'role': - $where = "FIND_IN_SET(" . $this->getModel()->escape($default_value) . ", {$this->getModel()->getTable()}.{$field}) > 0"; + $where = "FIND_IN_SET(" . $this->getModel()->escape($filter_value) . ", {$this->getModel()->getTable()}.{$field}) > 0"; //FIND_IN_SET()은 MySQL 함수이므로 CodeIgniter가 이를 일반 컬럼명으로 착각하고 escape하게 되면 오류가 발생합니다. 따라서 ->where($sql, null, false)로 명시하여 escape를 꺼줘야 정상 작동 $this->getModel()->where($where, null, false); break; default: - parent::setList_FormFilter($field, $default_value); + parent::setList_FormFilter($field, $filter_value); break; } } diff --git a/app/Services/Customer/ServiceService.php b/app/Services/Customer/ServiceService.php index 8f68652..833ca49 100644 --- a/app/Services/Customer/ServiceService.php +++ b/app/Services/Customer/ServiceService.php @@ -81,7 +81,7 @@ class ServiceService extends CustomerService { return $this->_searchIP; } - // protected function findAllDatas_process(array $columns = ['*']): mixed + // protected function getEntities_process(mixed $where = null,array $columns = ['*']): mixed // { // $ip = $this->getSearchIp(); // if ($ip) { @@ -91,7 +91,7 @@ class ServiceService extends CustomerService // AND serviceinfo_items.item_uid IN (SELECT uid FROM ipinfo WHERE ip = ?)"; // return $this->getModel()->query($sql, ['IP', $ip])->getResult(ServiceEntity::class); // } - // return parent::findAllDatas_process($columns); + // return parent::getEntities_process($where,$columns); // } //기본 기능부분 //FieldForm관련용 diff --git a/app/Services/Equipment/ServerService.php b/app/Services/Equipment/ServerService.php index 255fb9b..635f223 100644 --- a/app/Services/Equipment/ServerService.php +++ b/app/Services/Equipment/ServerService.php @@ -175,8 +175,7 @@ class ServerService extends EquipmentService if ($entity->getServiceInfoUID()) { //서비스정보가 있다면 $partFormDatas["serviceinfo_uid"] = $entity->getServiceInfoUID(); } - - dd($formDatas); + // dd($formDatas); $partFormDatas["billing_method"] = PAYMENT['BILLING']['METHOD_MONTH']; $partLinkFormDatas = []; foreach (self::BaseParts as $basePart) { diff --git a/app/Services/UserService.php b/app/Services/UserService.php index f78d0f1..9d7c475 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -93,16 +93,16 @@ class UserService extends CommonService } //List 검색용 //FormFilter 조건절 처리 - public function setList_FormFilter(string $field, mixed $default_value): void + public function setList_FormFilter(string $field, mixed $filter_value): void { switch ($field) { case 'role': - $where = "FIND_IN_SET(" . $this->getModel()->escape($default_value) . ", {$this->getModel()->getTable()}.{$field}) > 0"; + $where = "FIND_IN_SET(" . $this->getModel()->escape($filter_value) . ", {$this->getModel()->getTable()}.{$field}) > 0"; //FIND_IN_SET()은 MySQL 함수이므로 CodeIgniter가 이를 일반 컬럼명으로 착각하고 escape하게 되면 오류가 발생합니다. 따라서 ->where($sql, null, false)로 명시하여 escape를 꺼줘야 정상 작동 $this->getModel()->where($where, null, false); break; default: - parent::setList_FormFilter($field, $default_value); + parent::setList_FormFilter($field, $filter_value); break; } } diff --git a/app/Views/admin/create_form.php b/app/Views/admin/create_form.php index 44a5bcf..2ab7d5d 100644 --- a/app/Views/admin/create_form.php +++ b/app/Views/admin/create_form.php @@ -10,7 +10,7 @@ getFieldLabel($field, lang("{$viewDatas['class_path']}.label.{$field}"), $viewDatas) ?> - getFieldForm($field, old($field) ?? ($viewDatas['control']['default_values'][$field] ?? null), $viewDatas) ?> + getFieldForm($field, old($field) ?? ($viewDatas['control']['form_data_defaults'][$field] ?? null), $viewDatas) ?> diff --git a/app/Views/admin/popup/create_form.php b/app/Views/admin/popup/create_form.php index 44a5bcf..2ab7d5d 100644 --- a/app/Views/admin/popup/create_form.php +++ b/app/Views/admin/popup/create_form.php @@ -10,7 +10,7 @@ getFieldLabel($field, lang("{$viewDatas['class_path']}.label.{$field}"), $viewDatas) ?> - getFieldForm($field, old($field) ?? ($viewDatas['control']['default_values'][$field] ?? null), $viewDatas) ?> + getFieldForm($field, old($field) ?? ($viewDatas['control']['form_data_defaults'][$field] ?? null), $viewDatas) ?> diff --git a/app/Views/templates/admin/index_content_top.php b/app/Views/templates/admin/index_content_top.php index a858705..1d58eed 100644 --- a/app/Views/templates/admin/index_content_top.php +++ b/app/Views/templates/admin/index_content_top.php @@ -4,7 +4,7 @@