diff --git a/app/Controllers/AbstractCRUDController.php b/app/Controllers/AbstractCRUDController.php index 9b1f26b..37c7270 100644 --- a/app/Controllers/AbstractCRUDController.php +++ b/app/Controllers/AbstractCRUDController.php @@ -25,18 +25,6 @@ abstract class AbstractCRUDController extends AbstractWebController return $this->action_render_process($this->getActionPaths(), $action, $this->getViewDatas()); } - final public function create_form(): string|RedirectResponse - { - try { - $action = __FUNCTION__; - $this->action_init_process($action); - $this->addViewDatas('formDatas', $this->create_form_process()); - return $this->create_form_result_process($action); - } catch (\Exception $e) { - return $this->action_redirect_process('error', "{$this->getTitle()}에서 생성폼 오류:" . $e->getMessage()); - } - } - protected function create_process(): CommonEntity { // POST 데이터를 DTO 객체로 변환 (getPost()는 POST 요청 본문만 가져옵니다.) @@ -49,20 +37,7 @@ abstract class AbstractCRUDController extends AbstractWebController return $this->action_modal_process("{$this->getTitle()}에서 {$entity->getTitle()} 생성이 완료되었습니다."); } - final public function create(): string|RedirectResponse - { - try { - $this->action_init_process(__FUNCTION__); - return $this->create_result_process($this->create_process()); - } catch (ValidationException $e) { - return $this->action_redirect_process('error', "{$this->getTitle()}에서 생성 검증오류:" . $e->getMessage()); - } catch (\Exception $e) { - return $this->action_redirect_process('error', "{$this->getTitle()}에서 생성 오류:" . $e->getMessage()); - } - } - // --- 수정 (Modify) --- - protected function modify_form_process($uid): CommonEntity { if (!$uid) { @@ -80,18 +55,6 @@ abstract class AbstractCRUDController extends AbstractWebController return $this->action_render_process($this->getActionPaths(), $action, $this->getViewDatas()); } - final public function modify_form($uid): string|RedirectResponse - { - try { - $action = __FUNCTION__; - $this->action_init_process($action); - $this->addViewDatas('entity', $this->modify_form_process($uid)); - return $this->modify_form_result_process($action); - } catch (\Exception $e) { - return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 수정폼 오류:" . $e->getMessage()); - } - } - protected function modify_process($uid): CommonEntity { // POST 데이터를 DTO 객체로 변환 @@ -104,18 +67,6 @@ abstract class AbstractCRUDController extends AbstractWebController return $this->action_modal_process("{$this->getTitle()}에서 {$entity->getTitle()} 수정이 완료되었습니다."); } - final public function modify($uid): string|RedirectResponse - { - try { - $this->action_init_process(__FUNCTION__); - return $this->modify_result_process($this->modify_process($uid)); - } catch (ValidationException $e) { - return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 수정 검증오류:" . $e->getMessage()); - } catch (\Exception $e) { - return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 수정 오류:" . $e->getMessage()); - } - } - // --- 삭제 (Delete) --- protected function delete_process($uid): CommonEntity @@ -128,15 +79,6 @@ abstract class AbstractCRUDController extends AbstractWebController return $this->action_redirect_process('info', "{$this->getTitle()}에서 {$entity->getTitle()} 삭제가 완료되었습니다."); } - final public function delete($uid): RedirectResponse - { - try { - return $this->delete_result_process($this->delete_process($uid)); - } catch (\Exception $e) { - return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 삭제 오류:" . $e->getMessage()); - } - } - // --- 상세보기 (View) --- protected function view_process($uid): CommonEntity @@ -155,16 +97,4 @@ abstract class AbstractCRUDController extends AbstractWebController { return $this->action_render_process($this->getActionPaths(), $action, $this->getViewDatas()); } - - final public function view($uid): string|RedirectResponse - { - try { - $action = __FUNCTION__; - $this->action_init_process($action); - $this->addViewDatas('entity', $this->view_process($uid)); - return $this->view_result_process($action); - } catch (\Exception $e) { - return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 상세보기 오류:" . $e->getMessage()); - } - } } diff --git a/app/Controllers/Admin/CollectorController.php b/app/Controllers/Admin/CollectorController.php index a309bbd..e27ba92 100644 --- a/app/Controllers/Admin/CollectorController.php +++ b/app/Controllers/Admin/CollectorController.php @@ -3,8 +3,11 @@ namespace App\Controllers\Admin; use App\Entities\CollectorEntity; +use CodeIgniter\HTTP\DownloadResponse; +use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; +use CodeIgniter\Validation\Exceptions\ValidationException; use Psr\Log\LoggerInterface; class CollectorController extends AdminController @@ -50,60 +53,163 @@ class CollectorController extends AdminController $this->service->getFormService()->setBatchjobButtons($batchjobButtons); parent::action_init_process($action); } - protected function create_process(): CollectorEntity + public function create_form(): string|RedirectResponse { - $entity = parent::create_process(); - if (!$entity instanceof CollectorEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 CollectorEntity만 가능"); + try { + $action = __FUNCTION__; + $this->action_init_process($action); + $this->addViewDatas('formDatas', $this->create_form_process()); + return $this->create_form_result_process($action); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 생성폼 오류:" . $e->getMessage()); } - return $entity; } - protected function modify_form_process($uid): CollectorEntity + public function create(): string|RedirectResponse { - $entity = parent::modify_form_process($uid); - if (!$entity instanceof CollectorEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 CollectorEntity만 가능"); + try { + $action = __FUNCTION__; + $this->action_init_process($action); + $entity = $this->create_process(); + if (!$entity instanceof CollectorEntity) { + throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 CollectorEntity만 가능"); + } + return $this->create_result_process($entity); + } catch (ValidationException $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 생성 검증오류:" . $e->getMessage()); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 생성 오류:" . $e->getMessage()); } - return $entity; } - protected function modify_process($uid): CollectorEntity + public function modify_form($uid): string|RedirectResponse { - $entity = parent::modify_process($uid); - if (!$entity instanceof CollectorEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 CollectorEntity만 가능"); + try { + $action = __FUNCTION__; + $this->action_init_process($action); + $entity = $this->modify_form_process($uid); + if (!$entity instanceof CollectorEntity) { + throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 CollectorEntity만 가능"); + } + $this->addViewDatas('entity', $entity); + return $this->modify_form_result_process($action); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 수정폼 오류:" . $e->getMessage()); } - return $entity; } - protected function delete_process($uid): CollectorEntity + public function modify($uid): string|RedirectResponse { - $entity = parent::delete_process($uid); - if (!$entity instanceof CollectorEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 CollectorEntity만 가능"); + try { + $action = __FUNCTION__; + $this->action_init_process($action); + $entity = $this->modify_process($uid); + if (!$entity instanceof CollectorEntity) { + throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 CollectorEntity만 가능"); + } + $this->addViewDatas('entity', $entity); + return $this->modify_result_process($entity); + } catch (ValidationException $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 수정 검증오류:" . $e->getMessage()); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 수정 오류:" . $e->getMessage()); } - return $entity; } - protected function view_process($uid): CollectorEntity + public function delete($uid): RedirectResponse { - $entity = parent::view_process($uid); - if (!$entity instanceof CollectorEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 CollectorEntity만 가능"); + try { + $entity = $this->delete_process($uid); + if (!$entity instanceof CollectorEntity) { + throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 CollectorEntity만 가능"); + } + return $this->delete_result_process($entity); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 삭제 오류:" . $e->getMessage()); } - return $entity; } - protected function batchjob_process($uid, array $formDatas): CollectorEntity + public function view($uid): string|RedirectResponse { - $entity = parent::batchjob_process($uid, $formDatas); - if (!$entity instanceof CollectorEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 CollectorEntity만 가능"); + try { + $action = __FUNCTION__; + $this->action_init_process($action); + $entity = $this->view_process($uid); + if (!$entity instanceof CollectorEntity) { + throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 CollectorEntity만 가능"); + } + $this->addViewDatas('entity', $entity); + return $this->view_result_process($action); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 상세보기 오류:" . $e->getMessage()); } - return $entity; } - protected function batchjob_delete_process($uid): CollectorEntity + public function batchjob(): string|RedirectResponse { - $entity = $this->service->delete($uid); - if (!$entity instanceof CollectorEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 CollectorEntity만 가능"); + try { + // 사전작업 및 데이터 추출 초기화 + list($uids, $selectedFields, $formDatas) = $this->batchjob_pre_process(); + $this->service->getFormService()->setFormFields($selectedFields); + $this->service->getFormService()->setFormRules(__FUNCTION__, $selectedFields); + $this->service->getFormService()->setFormFilters($selectedFields); + $this->service->getFormService()->setFormOptions($selectedFields); + $entities = []; + $errors = []; + foreach ($uids as $uid) { + try { + $entities[] = $this->batchjob_process($uid, $formDatas); + } catch (ValidationException $e) { + log_message('error', "{$this->getTitle()}에서 {$uid} 수정 검증오류:" . $e->getMessage()); + $errors[] = $e->getMessage(); + } catch (\Exception $e) { + log_message('error', "{$this->getTitle()}에서 {$uid} 수정 오류:" . $e->getMessage()); + $errors[] = $e->getMessage(); + } + } + return $this->batchjob_result_process($uids, $entities, $errors); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 일괄작업처리 오류:" . $e->getMessage()); } - return $entity; } + + public function batchjob_delete(): string|RedirectResponse + { + try { + $uids = $this->batchjob_delete_pre_process(); + $entities = []; + $errors = []; + foreach ($uids as $uid) { + try { + $entities[] = $this->batchjob_delete_process($uid); + } catch (\Exception $e) { + log_message('error', "{$this->getTitle()}에서 {$uid} 삭제 오류:" . $e->getMessage()); + $errors[] = $e->getMessage(); + } + } + return $this->batchjob_delete_result_process($uids, $entities, $errors); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 일괄삭제 오류:" . $e->getMessage()); + } + } + + public function index(): string|ResponseInterface + { + try { + $action = __FUNCTION__; + $this->action_init_process($action); + $this->index_process($action); + $this->index_result_process($action); + } catch (\Exception $e) { + session()->setFlashdata('message', $e->getMessage()); + } + return $this->index_result_process($action); + } + + public function download(string $output_type, mixed $uid = false): DownloadResponse|RedirectResponse|string + { + try { + $action = __FUNCTION__; + $this->action_init_process($action); + return $this->download_process($action, $output_type, $uid); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 오류:" . $e->getMessage()); + } + } + //기본 함수 작업 + //Custom 추가 함수 } diff --git a/app/Controllers/Admin/MylogController.php b/app/Controllers/Admin/MylogController.php index 3be9674..32faa8b 100644 --- a/app/Controllers/Admin/MylogController.php +++ b/app/Controllers/Admin/MylogController.php @@ -3,8 +3,11 @@ namespace App\Controllers\Admin; use App\Entities\MylogEntity; +use CodeIgniter\HTTP\DownloadResponse; +use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; +use CodeIgniter\Validation\Exceptions\ValidationException; use Psr\Log\LoggerInterface; class MylogController extends AdminController @@ -46,60 +49,163 @@ class MylogController extends AdminController $this->service->getFormService()->setBatchjobFilters($batchjobFilters); parent::action_init_process($action); } - protected function create_process(): MylogEntity + public function create_form(): string|RedirectResponse { - $entity = parent::create_process(); - if (!$entity instanceof MylogEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 MylogEntity만 가능"); + try { + $action = __FUNCTION__; + $this->action_init_process($action); + $this->addViewDatas('formDatas', $this->create_form_process()); + return $this->create_form_result_process($action); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 생성폼 오류:" . $e->getMessage()); } - return $entity; } - protected function modify_form_process($uid): MylogEntity + public function create(): string|RedirectResponse { - $entity = parent::modify_form_process($uid); - if (!$entity instanceof MylogEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 MylogEntity만 가능"); + try { + $action = __FUNCTION__; + $this->action_init_process($action); + $entity = $this->create_process(); + if (!$entity instanceof MylogEntity) { + throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 MylogEntity만 가능"); + } + return $this->create_result_process($entity); + } catch (ValidationException $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 생성 검증오류:" . $e->getMessage()); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 생성 오류:" . $e->getMessage()); } - return $entity; } - protected function modify_process($uid): MylogEntity + public function modify_form($uid): string|RedirectResponse { - $entity = parent::modify_process($uid); - if (!$entity instanceof MylogEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 MylogEntity만 가능"); + try { + $action = __FUNCTION__; + $this->action_init_process($action); + $entity = $this->modify_form_process($uid); + if (!$entity instanceof MylogEntity) { + throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 MylogEntity만 가능"); + } + $this->addViewDatas('entity', $entity); + return $this->modify_form_result_process($action); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 수정폼 오류:" . $e->getMessage()); } - return $entity; } - protected function delete_process($uid): MylogEntity + public function modify($uid): string|RedirectResponse { - $entity = parent::delete_process($uid); - if (!$entity instanceof MylogEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 MylogEntity만 가능"); + try { + $action = __FUNCTION__; + $this->action_init_process($action); + $entity = $this->modify_process($uid); + if (!$entity instanceof MylogEntity) { + throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 MylogEntity만 가능"); + } + $this->addViewDatas('entity', $entity); + return $this->modify_result_process($entity); + } catch (ValidationException $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 수정 검증오류:" . $e->getMessage()); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 수정 오류:" . $e->getMessage()); } - return $entity; } - protected function view_process($uid): MylogEntity + public function delete($uid): RedirectResponse { - $entity = parent::view_process($uid); - if (!$entity instanceof MylogEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 MylogEntity만 가능"); + try { + $entity = $this->delete_process($uid); + if (!$entity instanceof MylogEntity) { + throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 MylogEntity만 가능"); + } + return $this->delete_result_process($entity); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 삭제 오류:" . $e->getMessage()); } - return $entity; } - protected function batchjob_process($uid, array $formDatas): MylogEntity + public function view($uid): string|RedirectResponse { - $entity = parent::batchjob_process($uid, $formDatas); - if (!$entity instanceof MylogEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 MylogEntity만 가능"); + try { + $action = __FUNCTION__; + $this->action_init_process($action); + $entity = $this->view_process($uid); + if (!$entity instanceof MylogEntity) { + throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 MylogEntity만 가능"); + } + $this->addViewDatas('entity', $entity); + return $this->view_result_process($action); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 상세보기 오류:" . $e->getMessage()); } - return $entity; } - protected function batchjob_delete_process($uid): MylogEntity + public function batchjob(): string|RedirectResponse { - $entity = $this->service->delete($uid); - if (!$entity instanceof MylogEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 MylogEntity만 가능"); + try { + // 사전작업 및 데이터 추출 초기화 + list($uids, $selectedFields, $formDatas) = $this->batchjob_pre_process(); + $this->service->getFormService()->setFormFields($selectedFields); + $this->service->getFormService()->setFormRules(__FUNCTION__, $selectedFields); + $this->service->getFormService()->setFormFilters($selectedFields); + $this->service->getFormService()->setFormOptions($selectedFields); + $entities = []; + $errors = []; + foreach ($uids as $uid) { + try { + $entities[] = $this->batchjob_process($uid, $formDatas); + } catch (ValidationException $e) { + log_message('error', "{$this->getTitle()}에서 {$uid} 수정 검증오류:" . $e->getMessage()); + $errors[] = $e->getMessage(); + } catch (\Exception $e) { + log_message('error', "{$this->getTitle()}에서 {$uid} 수정 오류:" . $e->getMessage()); + $errors[] = $e->getMessage(); + } + } + return $this->batchjob_result_process($uids, $entities, $errors); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 일괄작업처리 오류:" . $e->getMessage()); } - return $entity; } + + public function batchjob_delete(): string|RedirectResponse + { + try { + $uids = $this->batchjob_delete_pre_process(); + $entities = []; + $errors = []; + foreach ($uids as $uid) { + try { + $entities[] = $this->batchjob_delete_process($uid); + } catch (\Exception $e) { + log_message('error', "{$this->getTitle()}에서 {$uid} 삭제 오류:" . $e->getMessage()); + $errors[] = $e->getMessage(); + } + } + return $this->batchjob_delete_result_process($uids, $entities, $errors); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 일괄삭제 오류:" . $e->getMessage()); + } + } + + public function index(): string|ResponseInterface + { + try { + $action = __FUNCTION__; + $this->action_init_process($action); + $this->index_process($action); + $this->index_result_process($action); + } catch (\Exception $e) { + session()->setFlashdata('message', $e->getMessage()); + } + return $this->index_result_process($action); + } + + public function download(string $output_type, mixed $uid = false): DownloadResponse|RedirectResponse|string + { + try { + $action = __FUNCTION__; + $this->action_init_process($action); + return $this->download_process($action, $output_type, $uid); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 오류:" . $e->getMessage()); + } + } + //기본 함수 작업 + //Custom 추가 함수 } diff --git a/app/Controllers/Admin/TrafficController.php b/app/Controllers/Admin/TrafficController.php index 92ef54f..62e03e3 100644 --- a/app/Controllers/Admin/TrafficController.php +++ b/app/Controllers/Admin/TrafficController.php @@ -3,8 +3,11 @@ namespace App\Controllers\Admin; use App\Entities\TrafficEntity; +use CodeIgniter\HTTP\DownloadResponse; +use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; +use CodeIgniter\Validation\Exceptions\ValidationException; use Psr\Log\LoggerInterface; class TrafficController extends AdminController @@ -47,62 +50,166 @@ class TrafficController extends AdminController $this->service->getFormService()->setActionButtons($actionButtons); parent::action_init_process($action); } - protected function create_process(): TrafficEntity + public function create_form(): string|RedirectResponse { - $entity = parent::create_process(); - if (!$entity instanceof TrafficEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 TrafficEntity만 가능"); + try { + $action = __FUNCTION__; + $this->action_init_process($action); + $this->addViewDatas('formDatas', $this->create_form_process()); + return $this->create_form_result_process($action); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 생성폼 오류:" . $e->getMessage()); } - return $entity; } - protected function modify_form_process($uid): TrafficEntity + public function create(): string|RedirectResponse { - $entity = parent::modify_form_process($uid); - if (!$entity instanceof TrafficEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 TrafficEntity만 가능"); + try { + $action = __FUNCTION__; + $this->action_init_process($action); + $entity = $this->create_process(); + if (!$entity instanceof TrafficEntity) { + throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 TrafficEntity만 가능"); + } + return $this->create_result_process($entity); + } catch (ValidationException $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 생성 검증오류:" . $e->getMessage()); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 생성 오류:" . $e->getMessage()); } - return $entity; } - protected function modify_process($uid): TrafficEntity + public function modify_form($uid): string|RedirectResponse { - $entity = parent::modify_process($uid); - if (!$entity instanceof TrafficEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 TrafficEntity만 가능"); + try { + $action = __FUNCTION__; + $this->action_init_process($action); + $entity = $this->modify_form_process($uid); + if (!$entity instanceof TrafficEntity) { + throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 TrafficEntity만 가능"); + } + $this->addViewDatas('entity', $entity); + return $this->modify_form_result_process($action); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 수정폼 오류:" . $e->getMessage()); } - return $entity; } - protected function delete_process($uid): TrafficEntity + public function modify($uid): string|RedirectResponse { - $entity = parent::delete_process($uid); - if (!$entity instanceof TrafficEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 TrafficEntity만 가능"); + try { + $action = __FUNCTION__; + $this->action_init_process($action); + $entity = $this->modify_process($uid); + if (!$entity instanceof TrafficEntity) { + throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 TrafficEntity만 가능"); + } + $this->addViewDatas('entity', $entity); + return $this->modify_result_process($entity); + } catch (ValidationException $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 수정 검증오류:" . $e->getMessage()); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 수정 오류:" . $e->getMessage()); } - return $entity; } - protected function view_process($uid): TrafficEntity + public function delete($uid): RedirectResponse { - $entity = parent::view_process($uid); - if (!$entity instanceof TrafficEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 TrafficEntity만 가능"); + try { + $entity = $this->delete_process($uid); + if (!$entity instanceof TrafficEntity) { + throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 TrafficEntity만 가능"); + } + return $this->delete_result_process($entity); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 삭제 오류:" . $e->getMessage()); } - return $entity; } - protected function batchjob_process($uid, array $formDatas): TrafficEntity + public function view($uid): string|RedirectResponse { - $entity = parent::batchjob_process($uid, $formDatas); - if (!$entity instanceof TrafficEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 TrafficEntity만 가능"); + try { + $action = __FUNCTION__; + $this->action_init_process($action); + $entity = $this->view_process($uid); + if (!$entity instanceof TrafficEntity) { + throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 TrafficEntity만 가능"); + } + $this->addViewDatas('entity', $entity); + return $this->view_result_process($action); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 상세보기 오류:" . $e->getMessage()); } - return $entity; } - protected function batchjob_delete_process($uid): TrafficEntity + public function batchjob(): string|RedirectResponse { - $entity = $this->service->delete($uid); - if (!$entity instanceof TrafficEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 TrafficEntity만 가능"); + try { + // 사전작업 및 데이터 추출 초기화 + list($uids, $selectedFields, $formDatas) = $this->batchjob_pre_process(); + $this->service->getFormService()->setFormFields($selectedFields); + $this->service->getFormService()->setFormRules(__FUNCTION__, $selectedFields); + $this->service->getFormService()->setFormFilters($selectedFields); + $this->service->getFormService()->setFormOptions($selectedFields); + $entities = []; + $errors = []; + foreach ($uids as $uid) { + try { + $entities[] = $this->batchjob_process($uid, $formDatas); + } catch (ValidationException $e) { + log_message('error', "{$this->getTitle()}에서 {$uid} 수정 검증오류:" . $e->getMessage()); + $errors[] = $e->getMessage(); + } catch (\Exception $e) { + log_message('error', "{$this->getTitle()}에서 {$uid} 수정 오류:" . $e->getMessage()); + $errors[] = $e->getMessage(); + } + } + return $this->batchjob_result_process($uids, $entities, $errors); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 일괄작업처리 오류:" . $e->getMessage()); } - return $entity; } + + public function batchjob_delete(): string|RedirectResponse + { + try { + $uids = $this->batchjob_delete_pre_process(); + $entities = []; + $errors = []; + foreach ($uids as $uid) { + try { + $entities[] = $this->batchjob_delete_process($uid); + } catch (\Exception $e) { + log_message('error', "{$this->getTitle()}에서 {$uid} 삭제 오류:" . $e->getMessage()); + $errors[] = $e->getMessage(); + } + } + return $this->batchjob_delete_result_process($uids, $entities, $errors); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 일괄삭제 오류:" . $e->getMessage()); + } + } + + public function index(): string|ResponseInterface + { + try { + $action = __FUNCTION__; + $this->action_init_process($action); + $this->index_process($action); + $this->index_result_process($action); + } catch (\Exception $e) { + session()->setFlashdata('message', $e->getMessage()); + } + return $this->index_result_process($action); + } + + public function download(string $output_type, mixed $uid = false): DownloadResponse|RedirectResponse|string + { + try { + $action = __FUNCTION__; + $this->action_init_process($action); + return $this->download_process($action, $output_type, $uid); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 오류:" . $e->getMessage()); + } + } + //기본 함수 작업 + + //Custom 추가 함수 public function dashboard($uid): string { $entity = $this->service->getEntity($uid); diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php index 8026205..2732f32 100644 --- a/app/Controllers/Admin/UserController.php +++ b/app/Controllers/Admin/UserController.php @@ -3,8 +3,11 @@ namespace App\Controllers\Admin; use App\Entities\UserEntity; +use CodeIgniter\HTTP\DownloadResponse; +use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; +use CodeIgniter\Validation\Exceptions\ValidationException; use Psr\Log\LoggerInterface; class UserController extends AdminController @@ -19,8 +22,8 @@ class UserController extends AdminController //Action작업관련 protected function action_init_process(string $action): void { - $fields = ['id', 'passwd', 'confirmpassword', 'name', 'email', 'mobile', 'role']; - $filters = ['role', 'status']; + $fields = ['id', 'passwd', 'confirmpassword', 'name', 'email', 'mobile', 'role']; + $filters = ['role', 'status']; $batchjobFilters = ['status']; switch ($action) { case 'create': @@ -48,60 +51,163 @@ class UserController extends AdminController $this->service->getFormService()->setBatchjobFilters($batchjobFilters); parent::action_init_process($action); } - protected function create_process(): UserEntity + public function create_form(): string|RedirectResponse { - $entity = parent::create_process(); - if (!$entity instanceof UserEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 UserEntity만 가능"); + try { + $action = __FUNCTION__; + $this->action_init_process($action); + $this->addViewDatas('formDatas', $this->create_form_process()); + return $this->create_form_result_process($action); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 생성폼 오류:" . $e->getMessage()); } - return $entity; } - protected function modify_form_process($uid): UserEntity + public function create(): string|RedirectResponse { - $entity = parent::modify_form_process($uid); - if (!$entity instanceof UserEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 UserEntity만 가능"); + try { + $action = __FUNCTION__; + $this->action_init_process($action); + $entity = $this->create_process(); + if (!$entity instanceof UserEntity) { + throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 UserEntity만 가능"); + } + return $this->create_result_process($entity); + } catch (ValidationException $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 생성 검증오류:" . $e->getMessage()); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 생성 오류:" . $e->getMessage()); } - return $entity; } - protected function modify_process($uid): UserEntity + public function modify_form($uid): string|RedirectResponse { - $entity = parent::modify_process($uid); - if (!$entity instanceof UserEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 UserEntity만 가능"); + try { + $action = __FUNCTION__; + $this->action_init_process($action); + $entity = $this->modify_form_process($uid); + if (!$entity instanceof UserEntity) { + throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 UserEntity만 가능"); + } + $this->addViewDatas('entity', $entity); + return $this->modify_form_result_process($action); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 수정폼 오류:" . $e->getMessage()); } - return $entity; } - protected function delete_process($uid): UserEntity + public function modify($uid): string|RedirectResponse { - $entity = parent::delete_process($uid); - if (!$entity instanceof UserEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 UserEntity만 가능"); + try { + $action = __FUNCTION__; + $this->action_init_process($action); + $entity = $this->modify_process($uid); + if (!$entity instanceof UserEntity) { + throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 UserEntity만 가능"); + } + $this->addViewDatas('entity', $entity); + return $this->modify_result_process($entity); + } catch (ValidationException $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 수정 검증오류:" . $e->getMessage()); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 수정 오류:" . $e->getMessage()); } - return $entity; } - protected function view_process($uid): UserEntity + public function delete($uid): RedirectResponse { - $entity = parent::view_process($uid); - if (!$entity instanceof UserEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 UserEntity만 가능"); + try { + $entity = $this->delete_process($uid); + if (!$entity instanceof UserEntity) { + throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 UserEntity만 가능"); + } + return $this->delete_result_process($entity); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 삭제 오류:" . $e->getMessage()); } - return $entity; } - protected function batchjob_process($uid, array $formDatas): UserEntity + public function view($uid): string|RedirectResponse { - $entity = parent::batchjob_process($uid, $formDatas); - if (!$entity instanceof UserEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 UserEntity만 가능"); + try { + $action = __FUNCTION__; + $this->action_init_process($action); + $entity = $this->view_process($uid); + if (!$entity instanceof UserEntity) { + throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 UserEntity만 가능"); + } + $this->addViewDatas('entity', $entity); + return $this->view_result_process($action); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 {$uid} 상세보기 오류:" . $e->getMessage()); } - return $entity; } - protected function batchjob_delete_process($uid): UserEntity + public function batchjob(): string|RedirectResponse { - $entity = $this->service->delete($uid); - if (!$entity instanceof UserEntity) { - throw new \RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 UserEntity만 가능"); + try { + // 사전작업 및 데이터 추출 초기화 + list($uids, $selectedFields, $formDatas) = $this->batchjob_pre_process(); + $this->service->getFormService()->setFormFields($selectedFields); + $this->service->getFormService()->setFormRules(__FUNCTION__, $selectedFields); + $this->service->getFormService()->setFormFilters($selectedFields); + $this->service->getFormService()->setFormOptions($selectedFields); + $entities = []; + $errors = []; + foreach ($uids as $uid) { + try { + $entities[] = $this->batchjob_process($uid, $formDatas); + } catch (ValidationException $e) { + log_message('error', "{$this->getTitle()}에서 {$uid} 수정 검증오류:" . $e->getMessage()); + $errors[] = $e->getMessage(); + } catch (\Exception $e) { + log_message('error', "{$this->getTitle()}에서 {$uid} 수정 오류:" . $e->getMessage()); + $errors[] = $e->getMessage(); + } + } + return $this->batchjob_result_process($uids, $entities, $errors); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 일괄작업처리 오류:" . $e->getMessage()); } - return $entity; } + + public function batchjob_delete(): string|RedirectResponse + { + try { + $uids = $this->batchjob_delete_pre_process(); + $entities = []; + $errors = []; + foreach ($uids as $uid) { + try { + $entities[] = $this->batchjob_delete_process($uid); + } catch (\Exception $e) { + log_message('error', "{$this->getTitle()}에서 {$uid} 삭제 오류:" . $e->getMessage()); + $errors[] = $e->getMessage(); + } + } + return $this->batchjob_delete_result_process($uids, $entities, $errors); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 일괄삭제 오류:" . $e->getMessage()); + } + } + + public function index(): string|ResponseInterface + { + try { + $action = __FUNCTION__; + $this->action_init_process($action); + $this->index_process($action); + $this->index_result_process($action); + } catch (\Exception $e) { + session()->setFlashdata('message', $e->getMessage()); + } + return $this->index_result_process($action); + } + + public function download(string $output_type, mixed $uid = false): DownloadResponse|RedirectResponse|string + { + try { + $action = __FUNCTION__; + $this->action_init_process($action); + return $this->download_process($action, $output_type, $uid); + } catch (\Exception $e) { + return $this->action_redirect_process('error', "{$this->getTitle()}에서 오류:" . $e->getMessage()); + } + } + //기본 함수 작업 + //Custom 추가 함수 } diff --git a/app/Controllers/CommonController.php b/app/Controllers/CommonController.php index a2cc1d5..24df79d 100644 --- a/app/Controllers/CommonController.php +++ b/app/Controllers/CommonController.php @@ -5,8 +5,6 @@ namespace App\Controllers; use App\Entities\CommonEntity; use CodeIgniter\HTTP\DownloadResponse; use CodeIgniter\HTTP\RedirectResponse; -use CodeIgniter\Validation\Exceptions\ValidationException; -use CodeIgniter\HTTP\ResponseInterface; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Reader\Html; use PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf; @@ -87,7 +85,7 @@ abstract class CommonController extends AbstractCRUDController /** * Service에서 엔티티 목록을 가져와 처리합니다. (Override 가능) */ - protected function index_process(array $entities = []): array + protected function index_entities_process(array $entities = []): array { foreach ($this->service->getEntities() as $entity) { $entities[] = $entity; @@ -95,9 +93,6 @@ abstract class CommonController extends AbstractCRUDController return $entities; } - /** - * HTML View 출력을 처리합니다. (Override 가능) - */ protected function index_result_process(string $action): string { return $this->action_render_process($this->getActionPaths(), $action, $this->getViewDatas()); @@ -106,47 +101,36 @@ abstract class CommonController extends AbstractCRUDController /** * 인덱스(목록) 페이지의 메인 로직입니다. */ - final public function index(): string|ResponseInterface + protected function index_process(string $action): void { - $action = __FUNCTION__; - try { - // 초기화 - $this->action_init_process($action); - $this->addViewDatas('uri', $this->request->getUri()); - - // Paging 설정 - $page = (int) $this->request->getVar('page') ?: 1; - $perpage = (int) $this->request->getVar('perpage') ?: intval(DEFAULTS['INDEX_PERPAGE'] ?? 10); - $this->addViewDatas('page', $page); - $this->addViewDatas('perpage', $perpage); - - // 1. Total Count 계산을 위한 조건절 처리 (오버라이드 가능) - $this->index_condition_process($action); - $index_totalcount = $this->service->getTotalCount(); - $this->addViewDatas('index_totalcount', $index_totalcount); - - // Pagination 설정 - $this->addViewDatas('index_pagination', $this->pagenation_process($index_totalcount, $page, $perpage)); - $this->addViewDatas('index_pagination_options', $this->pagenation_options_process($index_totalcount, $perpage)); - - // 2. 실제 리스트를 위한 조건절, LIMIT, OFFSET 처리 (오버라이드 가능) - $this->index_condition_process($action); // 조건절을 다시 호출하여 필터/검색어 유지 - $this->service->setLimit($perpage); - $this->service->setOffset(($page - 1) * $perpage); - - // Entities 처리 - $this->addViewDatas('entities', $this->index_process()); - helper(['form']); - $this->addViewDatas('formDatas', $this->request->getVar() ?? []); - } catch (\Exception $e) { - session()->setFlashdata('message', $e->getMessage()); - } - // 현재 URL을 이전 URL 스택에 저장 $this->getAuthContext()->pushCurrentUrl($this->request->getUri()->getPath() . ($this->request->getUri()->getQuery() ? "?" . $this->request->getUri()->getQuery() : "")); + $this->addViewDatas('uri', $this->request->getUri()); - // HTML 뷰 렌더링 - return $this->index_result_process($action); + // Paging 설정 + $page = (int) $this->request->getVar('page') ?: 1; + $perpage = (int) $this->request->getVar('perpage') ?: intval(DEFAULTS['INDEX_PERPAGE'] ?? 10); + $this->addViewDatas('page', $page); + $this->addViewDatas('perpage', $perpage); + + // 1. Total Count 계산을 위한 조건절 처리 (오버라이드 가능) + $this->index_condition_process($action); + $index_totalcount = $this->service->getTotalCount(); + $this->addViewDatas('index_totalcount', $index_totalcount); + + // Pagination 설정 + $this->addViewDatas('index_pagination', $this->pagenation_process($index_totalcount, $page, $perpage)); + $this->addViewDatas('index_pagination_options', $this->pagenation_options_process($index_totalcount, $perpage)); + + // 2. 실제 리스트를 위한 조건절, LIMIT, OFFSET 처리 (오버라이드 가능) + $this->index_condition_process($action); // 조건절을 다시 호출하여 필터/검색어 유지 + $this->service->setLimit($perpage); + $this->service->setOffset(($page - 1) * $perpage); + + // Entities 처리 + $this->addViewDatas('entities', $this->index_entities_process()); + helper(['form']); + $this->addViewDatas('formDatas', $this->request->getVar() ?? []); } // --- 일괄 작업 (Batch Job) --- @@ -192,38 +176,6 @@ abstract class CommonController extends AbstractCRUDController )); } - final public function batchjob(): string|RedirectResponse - { - try { - // 사전작업 및 데이터 추출 - list($uids, $selectedFields, $formDatas) = $this->batchjob_pre_process(); - - // 초기화 - $this->service->getFormService()->setFormFields($selectedFields); - $this->service->getFormService()->setFormRules(__FUNCTION__, $selectedFields); - $this->service->getFormService()->setFormFilters($selectedFields); - $this->service->getFormService()->setFormOptions($selectedFields); - - $entities = []; - $errors = []; - - foreach ($uids as $uid) { - try { - $entities[] = $this->batchjob_process($uid, $formDatas); - } catch (ValidationException $e) { - log_message('error', "{$this->getTitle()}에서 {$uid} 수정 검증오류:" . $e->getMessage()); - $errors[] = $e->getMessage(); - } catch (\Exception $e) { - log_message('error', "{$this->getTitle()}에서 {$uid} 수정 오류:" . $e->getMessage()); - $errors[] = $e->getMessage(); - } - } - return $this->batchjob_result_process($uids, $entities, $errors); - } catch (\Exception $e) { - return $this->action_redirect_process('error', "{$this->getTitle()}에서 일괄작업처리 오류:" . $e->getMessage()); - } - } - // --- 일괄 삭제 (Batch Job Delete) --- protected function batchjob_delete_pre_process(): array @@ -257,27 +209,6 @@ abstract class CommonController extends AbstractCRUDController return $this->service->delete($uid); } - final public function batchjob_delete(): string|RedirectResponse - { - try { - $uids = $this->batchjob_delete_pre_process(); - $entities = []; - $errors = []; - - foreach ($uids as $uid) { - try { - $entities[] = $this->batchjob_delete_process($uid); - } catch (\Exception $e) { - log_message('error', "{$this->getTitle()}에서 {$uid} 삭제 오류:" . $e->getMessage()); - $errors[] = $e->getMessage(); - } - } - return $this->batchjob_delete_result_process($uids, $entities, $errors); - } catch (\Exception $e) { - return $this->action_redirect_process('error', "{$this->getTitle()}에서 일괄삭제 오류:" . $e->getMessage()); - } - } - // --- 문서 다운로드 (Download) --- protected function downloadByDocumentType(string $document_type, mixed $loaded_data): array @@ -308,7 +239,7 @@ abstract class CommonController extends AbstractCRUDController helper(['form']); // 전체 목록을 다운로드하므로, 목록 조건절을 처리합니다. $this->index_condition_process($action); - $this->addViewDatas('entities', $this->index_process()); + $this->addViewDatas('entities', $this->index_entities_process()); // HTML로 렌더링된 내용을 가져옵니다. $html = $this->action_render_process($this->getActionPaths(), $action, $this->getViewDatas()); @@ -337,18 +268,4 @@ abstract class CommonController extends AbstractCRUDController } return $this->response->download($full_path, null)->setFileName($file_name); } - - /** - * 최종 다운로드 액션입니다. - */ - final public function download(string $output_type, mixed $uid = false): DownloadResponse|RedirectResponse|string - { - $action = __FUNCTION__; - try { - $this->action_init_process($action); - return $this->download_process($action, $output_type, $uid); - } catch (\Exception $e) { - return $this->action_redirect_process('error', "{$this->getTitle()}에서 오류:" . $e->getMessage()); - } - } }