addClassName('ServerPart'); } public function getFormFields(): array { return [ "serverinfo_uid", "type", "part_uid", "billing", "amount", "cnt", "extra", ]; } public function getFormFilters(): array { return [ "serverinfo_uid", "type", "part_uid", "billing", ]; } public function getBatchjobFields(): array { return ['billing', 'type', 'partinfo_uid']; } final public function getSwitchService(): SwitchService { if (!$this->_switchService) { $this->_switchService = new SwitchService(); } return $this->_switchService; } final public function getPartService(): PartService { if (!$this->_partService) { $this->_partService = new PartService(); } return $this->_partService; } final public function getIPService(): IPService { if (!$this->_ipService) { $this->_ipService = new IPService(); } return $this->_ipService; } final public function getCSService(): CSService { if (!$this->_csService) { $this->_csService = new CSService(); } return $this->_csService; } //partEntity 정보 추가 protected function getEntity_process(mixed $entity): ServerPartEntity { //부품정보 정의 $partEntity = $this->getPartService()->getEntity($entity->getPartInfoUID()); if ($entity) { $entity->setPartEntity($partEntity); } return $entity; } //기본 기능부분 // FieldForm관련용 public function getFormOption(string $field, array $options = []): array { switch ($field) { case 'SWITCH': $options = $this->getSwitchService()->getEntities(); break; case 'CPU': $options = $this->getPartService()->getEntities(['type' => 'CPU']); break; case 'RAM': $options = $this->getPartService()->getEntities(['type' => 'RAM']); break; case 'DISK': $options = $this->getPartService()->getEntities(['type' => 'DISK']); break; case 'OS': $options = $this->getPartService()->getEntities(['type' => 'OS']); break; case 'DB': $options = $this->getPartService()->getEntities(['type' => 'DB']); break; case 'SOFTWARE': $options = $this->getPartService()->getEntities(['type' => 'SOFTWARE']); break; case 'IP': $options = $this->getIPService()->getEntities(); break; case 'CS': $options = $this->getCSService()->getEntities(); break; } return $options; } //서버별생성 public function createByServer(ServerEntity $serverEntity, array $formDatas): ServerEntity { foreach (SERVERPART['PARTTYPES'] as $partType) { if (array_key_exists($partType, $formDatas)) { $serverPartFormDatas = []; $serverPartFormDatas["part_uid"] = $formDatas[$partType]; $serverPartFormDatas["serverinfo_uid"] = $serverEntity->getPK(); $serverPartFormDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID(); $serverPartFormDatas["type"] = $partType; $serverPartFormDatas["billing"] = null; $serverPartFormDatas["amount"] = 0; $serverPartFormDatas["cnt"] = array_key_exists("{$partType}_cnt", $formDatas) ? $formDatas["{$partType}_cnt"] : 1; $serverPartFormDatas["extra"] = array_key_exists("{$partType}_extra", $formDatas) ? $formDatas["{$partType}_extra"] : null; $entity = parent::create($serverPartFormDatas); //부품정보 정의 switch ($partType) { case 'SWITCH': $partService = $this->getSwitchService(); break; case 'IP': $partService = $this->getIPService(); break; case 'CS': $partService = $this->getCSService(); break; default: $partService = $this->getPartService(); break; } $partEntity = $partService->getEntity($entity->getPartUID()); if (!$partEntity) { throw new \Exception(__METHOD__ . "에서 오류:{$partType}의{$entity->getPartUID()}에 해닫하는 정보가 없습니다."); } $serverEntity->addServerPartEntity($partType, $partEntity); } } return $serverEntity; } //서버별삭제 public function deleteByServer(ServerEntity $serverEntity): void { //기존 서벼별 부품연결정보 삭제 후 foreach ($this->getEntities(['serverinfo_uid' => $serverEntity->getPK()]) as $entity) { $this->delete($entity); } } //서비스연결 public function enableService(ServerEntity $serverEntity, ServerPartEntity $entity, array $formDatas): ServerPartEntity { //ServerPart 수정 $formDatas["serverinfo_uid"] = $serverEntity->getPK(); $entity = parent::modify($entity, $formDatas); //각 파트서비스별 수정 switch ($entity->getType()) { case 'SWITCH': $partService = $this->getSwitchService(); $formDatas['status'] = STATUS['OCCUPIED'];; break; case 'IP': $partService = $this->getIPService(); $formDatas['status'] = STATUS['OCCUPIED'];; break; case 'CS': $partService = $this->getCSService(); $formDatas['status'] = STATUS['OCCUPIED'];; break; default: $partService = $this->getPartService(); break; } $partEntity = $partService->getEntity($entity->getPartUID()); if (!$partEntity) { throw new \Exception(__METHOD__ . "에서 오류:{$entity->getType()}의{$entity->getPartUID()}에 해닫하는 정보가 없습니다."); } $partEntity = $partService->modify($partEntity, $formDatas); //파트설정 $entity->setPartEntity($partEntity); return $entity; } //서비스해지 public function disableService(ServerPartEntity $entity, array $formDatas = []): ServerPartEntity { //ServerPart 수정 $entity = parent::modify($entity, $formDatas); //각 파트서비스별 수정 switch ($entity->getType()) { case 'SWITCH': $partService = $this->getSwitchService(); $formDatas['status'] = STATUS['AVAILABLE']; break; case 'IP': $partService = $this->getIPService(); $formDatas['status'] = STATUS['AVAILABLE']; break; case 'CS': $partService = $this->getCSService(); $formDatas['status'] = STATUS['AVAILABLE']; break; default: $partService = $this->getPartService(); break; } $partEntity = $partService->getEntity($entity->getPartUID()); if (!$partEntity) { throw new \Exception(__METHOD__ . "에서 오류:{$entity->getType()}의{$entity->getPartUID()}에 해닫하는 정보가 없습니다."); } $partEntity = $partService->modify($partEntity, $formDatas); //파트설정 $entity->setPartEntity($partEntity); return $entity; } public function show(int $serverinfo_uid): string { //서버파트연결용 $viewDatas = [ 'control' => [ 'fields' => SERVERPART['PARTTYPES'], 'filters' => SERVERPART['PARTTYPES'], 'field_options' => [], ], ]; foreach (SERVERPART['PARTTYPES'] as $partType) { $viewDatas['control']['field_options'][$partType] = $this->getFormOption($partType); } $viewDatas['helper'] = new ServerPartHelper(); $viewDatas['action'] = __FUNCTION__; //기존 Entity 가져오기 $viewDatas['entities'] = $this->getEntities(['serverinfo_uid' => $serverinfo_uid]); return view('serverpart/' . __FUNCTION__, ['viewDatas' => $viewDatas]); } }