service === null) { $this->service = service('userservice'); } } //Action작업관련 protected function action_init_process(string $action): void { $fields = ['id', 'passwd', 'confirmpassword', 'name', 'email', 'mobile', 'role']; $filters = ['role', 'status']; $batchjobFilters = ['status']; switch ($action) { case 'create': case 'create_form': break; case 'modify': case 'modify_form': $fields = [...$fields, 'status']; break; case 'view': $fields = ['id', 'name', 'email', 'mobile', 'role', 'status', 'created_at']; break; case 'index': case 'download': $fields = ['id', 'name', 'email', 'mobile', 'role', 'status', 'created_at']; break; default: throw new \Exception("[{$action}] 지원하지 않는 action입니다."); // break; } $this->service->getFormService()->setFormFields($fields); $this->service->getFormService()->setFormRules($action, $fields); $this->service->getFormService()->setFormFilters($filters); $this->service->getFormService()->setFormOptions($filters); $this->service->getFormService()->setBatchjobFilters($batchjobFilters); parent::action_init_process($action); } 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()); } } public function create(): string|RedirectResponse { 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()); } } public function modify_form($uid): string|RedirectResponse { 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()); } } public function modify($uid): string|RedirectResponse { 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()); } } public function delete($uid): RedirectResponse { 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()); } } public function view($uid): string|RedirectResponse { 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()); } } 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()); } } 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 추가 함수 }