addClassName('SWITCH'); } public function getFormFields(): array { return [ "code", "price", "status", ]; } public function getFormFilters(): array { return [ 'clientinfo_uid', 'serviceinfo_uid', 'serverinfo_uid', 'status' ]; } public function getIndexFields(): array { return [ 'clientinfo_uid', 'serviceinfo_uid', 'serverinfo_uid', "price", 'status', ]; } public function getBatchjobFields(): array { return ['clientinfo_uid', 'serverinfo_uid', 'status']; } public function getServiceService(): ServiceService { if (!$this->_serviceService) { $this->_serviceService = new ServiceService(); } return $this->_serviceService; } public function getServerService(): ServerService { if (!$this->_serverService) { $this->_serverService = new ServerService(); } return $this->_serverService; } //기본 기능부분 public function getFormOption(string $field, array $options = []): array { switch ($field) { case 'serviceinfo_uid': $options = $this->getServiceService()->getEntities(); break; case 'serverinfo_uid': $options = $this->getServerService()->getEntities(); break; default: $options = parent::getFormOption($field, $options); break; } return $options; } //FieldForm관련용 //List 검색용 //OrderBy 처리 public function setOrderBy(mixed $field = null, mixed $value = null): void { $this->getModel()->orderBy('code', 'ASC'); parent::setOrderBy($field, $value); } //서버관련 작업 public function attachToServer(ServerEntity $serverEntity, array $formDatas = []): void { $formDatas = []; $formDatas['clientinfo_uid'] = $serverEntity->getClientInfoUID(); $formDatas['serviceinfo_uid'] = $serverEntity->getServiceInfoUID(); $formDatas['serverinfo_uid'] = $serverEntity->getPK(); $formDatas['status'] = STATUS['OCCUPIED']; if (!array_key_exists('status', $formDatas)) { throw new \Exception(__METHOD__ . ":에서 오류발생: Switch상태가 설정되지 않았습니다."); } //Switch정보에서 해당하는 IP가 있으면 가져와서 사용중인지 체크 후 수정 $entity = $this->getEntity(['code' => $serverEntity->getCode()]); if ($entity instanceof SWITCHEntity) { if ($entity->getStatus() !== STATUS['AVAILABLE']) { throw new \Exception(__METHOD__ . ":에서 오류발생: {$serverEntity->getTitle()}는 사용중입니다."); } $entity = parent::modify($entity, $formDatas); } } public function detachFromServer(ServerEntity $serverEntity): void { $formDatas = []; $formDatas['clientinfo_uid'] = null; $formDatas['serviceinfo_uid'] = null; $formDatas['serverinfo_uid'] = null; $formDatas['old_clientinfo_uid'] = $serverEntity->getClientInfoUID() ?? null; $formDatas['status'] = STATUS['AVAILABLE']; if (!array_key_exists('status', $formDatas)) { throw new \Exception(__METHOD__ . ":에서 오류발생: Switch상태가 설정되지 않았습니다."); } //Switch정보가져오기 $entity = $this->getEntity(['code' => $serverEntity->getCode()]); if (!$entity instanceof SWITCHEntity) { throw new \Exception("{$serverEntity->getIP()}에 해당하는 IP정보를 찾을수없습니다."); } //Switch정보 수정 parent::modify($entity, $formDatas); } //서버파트관련 작업 public function attachToServerPart(ServerPartEntity $serverPartEntity): SWITCHEntity { $formDatas = []; $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID(); $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); $formDatas['status'] = STATUS['OCCUPIED']; if (!array_key_exists('status', $formDatas)) { throw new \Exception(__METHOD__ . ":에서 오류발생: Switch상태가 설정되지 않았습니다."); } //SWITCH정보에서 해당하는 SWITCH가 있으면 가져와서 사용중인지 체크 후 수정 $entity = $this->getEntity($serverPartEntity->getPartUID()); if ($entity instanceof SWITCHEntity) { if ($entity->getStatus() !== STATUS['AVAILABLE']) { throw new \Exception(__METHOD__ . ":에서 오류발생: {$entity->getTitle()}는 사용중입니다."); } $entity = parent::modify($entity, $formDatas); } return $entity; } public function detachFromServerPart(ServerPartEntity $serverPartEntity): SWITCHEntity { $formDatas = []; $formDatas['clientinfo_uid'] = null; $formDatas['serviceinfo_uid'] = null; $formDatas['serverinfo_uid'] = null; $formDatas['old_clientinfo_uid'] = $serverPartEntity->getClientInfoUID() ?? null; $formDatas['status'] = STATUS['AVAILABLE']; if (!array_key_exists('status', $formDatas)) { throw new \Exception(__METHOD__ . ":에서 오류발생: Switch상태가 설정되지 않았습니다."); } //Switch정보가져와서 있으면 수정 $entity = $this->getEntity($serverPartEntity->getPartUID()); if (!$entity instanceof SWITCHEntity) { throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 Switch정보를 찾을수없습니다."); } return $entity; } }