addActionPaths(self::PATH); } final protected function getLayout(): string { return 'admin'; } protected function action_init_process(string $action): void { $this->addViewDatas('layout', $this->getLayout()); $this->addViewDatas('helper', $this->service->getHelper()); $this->addViewDatas('formFields', $this->service->getFormService()->getFormFields()); $this->addViewDatas('formRules', $this->service->getFormService()->getFormRules()); $this->addViewDatas('formFilters', $this->service->getFormService()->getFormFilters()); $this->addViewDatas('formOptions', $this->service->getFormService()->getFormOptions()); $this->addViewDatas('index_batchjobFields', $this->service->getFormService()->getBatchjobFilters()); $this->addViewDatas('index_batchjobButtions', $this->service->getFormService()->getBatchjobButtons()); parent::action_init_process($action); } abstract protected function create_form_process(): void; final public function create_form(): string { $action = __FUNCTION__; try { //초기화 $this->action_init_process($action); $this->create_form_process(); } catch (\Exception $e) { log_message('error', $e->getMessage()); session()->setFlashdata('message', $e->getMessage()); } return $this->action_render_process($this->getActionPaths(), $action, $this->getViewDatas()); } abstract protected function create_process(): array; final public function create(): string|RedirectResponse { $action = __FUNCTION__; try { //초기화 $this->action_init_process($action); list($entity, $message) = $this->create_process(); return $this->action_modal_process($message); } catch (ValidationException $e) { // 검증 실패 시 폼으로 돌아가서 오류 메시지 표시 log_message('error', $e->getMessage()); return redirect()->back()->withInput()->with('message', $e->getMessage()); } catch (\Exception $e) { log_message('error', $e->getMessage()); return redirect()->back()->withInput()->with('message', $e->getMessage()); } } abstract protected function modify_form_process($uid): void; final public function modify_form($uid): string { $action = __FUNCTION__; try { //초기화 $this->action_init_process($action); $this->modify_form_process($uid); } catch (\Exception $e) { log_message('error', $e->getMessage()); session()->setFlashdata('message', $e->getMessage()); } return $this->action_render_process($this->getActionPaths(), $action, $this->getViewDatas()); } abstract protected function modify_process($uid): array; final public function modify($uid): string|RedirectResponse { $action = __FUNCTION__; try { //초기화 $this->action_init_process($action); list($entity, $message) = $this->modify_process($uid); return $this->action_modal_process($message); } catch (ValidationException $e) { // 검증 실패 시 폼으로 돌아가서 오류 메시지 표시 log_message('error', $e->getMessage()); return redirect()->back()->withInput()->with('message', $e->getMessage()); } catch (\Exception $e) { log_message('error', $e->getMessage()); return redirect()->back()->withInput()->with('message', $e->getMessage()); } } protected function delete_process($uid): RedirectResponse { if (!$uid) { throw new \Exception("계정 번호가 정의 되지 않았습니다."); } $entity = $this->service->getEntity($uid); if (!$entity instanceof CommonEntity) { throw new \Exception("{$uid}에 해당하는 계정을 찾을수 없습니다."); } $this->service->delete($uid); $redirect_url = $this->getAuthContext()->popPreviousUrl() ?? implode(DIRECTORY_SEPARATOR, $this->getActionPaths()); return redirect()->to($redirect_url)->with('message', "{$entity->getTitle()} 계정 생성이 완료되었습니다."); } final public function delete($uid): RedirectResponse { $action = __FUNCTION__; try { //초기화 $this->action_init_process($action); return $this->delete_process($uid); } catch (ValidationException $e) { // 검증 실패 시 폼으로 돌아가서 오류 메시지 표시 log_message('error', $e->getMessage()); return redirect()->back()->withInput()->with('message', $e->getMessage()); } catch (\Exception $e) { log_message('error', $e->getMessage()); return redirect()->back()->withInput()->with('message', $e->getMessage()); } } protected function view_process($uid): CommonEntity { if (!$uid) { throw new \Exception("계정 번호가 정의 되지 않았습니다."); } $entity = $this->service->getEntity($uid); if (!$entity instanceof CommonEntity) { throw new \Exception("{$uid}에 해당하는 계정을 찾을수 없습니다."); } return $entity; } final public function view($uid): string { $action = __FUNCTION__; try { //초기화 $this->action_init_process($action); $entity = $this->view_process($uid); $this->addViewDatas('entity', $entity); } catch (\Exception $e) { log_message('error', $e->getMessage()); session()->setFlashdata('message', $e->getMessage()); } return $this->action_render_process($this->getActionPaths(), $action, $this->getViewDatas()); } //리스트관련 //조건절 처리 protected function index_condition_process(string $action): void { //Filter조건절 처리 $index_filters = []; foreach ($this->service->getFormService()->getFormFilters($action) as $field) { $value = $this->request->getVar(index: $field) ?? null; if ($value) { $this->service->setFilter($field, $value); $index_filters[$field] = $value; } } $this->addViewDatas('index_filters', $index_filters); //검색어조건절 처리 $index_word = $this->request->getVar('index_word'); if ($index_word !== null && $index_word !== '') { $this->service->setSearchWord($index_word); } $this->addViewDatas('index_word', $index_word); //날자검색 $index_start = $this->request->getVar('index_start'); $index_end = $this->request->getVar('index_end'); if ($index_start !== null && $index_start !== '' && $index_end !== null && $index_end !== '') { $this->service->setDateFilter($index_start, $index_end); } $this->addViewDatas('index_start', $index_start); $this->addViewDatas('index_end', $index_end); } //Index Option출력용 protected function pagenation_options_process(int $index_totalcount, int $perpage): array { $page_options = ["" => "줄수선택"]; for ($i = $perpage; $i <= $index_totalcount; $i += $perpage) { $page_options[$i] = $i; } $page_options[$index_totalcount] = $index_totalcount; return $page_options; } //PageNation 처리 protected function pagenation_process(int $index_totalcount, int $page, int $perpage, $pager_group = 'default', int $segment = 0, $template = 'bootstrap_full'): mixed { // 1.Views/Pagers/에 bootstrap_full.php,bootstrap_simple.php 생성 // 2.app/Config/Pager.php/$templates에 'bootstrap_full => 'Pagers\bootstrap_full', // 'bootstrap_simple' => 'Pagers\bootstrap_simple', 추가 $pager = service("pager"); $pager->makeLinks($page, $perpage, $index_totalcount, $template, $segment, $pager_group); // $page = $pager->getCurrentPage($pager_group); $this->addViewDatas('index_totalpage', $pager->getPageCount($pager_group)); return $pager->links($pager_group, $template); } // //Page출력 처리 //Entities처리 protected function index_process(array $entities = []): array { foreach ($this->service->getEntities() as $entity) { $entities[] = $entity; } return $entities; } public function index(): string { $action = __FUNCTION__; try { //초기화 $this->action_init_process($action); $this->addViewDatas('uri', $this->request->getUri()); //Page, Per_page필요부분 $page = (int) $this->request->getVar('page') ?: 1; $perpage = (int) $this->request->getVar('perpage') ?: intval(DEFAULTS['INDEX_PERPAGE']); $this->addViewDatas('page', $page); $this->addViewDatas('perpage', $perpage); //index_totalcount //조건절 처리 index_totalcount용 $this->index_condition_process($action); $index_totalcount = $this->service->getTotalCount(); $this->addViewDatas('index_totalcount', $index_totalcount); $this->addViewDatas('index_pagination', $this->pagenation_process($index_totalcount, $page, $perpage)); $this->addViewDatas('index_pagination_options', $this->pagenation_options_process($index_totalcount, $perpage)); //OrcerBy , Limit 처리 $order_field = $this->request->getVar('order_field'); $order_value = $this->request->getVar('order_value'); $this->service->setOrderBy($order_field, $order_value); $this->addViewDatas('order_field', $order_field); $this->addViewDatas('order_value', $order_value); $this->service->setLimit($perpage); $this->service->setOffset(($page - 1) * $perpage); //List //조건절 처리 List용 $this->index_condition_process($action); $this->addViewDatas('entities', $this->index_process()); helper(['form']); $this->addViewDatas('formDatas', $this->request->getGet()); } catch (\Exception $e) { session()->setFlashdata('message', $e->getMessage()); } //현재 URL을 세션에 저장 $this->getAuthContext()->pushCurrentUrl($this->request->getUri()->getPath() . ($this->request->getUri()->getQuery() ? "?" . $this->request->getUri()->getQuery() : "")); return $this->action_render_process($this->getActionPaths(), $action, $this->getViewDatas()); } }