addClassName('ServerPart'); } public function getFormFields(): array { return [ "serviceinfo_uid", "serverinfo_uid", "type", "partinfo_uid", "billing", "amount", "cnt", "extra", ]; } public function getFormFilters(): array { return [ "serviceinfo_uid", "serverinfo_uid", "type", "partinfo_uid", "billing", ]; } public function getBatchjobFields(): array { return ['billing', 'type', 'partinfo_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 getFormOption(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::getFormOption($field, $options); break; } return $options; } //생성 public function createByServer(ServerEntity $serverEntity, array $formDatas): ServerPartEntity { foreach (SERVER['PARTTYPES'] as $partType) { $serverPartFormDatas = []; $serverPartFormDatas["partinfo_uid"] = $formDatas["partinfo_uid_{$partType}"]; $serverPartFormDatas["serverinfo_uid"] = $serverEntity->getPK(); $serverPartFormDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID(); $serverPartFormDatas["type"] = $partType; $serverPartFormDatas["billing"] = array_key_exists("partinfo_uid_{$partType}_billing", $formDatas) ? $formDatas["partinfo_uid_{$partType}_billing"] : null; $serverPartFormDatas["amount"] = array_key_exists("partinfo_uid_{$partType}_amount", $formDatas) ? $formDatas["partinfo_uid_{$partType}_amount"] : 0; $serverPartFormDatas["cnt"] = array_key_exists("partinfo_uid_{$partType}_cnt", $formDatas) ? $formDatas["partinfo_uid_{$partType}_cnt"] : null; $serverPartFormDatas["extra"] = array_key_exists("partinfo_uid_{$partType}_extra", $formDatas) ? $formDatas["partinfo_uid_{$partType}_extra"] : null; $entity = parent::create($serverPartFormDatas); //부품정보 정의 $partEntity = $this->getPartService()->getEntity($entity->getPartInfoUID()); if ($partEntity) { $entity->setPartEntity($partEntity); } } return $entity; } //삭제 public function deleteByServer(ServerEntity $serverEntity): void { //기존 서벼별 부품연결정보 삭제 후 foreach ($this->getEntities(['serverinfo_uid' => $serverEntity->getPK()]) as $entity) { $this->delete($entity); } } }