diff --git a/app/Controllers/Admin/Customer/ServiceItemController.php b/app/Controllers/Admin/Customer/ServiceItemController.php index b05985a..94404dc 100644 --- a/app/Controllers/Admin/Customer/ServiceItemController.php +++ b/app/Controllers/Admin/Customer/ServiceItemController.php @@ -26,7 +26,16 @@ class ServiceItemController extends CustomerController // $this->view_path .= strtolower($this->getService()->getClassName()) . DIRECTORY_SEPARATOR; } - + protected function initAction(string $action): void + { + parent::initAction($action); + //LINE,IP,SERVER등 추가 FilterOption 셋팅용 + foreach (SERVICE_ITEM_TYPES as $item_type => $label) { + $options = $this->getService()->getServiceItemLinkService($item_type)->getEntities(); + $this->setFieldRule($item_type, $this->getFormFieldRule($this->getAction(), $item_type)); + $this->setFilterFieldOption($item_type, $options); + } + } public function getService(): ServiceItemService { if (!$this->_service) { @@ -51,6 +60,8 @@ class ServiceItemController extends CustomerController protected function getResultSuccess(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string { switch ($this->getAction()) { + case 'create_form': + case 'modify_form': case 'index': $result = parent::getResultSuccess($message, $this->request->getVar('ActionTemplate') ?? $actionTemplate ?? 'popup'); break; @@ -79,26 +90,20 @@ class ServiceItemController extends CustomerController } //Index,FieldForm관련 - protected function create_form_process(): void + //item_type에 따른 item_uid 값 가져오기 + private function setItemUID(ServiceEntity $serviceEntity, array $formDatas): array { - //LINE,IP,SERVER등 추가 FilterOption 셋팅용 - foreach (SERVICE_ITEM_TYPES as $item_type => $label) { - $options = $this->getService()->getServiceItemLinkService($item_type)->getEntities(); - $this->setFilterFieldOption($item_type, $options); + switch ($formDatas['item_type']) { + case 'DOMAIN': + //DomainService에 먼저 create후 결과 uid를 item_uid로 전달함 + $equipmentEntity = $this->getService()->getServiceItemLinkService($formDatas['item_type'])->create([ + 'clientinfo_uid' => $serviceEntity->getClientUID(), + 'domain' => $formDatas['item_uid'] + ]); + //도메인용 항목의 item_uid로 전달함 + $formDatas['item_uid'] = $equipmentEntity->getPK(); + break; } - parent::create_form_process(); - } - - //도메인의 경우 domaininfo에 등록 후 ServiceItemEntity의 item_uid에 넣고 create해야함 - private function createDomain(ServiceEntity $serviceEntity, array $formDatas): array - { - //DomainService에 먼저 create후 결과 uid를 item_uid로 전달함 - $equipmentEntity = $this->getService()->getServiceItemLinkService($formDatas['item_type'])->create([ - 'clientinfo_uid' => $serviceEntity->getClientUID(), - 'domain' => $formDatas['item_uid'] - ]); - //도메인용 항목의 item_uid로 전달함 - $formDatas['item_uid'] = $equipmentEntity->getPK(); return $formDatas; } protected function create_process(array $formDatas): ServiceItemEntity @@ -107,30 +112,8 @@ class ServiceItemController extends CustomerController if (!$serviceEntity) { throw new \Exception("{$formDatas['serviceinfo_uid']}에 대한 서비스정보를 찾을수 없습니다."); } - // item_type이 도메인의 경우 domaininfo에 등록 후 ServiceItemEntity의 item_uid에 넣고 create해야함 - if ($formDatas['item_type'] === 'DOMAIN') { - $formDatas = $this->createDomain($serviceEntity, $formDatas); - } + //item_type에 따른 item_uid 값 가져오기 반드시 Validation 전에 정의해야함 + $formDatas = $this->setItemUID($serviceEntity, $formDatas); return parent::create_process($formDatas); } - - protected function modify_form_process(mixed $entity): mixed - { - //LINE,IP,SERVER등 추가 FilterOption 셋팅용 - foreach (SERVICE_ITEM_TYPES as $item_type => $label) { - $options = $this->getService()->getServiceItemLinkService($item_type)->getEntities(); - $this->setFilterFieldOption($item_type, $options); - } - return parent::modify_form_process($entity); - } - - protected function index_process(): array - { - //LINE,IP,SERVER등 추가 FilterOption 셋팅용 - foreach (SERVICE_ITEM_TYPES as $item_type => $label) { - $options = $this->getService()->getServiceItemLinkService($item_type)->getEntities(); - $this->setFilterFieldOption($item_type, $options); - } - return parent::index_process(); - } } diff --git a/app/Controllers/CommonController.php b/app/Controllers/CommonController.php index e4574d8..92c5b87 100644 --- a/app/Controllers/CommonController.php +++ b/app/Controllers/CommonController.php @@ -211,6 +211,7 @@ abstract class CommonController extends BaseController foreach ($rules as $field => $rule) { $validation = $this->setValidation($validation, $field, $rule); } + // dd($formDatas); if (!$validation->run($formDatas)) { throw new \Exception("{$this->getService()->getClassName()} 작업 데이터 검증 오류발생\n" . implode( "\n", diff --git a/app/Helpers/Customer/ServiceItemHelper.php b/app/Helpers/Customer/ServiceItemHelper.php index 87ce07d..1945836 100644 --- a/app/Helpers/Customer/ServiceItemHelper.php +++ b/app/Helpers/Customer/ServiceItemHelper.php @@ -23,18 +23,20 @@ class ServiceItemHelper extends CustomerHelper if (in_array($viewDatas['control']['action'], ['create', 'modify', 'create_form', 'modify_form'])) { $extras = (strpos($viewDatas['control']['field_rules'][$field], 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras]; } - switch ($viewDatas['item_type']) { + $item_type = $viewDatas['item_type']; + //Field는 item_uid이지만 , item_tpe에 따라 filter_options가 달라진다. + switch ($item_type) { case 'DOMAIN': if (in_array($viewDatas['control']['action'], ['create', 'modify', 'create_form', 'modify_form'])) { $form = form_input($field, $value ?? "", ["placeholder" => "예)example.com", ...$extras]); } else { - if (!is_array($viewDatas['control']['filter_optons'][$field])) { - throw new \Exception(__METHOD__ . "에서 {$field}의 field_options가 array형태가 아닙니다."); + if (!is_array($viewDatas['control']['filter_optons'][$item_type])) { + throw new \Exception(__METHOD__ . "에서 {$item_type}의 field_options가 array형태가 아닙니다."); } //CodeIgniter 4의 form_dropdown()은 options 배열로만 값을 받기 때문에, disabled 속성 같은 개별 옵션에 대한 HTML 속성 추가는 기본적으로 지원하지 않습니다. $form_temps = ["'; $form = implode("", $form_temps); } + break; case "LINE": case "SERVER": case "CPU": @@ -49,13 +52,14 @@ class ServiceItemHelper extends CustomerHelper case "STORAGE": case "SOFTWARE": case "DEFENCE": - if (!is_array($viewDatas['control']['filter_optons'][$field])) { - throw new \Exception(__METHOD__ . "에서 {$field}의 field_options가 array형태가 아닙니다."); + // dd($viewDatas['control']['filter_optons']); + if (!is_array($viewDatas['control']['filter_optons'][$item_type])) { + throw new \Exception(__METHOD__ . "에서 {$item_type}의 field_options가 array형태가 아닙니다."); } //CodeIgniter 4의 form_dropdown()은 options 배열로만 값을 받기 때문에, disabled 속성 같은 개별 옵션에 대한 HTML 속성 추가는 기본적으로 지원하지 않습니다. $form_temps = [""]; - $form_temps[] = ""; - foreach ($viewDatas['control']['filter_optons'][$field] as $key => $filterEntity) { + $form_temps[] = ""; + foreach ($viewDatas['control']['filter_optons'][$item_type] as $key => $filterEntity) { $disabled = in_array($filterEntity->getStatus(), [IpEntity::STATUS_OCCUPIED, IpEntity::STATUS_FORBIDDEN]) ? 'disabled="disabled"' : ''; $selected = ($value === $key) ? 'selected="selected"' : ''; $form_temps[] = ""; } $form_temps[] = ''; $form = implode("", $form_temps); - //dd($viewDatas['occupied_ips']); break; default: $form = parent::getFieldForm($field, $value, $viewDatas, $extras); @@ -92,7 +95,7 @@ class ServiceItemHelper extends CustomerHelper } switch ($field) { case 'item_uid': - $form = $this->getFieldFormByItemType($this->getRequest()->getVar('item_type'), $value, $viewDatas, $extras); + $form = $this->getFieldFormByItemType($field, $value, $viewDatas, $extras); break; default: $form = parent::getFieldForm($field, $value, $viewDatas, $extras); diff --git a/app/Services/Customer/CustomerService.php b/app/Services/Customer/CustomerService.php index 34aee6a..f4709be 100644 --- a/app/Services/Customer/CustomerService.php +++ b/app/Services/Customer/CustomerService.php @@ -40,32 +40,50 @@ abstract class CustomerService extends CommonService if (!array_key_exists($key, $this->_equipmentService)) { switch ($key) { case 'SERVER': - $this->_equipmentService[$key] = new ServerService(); + if (!array_key_exists($key, $this->_equipmentService)) { + $this->_equipmentService[$key] = new ServerService(); + } break; case 'CPU': - $this->_equipmentService[$key] = new CpuService(); + if (!array_key_exists($key, $this->_equipmentService)) { + $this->_equipmentService[$key] = new CpuService(); + } break; case 'RAM': - $this->_equipmentService[$key] = new RamService(); + if (!array_key_exists($key, $this->_equipmentService)) { + $this->_equipmentService[$key] = new RamService(); + } break; case 'STORAGE': - $this->_equipmentService[$key] = new StorageService(); + if (!array_key_exists($key, $this->_equipmentService)) { + $this->_equipmentService[$key] = new StorageService(); + } break; case 'LINE': - $this->_equipmentService[$key] = new LineService(); + if (!array_key_exists($key, $this->_equipmentService)) { + $this->_equipmentService[$key] = new LineService(); + } break; case 'IP': - // $this->_equipmentService[$key] = new ServiceItemIpService(); - $this->_equipmentService[$key] = new IpService(); + if (!array_key_exists($key, $this->_equipmentService)) { + // $this->_equipmentService[$key] = new ServiceItemIpService(); + $this->_equipmentService[$key] = new IpService(); + } break; case 'DEFENCE': - $this->_equipmentService[$key] = new DefenceService(); + if (!array_key_exists($key, $this->_equipmentService)) { + $this->_equipmentService[$key] = new DefenceService(); + } break; case 'SOFTWARE': - $this->_equipmentService[$key] = new SoftwareService(); + if (!array_key_exists($key, $this->_equipmentService)) { + $this->_equipmentService[$key] = new SoftwareService(); + } break; case 'DOMAIN': - $this->_equipmentService[$key] = new DomainService(); + if (!array_key_exists($key, $this->_equipmentService)) { + $this->_equipmentService[$key] = new DomainService(); + } break; default: throw new \Exception(__FUNCTION__ . "에서 사용하지않는 Service를 요청하였습니다.: {$key}");