From 383e3e4ac98a1c74056ae19322cfde17fa679eb0 Mon Sep 17 00:00:00 2001 From: "choi.jh" Date: Mon, 1 Sep 2025 13:54:20 +0900 Subject: [PATCH] dbmsv2 init...1 --- app/Config/Routes.php | 10 +- .../Admin/Customer/ClientController.php | 4 +- .../Admin/Customer/PaymentController.php | 8 +- .../Admin/Equipment/ServerController.php | 12 +- app/Controllers/Admin/Home.php | 9 +- app/Controllers/Admin/SearchController.php | 6 +- app/Controllers/Admin/UserController.php | 49 +- app/Controllers/Auth/AuthController.php | 51 +- app/Controllers/Auth/GoogleController.php | 2 +- app/Controllers/Auth/LocalController.php | 2 +- app/Controllers/CommonController.php | 819 +++++++++--------- app/Helpers/CommonHelper.php | 20 +- app/Helpers/Customer/AccountHelper.php | 2 +- app/Helpers/Customer/CouponHelper.php | 2 +- app/Helpers/Customer/PaymentHelper.php | 4 +- app/Helpers/Customer/PointHelper.php | 2 +- app/Helpers/Customer/ServiceHelper.php | 4 +- app/Helpers/HomeHelper.php | 12 +- app/Helpers/MyLogHelper.php | 4 +- app/Models/CommonModel.php | 2 +- app/Models/Customer/AccountModel.php | 4 +- app/Models/Customer/ClientModel.php | 4 +- app/Models/Customer/CouponModel.php | 4 +- app/Models/Customer/CustomerModel.php | 4 +- app/Models/Customer/PaymentModel.php | 4 +- app/Models/Customer/PointModel.php | 4 +- app/Models/Customer/ServiceModel.php | 4 +- app/Models/Equipment/CSModel.php | 4 +- app/Models/Equipment/EquipmentModel.php | 4 +- app/Models/Equipment/IPModel.php | 4 +- app/Models/Equipment/LineModel.php | 4 +- app/Models/Equipment/PartModel.php | 4 +- app/Models/Equipment/ServerModel.php | 4 +- app/Models/Equipment/ServerPartModel.php | 4 +- app/Models/Equipment/SwitchModel.php | 4 +- app/Models/MyLogModel.php | 4 +- app/Models/UserModel.php | 4 +- app/Models/UserSNSModel.php | 4 +- app/Services/Auth/GoogleService.php | 12 +- app/Services/Auth/LocalService.php | 28 +- app/Services/CommonService.php | 25 +- app/Services/Customer/AccountService.php | 40 +- app/Services/Customer/ClientService.php | 54 +- app/Services/Customer/CouponService.php | 28 +- app/Services/Customer/CustomerService.php | 4 +- app/Services/Customer/PaymentService.php | 68 +- app/Services/Customer/PointService.php | 28 +- app/Services/Customer/ServiceService.php | 75 +- app/Services/Equipment/CSService.php | 59 +- app/Services/Equipment/EquipmentService.php | 4 +- app/Services/Equipment/IPService.php | 61 +- app/Services/Equipment/LineService.php | 34 +- app/Services/Equipment/PartService.php | 29 +- app/Services/Equipment/ServerPartService.php | 37 +- app/Services/Equipment/ServerService.php | 134 +-- app/Services/Equipment/SwitchService.php | 50 +- app/Services/MyLogService.php | 32 +- app/Services/UserSNSService.php | 40 +- app/Services/UserService.php | 53 +- app/Views/admin/create_form.php | 2 +- app/Views/admin/popup/create_form.php | 2 +- app/Views/admin/server/create_form.php | 18 +- app/Views/admin/server/modify_form.php | 16 +- .../auth/{create_form.php => login_form.php} | 0 .../templates/admin/index_content_top.php | 2 +- 65 files changed, 954 insertions(+), 1077 deletions(-) rename app/Views/auth/{create_form.php => login_form.php} (100%) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index eef2e0f..a04ae0a 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -24,9 +24,9 @@ $routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) $routes->group('', ['namespace' => 'App\Controllers'], function ($routes) { $routes->get('/', 'Home::index'); $routes->group('auth', ['namespace' => 'App\Controllers\Auth'], function ($routes) { - $routes->get('login', 'LocalController::create_form'); - $routes->post('login', 'LocalController::create'); - $routes->get('google_login', 'GoogleController::create'); + $routes->get('login', 'LocalController::login_form'); + $routes->post('login', 'LocalController::login'); + $routes->get('google_login', 'GoogleController::login'); $routes->get('logout', 'LocalController::logout'); }); }); @@ -45,8 +45,8 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au $routes->post('batchjob', 'UserController::batchjob', ['filter' => 'authFilter:master']); $routes->post('batchjob_delete', 'UserController::batchjob_delete', ['filter' => 'authFilter:master']); $routes->get('download/(:alpha)', 'UserController::download/$1', ['filter' => 'authFilter:master']); - $routes->get('profile_modify/(:num)', 'UserController::profile_modify_form/$1', ['filter' => 'authFilter:manager']); - $routes->post('profile_modify/(:num)', 'UserController::profile_modify/$1', ['filter' => 'authFilter:manager']); + $routes->get('profile/(:num)', 'UserController::profile_form/$1', ['filter' => 'authFilter:manager']); + $routes->post('profile/(:num)', 'UserController::profile/$1', ['filter' => 'authFilter:manager']); }); $routes->group('mylog', ['namespace' => 'App\Controllers\Admin'], function ($routes) { $routes->get('/', 'MyLogController::index'); diff --git a/app/Controllers/Admin/Customer/ClientController.php b/app/Controllers/Admin/Customer/ClientController.php index 82c8ce2..a5da90f 100644 --- a/app/Controllers/Admin/Customer/ClientController.php +++ b/app/Controllers/Admin/Customer/ClientController.php @@ -61,7 +61,7 @@ class ClientController extends CustomerController $formDatas['user_uid'] = $this->getMyAuth()->getUIDByAuthInfo(); return parent::modify_process($entity, $formDatas); } - protected function doValidation_process(Validation $validation, string $field, string $rule): Validation + protected function doValidation(Validation $validation, string $field, string $rule): Validation { switch ($field) { case 'role': @@ -69,7 +69,7 @@ class ClientController extends CustomerController $validation->setRule("{$field}.*", $field, $rule); break; default: - $validation = parent::doValidation_process($validation, $field, $rule); + $validation = parent::doValidation($validation, $field, $rule); break; } return $validation; diff --git a/app/Controllers/Admin/Customer/PaymentController.php b/app/Controllers/Admin/Customer/PaymentController.php index 9ffd625..70a5a0a 100644 --- a/app/Controllers/Admin/Customer/PaymentController.php +++ b/app/Controllers/Admin/Customer/PaymentController.php @@ -48,7 +48,7 @@ class PaymentController extends CustomerController } return $this->_clientService; } - protected function getResultSuccess_process(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string + protected function getResultSuccess(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string { switch ($this->getAction()) { case 'invoice': @@ -63,7 +63,7 @@ class PaymentController extends CustomerController $result = view($view_file, ['viewDatas' => $this->getViewDatas()]); break; default: - $result = parent::getResultSuccess_process($message, $actionTemplate); + $result = parent::getResultSuccess($message, $actionTemplate); break; } return $result; @@ -141,9 +141,9 @@ class PaymentController extends CustomerController //각 Field 초기화 $this->initAction($this->getService()->getFormFields()); $this->invoice_process(); - return $this->getResultSuccess_process(); + return $this->getResultSuccess(); } catch (\Exception $e) { - return $this->getResultFail_process($e->getMessage()); + return $this->getResultFail($e->getMessage()); } } } diff --git a/app/Controllers/Admin/Equipment/ServerController.php b/app/Controllers/Admin/Equipment/ServerController.php index 86e6017..34734bc 100644 --- a/app/Controllers/Admin/Equipment/ServerController.php +++ b/app/Controllers/Admin/Equipment/ServerController.php @@ -37,7 +37,7 @@ class ServerController extends EquipmentController return $this->_helper; } //Index,FieldForm관련 - protected function getResultSuccess_process(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string + protected function getResultSuccess(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string { switch ($this->getAction()) { case 'create_form': @@ -54,7 +54,7 @@ class ServerController extends EquipmentController $result = view($view_file, ['viewDatas' => $this->getViewDatas()]); break; default: - $result = parent::getResultSuccess_process($message, $actionTemplate); + $result = parent::getResultSuccess($message, $actionTemplate); break; } return $result; @@ -66,7 +66,13 @@ class ServerController extends EquipmentController if (!$format) { throw new \Exception(__METHOD__ . "에서 code의 format[Server.Prefix.code.format]이 정의되지 않았습니다."); } - $this->setFieldDefaultValue('code', $this->getService()->getLastestCode($format, (int)env("Server.Default.code", 0))); + //기본값정의 + $this->setFormDatas([ + 'code' => $this->getService()->getLastestCode( + $format, + (int)env("Server.Default.code", 0) + ) + ]); parent::create_form_process(); } //생성 diff --git a/app/Controllers/Admin/Home.php b/app/Controllers/Admin/Home.php index e16b352..7b3123d 100644 --- a/app/Controllers/Admin/Home.php +++ b/app/Controllers/Admin/Home.php @@ -44,7 +44,7 @@ class Home extends AdminController } return $this->_PaymentService; } - protected function getResultSuccess_process(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string + protected function getResultSuccess(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string { switch ($this->getAction()) { case 'index': @@ -59,7 +59,7 @@ class Home extends AdminController $result = view($view_file, ['viewDatas' => $this->getViewDatas()]); break; default: - $result = parent::getResultSuccess_process($message, $actionTemplate); + $result = parent::getResultSuccess($message, $actionTemplate); } return $result; } @@ -68,10 +68,7 @@ class Home extends AdminController //Index,FieldForm관련 public function index(): RedirectResponse|string { - //각 Field 초기화 $this->setAction(__FUNCTION__); - //각 Field 초기화 - $this->initAction($this->getService()->getIndexFields()); //Total 서버 현황 $this->totalCounts = $this->getService()->getTotalCountsByType(); //interval을 기준으로 최근 신규 서비스정보 가져오기 @@ -82,6 +79,6 @@ class Home extends AdminController $this->unPaids = $this->getPaymentService()->getUnPaidCount(); $this->unPaidCount = count($this->unPaids); helper(['form']); - return $this->getResultSuccess_process(); + return $this->getResultSuccess(); } } diff --git a/app/Controllers/Admin/SearchController.php b/app/Controllers/Admin/SearchController.php index ddc85b1..a53ef4d 100644 --- a/app/Controllers/Admin/SearchController.php +++ b/app/Controllers/Admin/SearchController.php @@ -36,14 +36,14 @@ class SearchController extends AdminController } return $this->_helper; } - protected function getResultSuccess_process(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string + protected function getResultSuccess(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string { switch ($this->getAction()) { case 'index': - $result = parent::getResultSuccess_process($message, $this->request->getVar('ActionTemplate') ?? $actionTemplate ?? 'search'); + $result = parent::getResultSuccess($message, $this->request->getVar('ActionTemplate') ?? $actionTemplate ?? 'search'); break; default: - $result = parent::getResultSuccess_process($message, $actionTemplate); + $result = parent::getResultSuccess($message, $actionTemplate); break; } return $result; diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php index e15cdfb..7fd96cc 100644 --- a/app/Controllers/Admin/UserController.php +++ b/app/Controllers/Admin/UserController.php @@ -41,7 +41,7 @@ class UserController extends AdminController return $this->_helper; } //Index,FieldForm관련 - protected function getResultSuccess_process(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string + protected function getResultSuccess(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string { switch ($this->getAction()) { case 'profile_modify': @@ -60,12 +60,12 @@ class UserController extends AdminController $result = view($view_file, ['viewDatas' => $this->getViewDatas()]); break; default: - $result = parent::getResultSuccess_process($message, $actionTemplate); + $result = parent::getResultSuccess($message, $actionTemplate); break; } return $result; } - protected function doValidation_process(Validation $validation, string $field, string $rule): Validation + protected function doValidation(Validation $validation, string $field, string $rule): Validation { switch ($field) { case 'role': @@ -73,56 +73,59 @@ class UserController extends AdminController $validation->setRule("{$field}.*", $field, $rule); break; default: - $validation = parent::doValidation_process($validation, $field, $rule); + $validation = parent::doValidation($validation, $field, $rule); break; } return $validation; } //Index,FieldForm관련. - final public function profile_modify_form(mixed $uid): RedirectResponse|string + final public function profile_form(mixed $uid): RedirectResponse|string { try { - //각 Field 초기화 $this->setAction(__FUNCTION__); - $this->initAction([ - 'fields' => ['id', 'passwd', 'confirmpassword', 'name', 'email', 'mobile'], - ]); - helper(['form']); + $this->setFormFields(); + $this->setFormFilters(); + $this->setFormRules(); + $this->setFormOptions(); + //기본값정의 + $this->setFormDatas($this->request->getGet()); //기존 Entity 가져오기 $entity = $this->getService()->getEntity($uid); if (!$entity) { throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); } - $this->modify_form_process($entity); + $this->entity = $entity; + helper(['form']); $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; - return $this->getResultSuccess_process(); + return $this->getResultSuccess(); } catch (\Exception $e) { - return $this->getResultFail_process($e->getMessage()); + return $this->getResultFail($e->getMessage()); } } - final public function profile_modify(int $uid): RedirectResponse|string + final public function profile(int $uid): RedirectResponse|string { //Transaction Start + $db = \Config\Database::connect(); $this->_db->transStart(); try { - //각 Field 초기화 $this->setAction(__FUNCTION__); - $this->initAction([ - 'fields' => ['id', 'passwd', 'confirmpassword', 'name', 'email', 'mobile'], - ]); - //전달값받기 - $formDatas = $this->getFormDatas($this->getControlDatas('actionFields'), $this->request->getPost()); + $this->setFormFields(); + $this->setFormFilters(); + $this->setFormRules(); + //전달값정의 + $this->setFormDatas($this->request->getPost()); + $this->doValidations(); //기존 Entity 가져오기 $entity = $this->getService()->getEntity($uid); if (!$entity) { throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); } - $this->modify_process($entity, $formDatas); + $this->entity = $this->modify_process($entity, $this->getFormDatas()); $this->_db->transCommit(); - return $this->getResultSuccess_process(); + return $this->getResultSuccess(); } catch (\Exception $e) { $this->_db->transRollback(); - return $this->getResultFail_process($e->getMessage()); + return $this->getResultFail($e->getMessage()); } } } diff --git a/app/Controllers/Auth/AuthController.php b/app/Controllers/Auth/AuthController.php index 84e1061..17f17c4 100644 --- a/app/Controllers/Auth/AuthController.php +++ b/app/Controllers/Auth/AuthController.php @@ -4,6 +4,7 @@ namespace App\Controllers\Auth; use App\Controllers\CommonController; +use App\Entities\UserEntity; use App\Helpers\AuthHelper; use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RequestInterface; @@ -22,6 +23,7 @@ abstract class AuthController extends CommonController $this->content_title = "사용자인증"; } abstract protected function getSNSButton(): string; + abstract protected function login_process(array $formDatas): UserEntity; final public function getHelper(): mixed { if (!$this->_helper) { @@ -29,21 +31,21 @@ abstract class AuthController extends CommonController } return $this->_helper; } - protected function getResultFail_process(string $message = MESSAGES["FAILED"]): RedirectResponse + protected function getResultFail(string $message = MESSAGES["FAILED"]): RedirectResponse { if ($this->request->getMethod() === 'POST') { return redirect()->back()->withInput()->with('error', $message); } return redirect()->to($this->getMyAuth()->popPreviousUrl())->with('error', $message); } - protected function getResultSuccess_process(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string + protected function getResultSuccess(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string { switch ($this->getAction()) { case 'create': //Login처리 $result = redirect()->to($this->getMyAuth()->popPreviousUrl())->with('error', $message); break; default: - $result = parent::getResultSuccess_process($message, $actionTemplate); + $result = parent::getResultSuccess($message, $actionTemplate); break; } return $result; @@ -53,10 +55,51 @@ abstract class AuthController extends CommonController return $formDatas; } //로그인화면 - public function create_form_process(): void + public function login_form_process(): void { $this->sns_buttoh = $this->getSNSButton(); } + public function login_form(): RedirectResponse|string + { + try { + $this->setAction(__FUNCTION__); + $this->setFormFields(); + $this->setFormFilters(); + $this->setFormRules(); + $this->setFormOptions(); + //기본값정의 + $this->setFormDatas($this->request->getGet()); + $this->login_form_process(); + helper(['form']); + $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; + return $this->getResultSuccess(); + } catch (\Exception $e) { + dd($e->getMessage()); + return $this->getResultFail($e->getMessage()); + } + } + //로그인처리 + public function login(): RedirectResponse|string + { + //Transaction Start + $db = \Config\Database::connect(); + $db->transStart(); + try { + $this->setAction(__FUNCTION__); + $this->setFormFields(); + $this->setFormFilters(); + $this->setFormRules(); + //전달값정의 + $this->setFormDatas($this->request->getPost()); + $this->doValidations(); + $this->entity = $this->login_process($this->getFormDatas()); + $db->transCommit(); + return $this->getResultSuccess(); + } catch (\Exception $e) { + $db->transRollback(); + return $this->getResultFail($e->getMessage()); + } + } //로그아웃 final public function logout(): RedirectResponse { diff --git a/app/Controllers/Auth/GoogleController.php b/app/Controllers/Auth/GoogleController.php index 6e45986..c7e9143 100644 --- a/app/Controllers/Auth/GoogleController.php +++ b/app/Controllers/Auth/GoogleController.php @@ -41,7 +41,7 @@ class GoogleController extends AuthController } //로그인처리 - protected function create_process(array $formDatas): UserEntity + protected function login_process(array $formDatas): UserEntity { if (!array_key_exists('access_code', $formDatas) || !$formDatas['access_code']) { throw new \Exception("구글 로그인 실패"); diff --git a/app/Controllers/Auth/LocalController.php b/app/Controllers/Auth/LocalController.php index 44fd5f6..c50fc89 100644 --- a/app/Controllers/Auth/LocalController.php +++ b/app/Controllers/Auth/LocalController.php @@ -29,7 +29,7 @@ class LocalController extends AuthController return ""; } //로그인처리 - protected function create_process(array $formDatas): UserEntity + protected function login_process(array $formDatas): UserEntity { return $this->getService()->login($formDatas); } diff --git a/app/Controllers/CommonController.php b/app/Controllers/CommonController.php index b3aa482..7ed3beb 100644 --- a/app/Controllers/CommonController.php +++ b/app/Controllers/CommonController.php @@ -21,7 +21,6 @@ use Psr\Log\LoggerInterface; abstract class CommonController extends BaseController { - private $_db; private $_myAuth = null; private ?MyLogService $_myLogService = null; private $_viewDatas = []; @@ -38,7 +37,6 @@ abstract class CommonController extends BaseController $this->myAuthName = $this->getMyAuth()->getNameByAuthInfo(); $this->myAuthUID = $this->getMyAuth()->getUIDByAuthInfo(); } - $this->_db = \Config\Database::connect(); } final public function __get($name) { @@ -95,81 +93,104 @@ abstract class CommonController extends BaseController } return $this->_control['action']; } - final protected function initAction(array $actionFields): void + //FormFields정의 + final protected function getFormFields($fields = []): array { - //Fields 정의 - $this->setControlDatas('actionFields', array_key_exists('fields', $actionFields) ? $actionFields['fields'] : []); - //Filters 정의 - $this->setControlDatas('actionFilters', array_key_exists('filters', $actionFields) ? $actionFields['filters'] : []); - //Field Rule정의 - foreach ($this->getControlDatas('actionFields') as $field) { - $this->setFormFielRule($field, $this->getFormFieldRule_process($this->getAction(), $field)); + return array_merge($fields, $this->getControlDatas('actionFields')); + } + final protected function setFormFields(?array $fields = null): void + { + switch ($this->getAction()) { + case 'index': + $actionFields = $this->getService()->getIndexFields(); + break; + case 'view': + $actionFields = $this->getService()->getViewFields(); + break; + default: + $actionFields = $this->getService()->getFormFields(); + break; } - //Form용 Options정의 - foreach ($this->getControlDatas('actionFilters') as $field) { - $options = []; - foreach ($this->getFormFieldOption_process($field) as $entity) { - $options[$entity->getPK()] = $entity; - } - $this->setFormFieldOptions($field, $options); + $this->setControlDatas('actionFields', is_array($fields) ? $fields : $actionFields); + } + final protected function getFormFilters($filters = []): array + { + return array_merge($filters, $this->getControlDatas('actionFilters')); + } + final protected function setFormFilters(?array $filters = null): void + { + switch ($this->getAction()) { + case 'index': + $actionFilters = $this->getService()->getIndexFilters(); + break; + case 'view': + $actionFilters = $this->getService()->getViewFilters(); + break; + default: + $actionFilters = $this->getService()->getFormFilters(); + break; } - //일괄작업용 Fields정의 - $this->setControlDatas( - 'batchjob_fields', - array_key_exists('batchjob_fields', $actionFields) ? $actionFields['batchjob_fields'] : $this->getService()->getBatchjobFields() - ); - //일괄작업용 버튼정의 - $this->setControlDatas( - 'batchjob_buttions', - array_key_exists('batchjob_buttions', $actionFields) ? $actionFields['batchjob_buttions'] : $this->getService()->getBatchjobButtons() - ); + $this->setControlDatas('actionFilters', is_array($filters) ? $filters : $actionFilters); } //FormRules정의 - final protected function setFormFielRule($field, string $rule) + final protected function getFormRules(array $rules = []): array { - //기존 Filter Rules 가져와서 field에 해당하는 rule이 없으면 field를 filter_rules 전체 적용 - $allRules = $this->getControlDatas('field_rules') ?? []; - $allRules[$field] = $rule; - $this->setControlDatas('field_rules', $allRules); + foreach ($this->getControlDatas('field_rules') as $field => $rule) { + $rules[$field] = $rule; + } + return $rules; + } + final protected function setFormRules(): void + { + $rules = []; + foreach ($this->getControlDatas('actionFields') as $field) { + $rules = $this->getFormRule($field, $rules); + } + $this->setControlDatas('field_rules', $rules); } //FormOptions정의 - final protected function setFormFieldOptions($field, array $options) + final protected function getFormOptions(array $options = []): array + { + foreach ($this->getControlDatas('field_optons') as $field => $option) { + $options[$field] = $option; + } + return $options; + } + final protected function setFormOptions(): void { //기존 Filter Options 가져와서 field에 해당하는 option이 없으면 field를 key로 배열추가 후 다시 filter_options 전체 적용 - $allOptions = $this->getControlDatas('filter_optons') ?? []; - $allOptions[$field] = $options; - $this->setControlDatas('filter_optons', $allOptions); + $options = []; + foreach ($this->getControlDatas('actionFilters') as $field) { + $options[$field] = $this->getFormOption($field, $options); + } + $this->setControlDatas('field_optons', $options); } - //전체 FormDatas 전달값받기 - final protected function getFormDatas(array $fields, array $requestDatas, array $formDatas = []): array + //FormDatas 전달값,Default값 + final protected function getFormDatas($formDatas = []): array { - foreach ($fields as $field) { - //Post값이 null이면 formDatas에서 해당하는 default값이 있는지 확인후 넣고,없으면 최종적으로 null - $datas = $requestDatas[$field] ?? null; - if ($datas !== null) { - $formDatas[$field] = $datas; - } else { - $formDatas = $this->getFormData_process($field, $requestDatas, $formDatas); - } + foreach ($this->getControlDatas('form_datas') as $field => $value) { + $formDatas[$field] = $value; } return $formDatas; } - final protected function setFieldDefaultValue(string $field, mixed $default): void + final protected function setFormDatas(array $requestDatas, array $formDatas = []): void { - if (array_key_exists('field_default_values', $this->_control)) { - $this->_control['field_default_values'] = []; + foreach ($this->getControlDatas('actionFields') as $field) { + $formDatas = $this->getFormData($field, $requestDatas, $formDatas); } - $this->_control['field_default_values'][$field] = $default; + // echo var_dump($requestDatas); + // dd($formDatas); + $this->setControlDatas('form_datas', $formDatas); } //FormDatas 검증 - final protected function doValidation(array $formDatas): void + final protected function doValidations(): void { //변경할 값 확인 : Upload된 파일 검증시 $this->request->getPOST()보다 먼처 체크필요 $validation = service('validation'); foreach ($this->getControlDatas('field_rules') as $field => $rule) { - $validation = $this->doValidation_process($validation, $field, $rule); + $validation = $this->doValidation($validation, $field, $rule); } - if (!$validation->run($formDatas)) { + if (!$validation->run($this->getFormDatas())) { throw new \Exception("{$this->getService()->getClassName()} 작업 데이터 검증 오류발생\n" . implode( "\n", $validation->getErrors() @@ -177,309 +198,28 @@ abstract class CommonController extends BaseController } // return $validation->getValidated(); } - //생성 기본기능 - final public function create_form(): RedirectResponse|string - { - try { - //각 Field 초기화 - $this->setAction(__FUNCTION__); - //각 Field 초기화 - $this->initAction($this->getService()->getFormFields()); - $this->create_form_process(); - //actionFilters에 해당하는 값이 있을 경우 정의 - helper(['form']); - $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; - return $this->getResultSuccess_process(); - } catch (\Exception $e) { - return $this->getResultFail_process($e->getMessage()); - } - } - final public function create(): RedirectResponse|string - { - $this->_db->transStart(); - try { - //각 Field 초기화 - $this->setAction(__FUNCTION__); - //각 Field 초기화 - $this->initAction($this->getService()->getFormFields()); - //전달값받기 - $formDatas = $this->getFormDatas($this->getControlDatas('actionFields'), $this->request->getPost()); - $formDatas = $this->create_validate_process($formDatas); - $this->entity = $this->create_process($formDatas); - $this->_db->transCommit(); - return $this->getResultSuccess_process(); - } catch (\Exception $e) { - $this->_db->transRollback(); - return $this->getResultFail_process($e->getMessage()); - } - } - //수정 기본기능 - final public function modify_form(mixed $uid): RedirectResponse|string - { - try { - //각 Field 초기화 - $this->setAction(__FUNCTION__); - //각 Field 초기화 - $this->initAction($this->getService()->getFormFields()); - //기존 Entity 가져오기 - $entity = $this->getService()->getEntity($uid); - if (!$entity) { - throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); - } - $this->entity = $this->modify_form_process($entity); - helper(['form']); - $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; - return $this->getResultSuccess_process(); - } catch (\Exception $e) { - return $this->getResultFail_process($e->getMessage()); - } - } - final public function modify(int $uid): RedirectResponse|string - { - //Transaction Start - $this->_db->transStart(); - try { - //각 Field 초기화 - $this->setAction(__FUNCTION__); - //각 Field 초기화 - $this->initAction($this->getService()->getFormFields()); - //기존 Entity 가져오기 - $entity = $this->getService()->getEntity($uid); - if (!$entity) { - throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); - } - //전달값받기 - $formDatas = $this->getFormDatas($this->getControlDatas('actionFields'), $this->request->getPost()); - $formDatas = $this->modify_validate_process($formDatas); - $this->entity = $this->modify_process($entity, $formDatas); - $this->_db->transCommit(); - return $this->getResultSuccess_process(); - } catch (\Exception $e) { - $this->_db->transRollback(); - return $this->getResultFail_process($e->getMessage()); - } - } - //단일필드작업기능 - final public function toggle(mixed $uid, string $field): RedirectResponse|string - { - //Transaction Start - $this->_db->transStart(); - try { - //각 Field 초기화 - $this->setAction(__FUNCTION__); - //각 Field 초기화:조건항목 Field는 한개만 존재하므로 Field와 Rule을 정의 - $this->initAction(['fields' => [$field], 'filters' => [$field]]); - //기존 Entity 가져오기 - $entity = $this->getService()->getEntity($uid); - if (!$entity) { - throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); - } - //전달값받기 - $formDatas = $this->getFormDatas($this->getControlDatas('actionFields'), $this->request->getVar()); - $formDatas = $this->toggle_validate_process($formDatas); - // echo var_dump($this->getControlDatas()); - // dd($formDatas); - $this->entity = $this->toggle_process($entity, $formDatas); - $this->_db->transCommit(); - return $this->getResultSuccess_process(); - } catch (\Exception $e) { - $this->_db->transRollback(); - return $this->getResultFail_process($e->getMessage()); - } - } - //일괄처리작업기능 - protected function batchjob_pre_process(): array - { - $selectedFields = []; - //getBatchJobFields를 이용해서 선택된 Field 와 값정의 - $formDatas = []; - foreach ($this->getService()->getBatchjobFields() as $field) { - $value = $this->request->getPost($field); - if ($value) { - $selectedFields[] = $field; - $formDatas[$field] = $value; - } - } - if (!count($selectedFields)) { - throw new \Exception("변경할 조건항목을 선택하셔야합니다."); - } - //변경할 UIDS 정의 - $uids = $this->request->getPost('batchjob_uids[]'); - if (!is_array($uids) || !count($uids)) { - throw new \Exception("적용할 리스트을 선택하셔야합니다."); - } - return [$selectedFields, $formDatas, $uids]; - } - final public function batchjob(): RedirectResponse|string - { - //Transaction Start - $this->_db->transStart(); - try { - //각 Field 초기화 - $this->setAction(__FUNCTION__); - list($selectedFields, $formDatas, $uids) = $this->batchjob_pre_process(); - //각 Field 초기화:조건항목 Field와 Rule을 정의 - $this->initAction(['fields' => $selectedFields, 'filters' => $selectedFields]); - //전달값받기 - $formDatas = $this->getFormDatas($this->getControlDatas('actionFields'), $this->request->getPost()); - $formDatas = $this->batchjob_validate_process($formDatas); - $entities = []; - foreach ($uids as $uid) { - //기존 Entity 가져오기 - $entity = $this->getService()->getEntity($uid); - if (!$entity) { - throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); - } - $entities[] = $this->batchjob_process($entity, $formDatas); - } - $this->entities = $entities; - $this->_db->transCommit(); - LogCollector::debug(sprintf("%s에서 총 %s개중 %s개 일괄작업을 완료하였습니다.", __METHOD__, count($uids), count($this->entities))); - return $this->getResultSuccess_process(); - } catch (\Exception $e) { - $this->_db->transRollback(); - return $this->getResultFail_process($e->getMessage()); - } - } - final public function delete(mixed $uid): RedirectResponse|string - { - //Transaction Start - $this->_db->transStart(); - try { - //Action 정의:삭제는 다른 초기화 필요없음 - $this->setAction(__FUNCTION__); - //기존 Entity 가져오기 - $entity = $this->getService()->getEntity($uid); - if (!$entity) { - throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); - } - $this->delete_process($entity); - $this->_db->transCommit(); - return $this->getResultSuccess_process(); - } catch (\Exception $e) { - $this->_db->transRollback(); - return $this->getResultFail_process($e->getMessage()); - } - } - //일괄삭제 - final public function batchjob_delete(): RedirectResponse|string - { - //Transaction Start - $this->_db->transStart(); - try { - //Action 정의:삭제는 다른 초기화 필요없음 - $this->setAction(__FUNCTION__); - //변경할 UIDS - $uids = $this->request->getPost('batchjob_uids[]'); - if (!is_array($uids) || !count($uids)) { - throw new \Exception("적용할 리스트를 선택하셔야합니다."); - } - $entities = []; - foreach ($uids as $uid) { - //기존 Entity 가져오기 - $entity = $this->getService()->getEntity($uid); - if (!$entity) { - throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); - } - $entities[] = $this->batchjob_delete_process($entity); - } - $this->entities = $entities; - $this->_db->transCommit(); - LogCollector::debug(sprintf("%s에서 총 %s개중 %s개 일괄삭제를 완료하였습니다.", __METHOD__, count($uids), count($this->entities))); - return $this->getResultSuccess_process(); - } catch (\Exception $e) { - $this->_db->transRollback(); - return $this->getResultFail_process($e->getMessage()); - } - } - final public function view(string $uid): RedirectResponse|string - { - try { - //Action 정의 - //각 Field 초기화 - $this->setAction(__FUNCTION__); - //각 Field 초기화 - $this->initAction($this->getService()->getViewFields()); - //기존 Entity 가져오기 - $entity = $this->getService()->getEntity($uid); - if (!$entity) { - throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); - } - $this->entity = $this->view_process($entity); - helper(['form']); - $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; - return $this->getResultSuccess_process(); - } catch (\Exception $e) { - return $this->getResultFail_process($e->getMessage()); - } - } - //OUPUT Document 관련 - private function download_document(string $document_type, mixed $loaded_data): array - { - $full_path = WRITEPATH . DIRECTORY_SEPARATOR . "excel"; - switch ($document_type) { - case 'excel': - $file_name = sprintf("%s_%s.xlsx", $this->getService()->getClassName(), date('Y-m-d_Hm')); - $writer = IOFactory::createWriter($loaded_data, 'Xlsx'); - $writer->save($full_path . DIRECTORY_SEPARATOR . $file_name); - break; - case 'pdf': - $file_name = sprintf("%s_%s.pdf", $this->getService()->getClassName(), date('Y-m-d_Hm')); - $writer = new Mpdf($loaded_data); - $writer->save($full_path . DIRECTORY_SEPARATOR . $file_name); - break; - } - return array($full_path, $file_name); - } - // Download - final public function download(string $output_type, mixed $uid = false): DownloadResponse|RedirectResponse|string - { - try { - //각 Field 초기화 - $this->setAction(__FUNCTION__); - //각 Field 초기화 - $this->initAction($this->getService()->getIndexFields()); - //URL처리 - // $this->uri = $this->request->getUri(); - switch ($output_type) { - case 'excel': - case 'pdf': - helper(['form']); - $this->index_process(); - $html = $this->getResultSuccess_process(); - //data loading - $reader = new Html(); - $loaded_data = $reader->loadFromString($html); - list($full_path, $file_name) = $this->download_document($output_type, $loaded_data); - $full_path .= DIRECTORY_SEPARATOR . $file_name; - break; - default: - if (!$uid) { - throw new \Exception("{$output_type}은 반드시 uid의 값이 필요합니다."); - } - $entity = $this->getService()->getEntity($uid); - if (!$entity) { - throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); - } - $this->entity = $entity; - list($file_name, $uploaded_filename) = $entity->getDownlaodFile(); - $full_path = WRITEPATH . DIRECTORY_SEPARATOR . "uploads" . DIRECTORY_SEPARATOR . $uploaded_filename; - break; - } - return $this->response->download($full_path, null)->setFileName($file_name); - } catch (\Exception $e) { - return $this->getResultFail_process($e->getMessage()); - } - } - //공통 기본 기능 - - //추가 개별 처리 기능 + //공통 필수기능 //FieldForm관련용 - protected function getFormFieldOption_process(string $field, array $options = []): array + protected function getFormRule(string $field, array $rules = []): array + { + if (is_array($field)) { + throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true)); + } + switch ($field) { + default: + $rules[$field] = $this->getService()->getFormRule($this->getAction(), $field); + break; + } + if (!is_array($rules)) { + throw new \Exception(__FUNCTION__ . "에서 {$field}의 Rules 값이 array가 아닙니다.\n" . var_export($rules, true)); + } + return $rules; + } + protected function getFormOption(string $field, array $options = []): array { switch ($field) { default: - $options = $this->getService()->getFormFieldOption($field, $options); + $options = $this->getService()->getFormOption($field, $options); break; } if (!is_array($options)) { @@ -487,24 +227,17 @@ abstract class CommonController extends BaseController } return $options; } - protected function getFormFieldRule_process(string $action, string $field): string + //FormData Field별 전달값 처리 + protected function getFormData(string $field, array $requestDatas, array $formDatas): array { - if (is_array($field)) { - throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true)); - } switch ($field) { default: - $rule = $this->getService()->getFormFieldRule($action, $field); + $formDatas[$field] = $requestDatas[$field] ?? null; break; } - return $rule; - } - //FormData Field별 전달값 처리 - protected function getFormData_process(string $field, array $requestDatas, array $formDatas): array - { return $formDatas; } - protected function doValidation_process(Validation $validation, string $field, string $rule): Validation + protected function doValidation(Validation $validation, string $field, string $rule): Validation { switch ($field) { default: @@ -514,7 +247,7 @@ abstract class CommonController extends BaseController return $validation; } //Process Result처리 - protected function getResultFail_process(string $message = MESSAGES["FAILED"]): RedirectResponse + protected function getResultFail(string $message = MESSAGES["FAILED"]): RedirectResponse { LogCollector::debug($message); $this->getMyLogService()->save($this->getService()->getClassName(), $this->getAction(), $message, $this->getMyAuth()->getUIDByAuthInfo()); @@ -523,7 +256,7 @@ abstract class CommonController extends BaseController } return redirect()->to($this->getMyAuth()->popPreviousUrl())->with('error', $message); } - protected function getResultSuccess_process(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string + protected function getResultSuccess(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string { helper(['form']); switch ($this->getControlDatas('action')) { @@ -555,90 +288,294 @@ abstract class CommonController extends BaseController return $result; } //Index,FieldForm관련 - //생성관련 + //생성 기본기능 protected function create_form_process(): void {} - protected function create_validate_process(array $formDatas): array + public function create_form(): RedirectResponse|string { - $this->doValidation($formDatas); - return $formDatas; + try { + $this->setAction(__FUNCTION__); + $this->setFormFields(); + $this->setFormFilters(); + $this->setFormRules(); + $this->setFormOptions(); + //기본값정의 + $this->setFormDatas($this->request->getGet()); + $this->create_form_process(); + helper(['form']); + $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; + return $this->getResultSuccess(); + } catch (\Exception $e) { + // dd($e->getMessage()); + return $this->getResultFail($e->getMessage()); + } } protected function create_process(array $formDatas): mixed { return $this->getService()->create($formDatas); } - //수정관련 + public function create(): RedirectResponse|string + { + $db = \Config\Database::connect(); + $db->transStart(); + try { + $this->setAction(__FUNCTION__); + $this->setFormFields(); + $this->setFormFilters(); + $this->setFormRules(); + //전달값정의 + $this->setFormDatas($this->request->getPost()); + $this->doValidations(); + $this->entity = $this->create_process($this->getFormDatas()); + $db->transCommit(); + return $this->getResultSuccess(); + } catch (\Exception $e) { + $db->transRollback(); + return $this->getResultFail($e->getMessage()); + } + } + //수정 기본기능 protected function modify_form_process(mixed $entity): mixed { return $entity; } - protected function modify_validate_process(array $formDatas): array + public function modify_form(mixed $uid): RedirectResponse|string { - $this->doValidation($formDatas); - return $formDatas; + try { + $this->setAction(__FUNCTION__); + $this->setFormFields(); + $this->setFormFilters(); + $this->setFormRules(); + $this->setFormOptions(); + //기본값정의 + $this->setFormDatas($this->request->getGet()); + //기존 Entity 가져오기 + $entity = $this->getService()->getEntity($uid); + if (!$entity) { + throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); + } + $this->entity = $this->modify_form_process($uid); + helper(['form']); + $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; + return $this->getResultSuccess(); + } catch (\Exception $e) { + return $this->getResultFail($e->getMessage()); + } } protected function modify_process(mixed $entity, array $formDatas): mixed { return $this->getService()->modify($entity, $formDatas); } - //단일필드작업기능 - protected function toggle_validate_process(array $formDatas): array + public function modify(int $uid): RedirectResponse|string { - $this->doValidation($formDatas); - return $formDatas; + //Transaction Start + $db = \Config\Database::connect(); + $db->transStart(); + try { + $this->setAction(__FUNCTION__); + $this->setFormFields(); + $this->setFormFilters(); + $this->setFormRules(); + //전달값정의 + $this->setFormDatas($this->request->getPost()); + $this->doValidations(); + //기존 Entity 가져오기 + $entity = $this->getService()->getEntity($uid); + if (!$entity) { + throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); + } + $this->entity = $this->modify_process($entity, $this->getFormDatas()); + $db->transCommit(); + return $this->getResultSuccess(); + } catch (\Exception $e) { + $db->transRollback(); + return $this->getResultFail($e->getMessage()); + } } + //단일필드작업기능 protected function toggle_process(mixed $entity, array $formDatas): mixed { return $this->getService()->modify($entity, $formDatas); } - //일괄처리작업기능 - protected function batchjob_validate_process(array $formDatas): array + public function toggle(mixed $uid, string $field): RedirectResponse|string { - $this->doValidation($formDatas); - return $formDatas; + //Transaction Start + $db = \Config\Database::connect(); + $db->transStart(); + try { + $this->setAction(__FUNCTION__); + $this->setFormFields([$field]); + $this->setFormFilters([$field]); + $this->setFormRules(); + //기본값정의 + $this->setFormDatas($this->request->getGet()); + //기존 Entity 가져오기 + $entity = $this->getService()->getEntity($uid); + if (!$entity) { + throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); + } + $this->entity = $this->toggle_process($entity, $this->getFormDatas()); + $db->transCommit(); + return $this->getResultSuccess(); + } catch (\Exception $e) { + $db->transRollback(); + return $this->getResultFail($e->getMessage()); + } } - protected function batchjob_process($entity, array $formDatas): mixed + //일괄처리작업기능 + protected function batchjob_process(mixed $entity, array $formDatas): mixed { return $this->getService()->modify($entity, $formDatas); } + protected function batchjob_pre_process(): array + { + $selectedFields = []; + //getBatchJobFields를 이용해서 선택된 Field 와 값정의 + $formDatas = []; + foreach ($this->getService()->getBatchjobFields() as $field) { + $value = $this->request->getPost($field); + if ($value) { + $selectedFields[] = $field; + $formDatas[$field] = $value; + } + } + if (!count($selectedFields)) { + throw new \Exception("변경할 조건항목을 선택하셔야합니다."); + } + //변경할 UIDS 정의 + $uids = $this->request->getPost('batchjob_uids[]'); + if (!is_array($uids) || !count($uids)) { + throw new \Exception("적용할 리스트을 선택하셔야합니다."); + } + return [$selectedFields, $formDatas, $uids]; + } + public function batchjob(): RedirectResponse|string + { + //Transaction Start + $db = \Config\Database::connect(); + $db->transStart(); + try { + $this->setAction(__FUNCTION__); + list($selectedFields, $formDatas, $uids) = $this->batchjob_pre_process(); + $this->setFormFields($selectedFields); + $this->setFormFilters($selectedFields); + $this->setFormRules(); + //기본값정의 + $this->setFormDatas($this->request->getGet()); + $entities = []; + foreach ($uids as $uid) { + //기존 Entity 가져오기 + $entity = $this->getService()->getEntity($uid); + if (!$entity) { + throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); + } + $entities[] = $this->batchjob_process($entity, $formDatas); + } + $this->entities = $entities; + $db->transCommit(); + LogCollector::debug(sprintf("%s에서 총 %s개중 %s개 일괄작업을 완료하였습니다.", __METHOD__, count($uids), count($this->entities))); + return $this->getResultSuccess(); + } catch (\Exception $e) { + $db->transRollback(); + return $this->getResultFail($e->getMessage()); + } + } //삭제관련 protected function delete_process(mixed $entity): mixed { return $this->getService()->delete($entity); } + public function delete(mixed $uid): RedirectResponse|string + { + //Transaction Start + $db = \Config\Database::connect(); + $db->transStart(); + try { + $this->setAction(__FUNCTION__); + //기존 Entity 가져오기 + $entity = $this->getService()->getEntity($uid); + if (!$entity) { + throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); + } + $this->delete_process($entity); + $db->transCommit(); + return $this->getResultSuccess(); + } catch (\Exception $e) { + $db->transRollback(); + return $this->getResultFail($e->getMessage()); + } + } //일괄삭제관련 - protected function batchjob_delete_process(mixed $entity, array $entities = []): mixed + protected function batchjob_delete_process(mixed $entity): mixed { return $this->getService()->delete($entity); } + protected function batchjob_delete_pre_process(): array + { + //변경할 UIDS + $uids = $this->request->getPost('batchjob_uids[]'); + if (!is_array($uids) || !count($uids)) { + throw new \Exception("적용할 리스트를 선택하셔야합니다."); + } + return $uids; + } + public function batchjob_delete(): RedirectResponse|string + { + //Transaction Start + $db = \Config\Database::connect(); + $db->transStart(); + try { + $this->setAction(__FUNCTION__); + $uids = $this->batchjob_delete_pre_process(); + $entities = []; + foreach ($uids as $uid) { + //기존 Entity 가져오기 + $entity = $this->getService()->getEntity($uid); + if (!$entity) { + throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); + } + $entities[] = $this->batchjob_delete_process($entity); + } + $this->entities = $entities; + $db->transCommit(); + LogCollector::debug(sprintf("%s에서 총 %s개중 %s개 일괄삭제를 완료하였습니다.", __METHOD__, count($uids), count($this->entities))); + return $this->getResultSuccess(); + } catch (\Exception $e) { + $db->transRollback(); + return $this->getResultFail($e->getMessage()); + } + } //View 관련 protected function view_process(mixed $entity): mixed { return $entity; } + public function view(string $uid): RedirectResponse|string + { + try { + $this->setAction(__FUNCTION__); + $this->setFormFields(); + $this->setFormFilters(); + $this->setFormRules(); + $this->setFormOptions(); + //기본값정의 + $this->setFormDatas($this->request->getGet()); + //기존 Entity 가져오기 + $entity = $this->getService()->getEntity($uid); + if (!$entity) { + throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); + } + $this->entity = $this->view_process($entity); + helper(['form']); + $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; + return $this->getResultSuccess(); + } catch (\Exception $e) { + return $this->getResultFail($e->getMessage()); + } + } //리스트관련 //조건절 처리 - //Filter Field별 전달값 처리 - protected function index_condition_filterfield_process(string $field, $filter_values = []): array - { - switch ($field) { - default: - $filter_value = $this->request->getVar($field); - if ($filter_value !== null && $filter_value !== '') { - $this->getService()->index_condition_filterField($field, $filter_value); - $filter_values[$field] = $filter_value; - } - break; - } - return $filter_values; - } protected function index_condition_process(): void { - //Paramter로 전달된 Filter값을 정의용 - $filter_values = []; - foreach ($this->getControlDatas('actionFilters') as $field) { - $filter_values = $this->index_condition_filterfield_process($field, $filter_values); - } - $this->setControlDatas('filter_values', $filter_values); //검색어조건절 처리 $this->word = $this->request->getVar('word'); if ($this->word !== null && $this->word !== '') { @@ -687,10 +624,17 @@ abstract class CommonController extends BaseController public function index(): RedirectResponse|string { try { - //각 Field 초기화 $this->setAction(__FUNCTION__); - //각 Field 초기화 - $this->initAction($this->getService()->getIndexFields()); + $this->setFormFields(); + $this->setFormFilters(); + $this->setFormRules(); + //기본값정의 + $this->setFormDatas($this->request->getGet()); + $this->setFormOptions(); + //일괄작업용 Fields정의 + $this->setControlDatas('batchjob_fields', $this->getService()->getBatchjobFields()); + //일괄작업용 버튼정의 + $this->setControlDatas('batchjob_buttions', $this->getService()->getBatchjobButtons()); helper(['form']); //Return Url정의 $this->getMyAuth()->pushCurrentUrl($this->request->getUri()->getPath() . ($this->request->getUri()->getQuery() ? "?" . $this->request->getUri()->getQuery() : "")); @@ -711,10 +655,69 @@ abstract class CommonController extends BaseController $this->getService()->setOffset(($this->page - 1) * $this->per_page); $this->index_condition_process(); $this->entities = $this->index_process(); - return $this->getResultSuccess_process(); + return $this->getResultSuccess(); } catch (\Exception $e) { return $e->getMessage(); - // return $this->getResultFail_process($e->getMessage()); + // return $this->getResultFail($e->getMessage()); + } + } + //OUPUT Document 관련 + private function download_process(string $document_type, mixed $loaded_data): array + { + $full_path = WRITEPATH . DIRECTORY_SEPARATOR . "excel"; + switch ($document_type) { + case 'excel': + $file_name = sprintf("%s_%s.xlsx", $this->getService()->getClassName(), date('Y-m-d_Hm')); + $writer = IOFactory::createWriter($loaded_data, 'Xlsx'); + $writer->save($full_path . DIRECTORY_SEPARATOR . $file_name); + break; + case 'pdf': + $file_name = sprintf("%s_%s.pdf", $this->getService()->getClassName(), date('Y-m-d_Hm')); + $writer = new Mpdf($loaded_data); + $writer->save($full_path . DIRECTORY_SEPARATOR . $file_name); + break; + } + return array($full_path, $file_name); + } + // Download + public function download(string $output_type, mixed $uid = false): DownloadResponse|RedirectResponse|string + { + try { + $this->setAction(__FUNCTION__); + $this->setFormFields(); + $this->setFormFilters(); + $this->setFormRules(); + $this->setFormOptions(); + //URL처리 + // $this->uri = $this->request->getUri(); + switch ($output_type) { + case 'excel': + case 'pdf': + helper(['form']); + $this->index_process(); + $html = $this->getResultSuccess(); + //data loading + $reader = new Html(); + $loaded_data = $reader->loadFromString($html); + list($full_path, $file_name) = $this->download_process($output_type, $loaded_data); + $full_path .= DIRECTORY_SEPARATOR . $file_name; + break; + default: + if (!$uid) { + throw new \Exception("{$output_type}은 반드시 uid의 값이 필요합니다."); + } + $entity = $this->getService()->getEntity($uid); + if (!$entity) { + throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); + } + $this->entity = $entity; + list($file_name, $uploaded_filename) = $entity->getDownlaodFile(); + $full_path = WRITEPATH . DIRECTORY_SEPARATOR . "uploads" . DIRECTORY_SEPARATOR . $uploaded_filename; + break; + } + return $this->response->download($full_path, null)->setFileName($file_name); + } catch (\Exception $e) { + return $this->getResultFail($e->getMessage()); } } } diff --git a/app/Helpers/CommonHelper.php b/app/Helpers/CommonHelper.php index 3783415..7bacb17 100644 --- a/app/Helpers/CommonHelper.php +++ b/app/Helpers/CommonHelper.php @@ -217,13 +217,13 @@ class CommonHelper $extra .= sprintf(" %s=\"%s\"", $extra_tag, htmlspecialchars($extra_value, ENT_QUOTES, 'UTF-8')); } // 필터 옵션이 없으면 빈 배열로 초기화 - if (!array_key_exists($field, $viewDatas['control']['filter_optons'])) { + if (!array_key_exists($field, $viewDatas['control']['field_optons'])) { return $field; // 필터 옵션이 없으면 빈 문자열 반환 } // $formOptions는 필터 옵션 배열로, key는 필터 엔티티의 PK, value는 필터 엔티티 객체 $html = sprintf("