addClassName('ServerPart'); } public function getFormFields(): array { return [ 'fields' => [ "partinfo_uid", "serverinfo_uid", "serviceinfo_uid", "type", "billing", "amount", "cnt", "extra", ], 'filters' => [ "partinfo_uid", "serverinfo_uid", "serviceinfo_uid", "type" ], ]; } public function getIndexFields(): array { return $this->getFormFields(); } public function getBatchjobFields(): array { return ['partinfo_uid', "serverinfo_uid", "serviceinfo_uid",]; } final public function getPartService(): PartService { if (!$this->_partService) { $this->_partService = new PartService(); } return $this->_partService; } //partEntity 정보 추가 protected function getEntity_process(mixed $entity): ServerPartEntity { //부품정보 정의 $partEntity = $this->getPartService()->getEntity($entity->getPartInfoUID()); if ($entity) { $entity->setPartEntity($partEntity); } return $entity; } //기본 기능부분 // FieldForm관련용 public function getFormFieldOption(string $field, array $options = []): array { switch ($field) { case 'partinfo_uid_CPU': $options = $this->getPartService()->getEntities(['type' => 'CPU']); break; case 'partinfo_uid_RAM': $options = $this->getPartService()->getEntities(['type' => 'RAM']); break; case 'partinfo_uid_DISK': $options = $this->getPartService()->getEntities(['type' => 'DISK']); break; case 'partinfo_uid_OS': $options = $this->getPartService()->getEntities(['type' => 'OS']); break; case 'partinfo_uid_DB': $options = $this->getPartService()->getEntities(['type' => 'DB']); break; case 'partinfo_uid_SOFTWARE': $options = $this->getPartService()->getEntities(['type' => 'SOFTWARE']); break; case 'partinfo_uid': //수정때문에 전체가 필요 $options = $this->getPartService()->getEntities(); break; default: $options = parent::getFormFieldOption($field, $options); break; } return $options; } //서버별 부품연결정보 생성 private function createByServer_process(ServerEntity $serverEntity, string $partType, array $formDatas): ServerPartEntity { $serverPartFormDatas = [ "partinfo_uid" => $formDatas["partinfo_uid_{$partType}"], "serverinfo_uid" => $serverEntity->getPK(), "serviceinfo_uid" => $serverEntity->getServiceInfoUID(), "type" => $partType, "billing" => array_key_exists("serverinfopartinfo_uid_{$partType}_billing", $formDatas) ? $formDatas["serverinfopartinfo_uid_{$partType}_billing"] : null, "amount" => array_key_exists("serverinfopartinfo_uid_{$partType}_amount", $formDatas) ? $formDatas["serverinfopartinfo_uid_{$partType}_amount"] : 0, "cnt" => array_key_exists("serverinfopartinfo_uid_{$partType}_cnt", $formDatas) ? $formDatas["serverinfopartinfo_uid_{$partType}_cnt"] : null, "extra" => array_key_exists("serverinfopartinfo_uid_{$partType}_extra", $formDatas) ? $formDatas["serverinfopartinfo_uid_{$partType}_extra"] : null ]; $entity = parent::create($serverPartFormDatas); //부품정보 정의 $partEntity = $this->getPartService()->getEntity($entity->getPartInfoUID()); if ($partEntity) { $entity->setPartEntity($partEntity); } return $entity; } //생성 public function createByServer(ServerEntity $serverEntity, array $formDatas): array { $entities = []; foreach (SERVER['PARTTYPES'] as $partType) { //파트정보 선택했는지 여부에따라 처리 if (array_key_exists("partinfo_uid_{$partType}", $formDatas) && $formDatas["partinfo_uid_{$partType}"]) { $entities[] = $this->createByServer_process($serverEntity, $partType, $formDatas); } } return $entities; } //수정 public function modifyByServer(ServerEntity $serverEntity, array $formDatas): array { //기존 서벼별 부품연결정보 삭제 후 $entities = $this->getEntities(['serverinfo_uid' => $serverEntity->getPK()]); foreach ($entities as $entity) { $this->delete($entity); } //서버별 부품연결정보 생성 return $this->createByServer($serverEntity, $formDatas); } }