dbmsv4/app/Services/Part/DISKService.php
2025-12-16 15:25:23 +09:00

139 lines
4.8 KiB
PHP

<?php
namespace App\Services\Part;
use RuntimeException;
use App\Models\Part\DISKModel;
use App\Helpers\Part\DISKHelper;
use App\Forms\Part\DISKForm;
use App\Entities\Part\DISKEntity;
use App\Entities\Equipment\ServerPartEntity;
use App\Entities\CommonEntity;
use App\DTOs\Part\DISKDTO;
class DISKService extends PartType1Service
{
private $_form = null;
private $_helper = null;
public function __construct(DISKModel $model)
{
parent::__construct($model);
$this->addClassPaths('DISK');
}
public function getDTOClass(): string
{
return DISKDTO::class;
}
public function createDTO(array $formDatas): DISKDTO
{
return new DISKDTO($formDatas);
}
public function getEntityClass(): string
{
return DISKEntity::class;
}
public function getFormService(): DISKForm
{
if ($this->_form === null) {
$this->_form = new DISKForm();
$this->_form->setAttributes([
'pk_field' => $this->getPKField(),
'title_field' => $this->getTitleField(),
'table' => $this->model->getTable(),
'useAutoIncrement' => $this->model->useAutoIncrement(),
'class_path' => $this->getClassPaths(false)
]);
}
return $this->_form;
}
public function getHelper(): DISKHelper
{
if ($this->_helper === null) {
$this->_helper = new DISKHelper();
$this->_helper->setAttributes([
'pk_field' => $this->getPKField(),
'title_field' => $this->getTitleField(),
'table' => $this->model->getTable(),
'useAutoIncrement' => $this->model->useAutoIncrement(),
'class_path' => $this->getClassPaths(false)
]);
}
return $this->_helper;
}
public function action_init_process(string $action, array $formDatas = []): void
{
$fields = [
"title",
"price",
"stock",
];
$filters = [
"status",
];
$indexFilter = $filters;
$batchjobFilters = ['status'];
switch ($action) {
case 'create':
case 'create_form':
break;
case 'modify':
case 'modify_form':
$fields = [...$fields, "format", 'status'];
break;
case 'view':
$fields = [...$fields, "format", 'status', 'created_at'];
break;
case 'index':
case 'download':
$fields = [...$fields, "format", 'status', 'created_at'];
break;
}
$this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules($action, $fields);
$this->getFormService()->setFormFilters($filters);
$this->getFormService()->setFormOptions($action, $filters, $formDatas);
$this->getFormService()->setIndexFilters($indexFilter);
$this->getFormService()->setBatchjobFilters($batchjobFilters);
}
//기본 기능부분
protected function getEntity_process(mixed $entity): DISKEntity
{
return $entity;
}
//List 검색용
//FormFilter 조건절 처리
//검색어조건절처리
//OrderBy 처리
public function setOrderBy(mixed $field = null, mixed $value = null): void
{
$this->model->orderBy('title ASC');
parent::setOrderBy($field, $value);
}
//서버파트관련 작업
//파트정보가져오기
public function getPartEntityByServerPart(ServerPartEntity $serverPartEntity): DISKEntity
{
//IP정보에서 해당하는 IP가 있으면 가져와서 사용중인지 체크 후 수정
$entity = $this->getEntity($serverPartEntity->getPartUID());
if (!$entity instanceof DISKEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 {$serverPartEntity->getPartUID()}에 해당하는 DISKEntity정보를 찾을수없습니다.");
}
return $entity;
}
public function attachToServerPart(ServerPartEntity $serverPartEntity, array $formDatas = []): DISKEntity
{
/** @var DISKEntity $entity IDE에 entity type알려주기*/
$entity = parent::attachToServerPart($serverPartEntity, $formDatas);
return $entity;
}
public function detachFromServerPart(ServerPartEntity $serverPartEntity, array $formDatas = []): DiskEntity
{
/** @var DiskEntity $entity IDE에 entity type알려주기*/
$entity = $this->getPartEntityByServerPart($serverPartEntity);
$formDatas['format'] = $entity->getFormat() + $serverPartEntity->getCnt();
return parent::detachFromServerPart($serverPartEntity, $formDatas);
}
}