diff --git a/app/Cells/Equipment/ServerPartCell.php b/app/Cells/Equipment/ServerPartCell.php
index 4430514..b0e2023 100644
--- a/app/Cells/Equipment/ServerPartCell.php
+++ b/app/Cells/Equipment/ServerPartCell.php
@@ -3,6 +3,7 @@
namespace App\Cells\Equipment;
+use App\Entities\Equipment\ServerEntity;
use App\Services\Equipment\ServerPartService;
use App\Services\Equipment\ServerService;
@@ -24,40 +25,37 @@ class ServerPartCell extends EquipmentCell
public function parttable(array $params): string
{
- $result = "";
+ $this->getService()->setAction(__FUNCTION__);
+ $this->getService()->setFormFields();
+ $this->getService()->setFormFilters();
+ $this->getService()->setFormRules();
+ $this->getService()->setFormOptions();
+ $entities = [];
+ $serverEntity = null;
if (array_key_exists('serverinfo_uid', $params)) {
- $this->getService()->setAction(__FUNCTION__);
- $this->getService()->setFormFields();
- $this->getService()->setFormFilters();
- $this->getService()->setFormRules();
- $this->getService()->setFormOptions();
- // dd($params);
//서버정보
$serverEntity = $this->getServerService()->getEntity($params['serverinfo_uid']);
- if (!$serverEntity) {
- return "[{$params['serverinfo_uid']}]에 해당하는 서버정보가 지정되지 않았거나 존재하지 않습니다.";
- }
- //서버파트정보
- $serverPartEntities = $this->getService()->getEntities(['serverinfo_uid' => $serverEntity->getPK(),]);
- $entities = [];
- foreach ($serverPartEntities as $entity) {
- if (!array_key_exists($entity->getType(), $entities)) {
- $entities[$entity->getType()] = [];
+ if ($serverEntity instanceof ServerEntity) {
+ //서버파트정보
+ $serverPartEntities = $this->getService()->getEntities(['serverinfo_uid' => $serverEntity->getPK(),]);
+ foreach ($serverPartEntities as $entity) {
+ if (!array_key_exists($entity->getType(), $entities)) {
+ $entities[$entity->getType()] = [];
+ }
+ $entities[$entity->getType()][] = $entity;
}
- $entities[$entity->getType()][] = $entity;
}
- $template = array_key_exists('template', $params) ? $params['template'] : __FUNCTION__;
- $result = view('cells/serverpart/' . $template, [
- 'serverPartCellDatas' => [
- 'control' => $this->getService()->getControlDatas(),
- 'service' => $this->getService(),
- 'serverinfo_uid' => $params['serverinfo_uid'],
- 'entities' => $entities,
- 'serverEntity' => $serverEntity,
- 'types' => $params['types'],
- ],
- ]);
}
- return $result;
+ $template = array_key_exists('template', $params) ? $params['template'] : __FUNCTION__;
+ return view('cells/serverpart/' . $template, [
+ 'serverPartCellDatas' => [
+ 'control' => $this->getService()->getControlDatas(),
+ 'service' => $this->getService(),
+ 'serverinfo_uid' => $params['serverinfo_uid'],
+ 'entities' => $entities,
+ 'serverEntity' => $serverEntity,
+ 'types' => $params['types'],
+ ],
+ ]);
}
}
diff --git a/app/Entities/CommonEntity.php b/app/Entities/CommonEntity.php
index 6320de3..31d6e3f 100644
--- a/app/Entities/CommonEntity.php
+++ b/app/Entities/CommonEntity.php
@@ -6,12 +6,12 @@ use CodeIgniter\Entity\Entity;
abstract class CommonEntity extends Entity
{
+ const DEFAULT_STATUS = "";
protected $datamap = [];
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
//사용법 : $client->created_at->format('Y-m-d')
//비교방법 : if ($client->created_at < new \DateTime('2024-01-01')) {
protected $casts = [];
-
public function __construct(array|null $data = null)
{
parent::__construct($data);
diff --git a/app/Entities/Equipment/ServerPartEntity.php b/app/Entities/Equipment/ServerPartEntity.php
index ca9d718..707bfd5 100644
--- a/app/Entities/Equipment/ServerPartEntity.php
+++ b/app/Entities/Equipment/ServerPartEntity.php
@@ -8,8 +8,6 @@ class ServerPartEntity extends EquipmentEntity
{
const PK = ServerPartModel::PK;
const TITLE = ServerPartModel::TITLE;
- const DEFAULT_STATUS = null;
-
public function setPartEntity(mixed $entity): ServerPartEntity
{
$this->attributes['partEntity'] = $entity;
@@ -56,4 +54,8 @@ class ServerPartEntity extends EquipmentEntity
{
return $this->attributes['extra'] ?? "";
}
+ public function getStatus(): string
+ {
+ return self::DEFAULT_STATUS;
+ }
}
diff --git a/app/Entities/FormOptionEntity.php b/app/Entities/FormOptionEntity.php
deleted file mode 100644
index 2462e45..0000000
--- a/app/Entities/FormOptionEntity.php
+++ /dev/null
@@ -1,10 +0,0 @@
- $entity) {
- $isSelected = $key == $value ? ' selected' : '';
+ foreach ($viewDatas['control']['field_optons'][$field] as $option_key => $option_value) {
+ $isSelected = $option_key == $value ? ' selected' : '';
$isDisabled = "";
$attribute = "";
- foreach ($attributes as $attribute_tag => $attribute_value) {
- $attribute .= sprintf(" %s=\"%s\"", $attribute_tag, $attribute_value);
+ $label = "";
+ if ($option_value instanceof CommonEntity) {
+ if (in_array($viewDatas['control']['action'], ['create_form', 'index'])) {
+ if ($option_value->getStatus() != $option_value::DEFAULT_STATUS)
+ $html = " disabled";
+ }
+ $label = $option_value->getStatus() != $option_value::DEFAULT_STATUS ? "X." : "";
+ $label .= $option_value->getCustomTitle();
+ } else {
+ $label = $option_value;
}
- $title = $entity->getStatus() != $entity::DEFAULT_STATUS ? "서비스중." : "";
- $title .= $entity->getCustomTitle();
- $html .= sprintf("", $key, $isSelected, $isDisabled, $attribute, $title);
+ $html .= sprintf("", $option_key, $isSelected, $isDisabled, $attribute, $label);
}
break;
}
diff --git a/app/Helpers/Customer/ServiceHelper.php b/app/Helpers/Customer/ServiceHelper.php
index 0c4bd72..012eab0 100644
--- a/app/Helpers/Customer/ServiceHelper.php
+++ b/app/Helpers/Customer/ServiceHelper.php
@@ -12,34 +12,6 @@ class ServiceHelper extends CustomerHelper
parent::__construct();
$this->setTitleField(field: ServiceModel::TITLE);
}
- protected function form_dropdown_common_process(string $field, mixed $value, array $viewDatas, array $extras = [], array $attributes = []): string
- {
- $html = "";
- switch ($field) {
- case 'serverinfo_uid':
- $attribute = "";
- foreach ($viewDatas['control']['field_optons'][$field] as $key => $entity) {
- $isSelected = $key == $value ? ' selected' : '';
- $isDisabled = "";
- if (in_array($viewDatas['control']['action'], ['create_form', 'index'])) {
- if ($entity->getStatus() != $entity::DEFAULT_STATUS)
- $isDisabled = " disabled";
- }
- $attribute = "";
- foreach ($attributes as $attribute_tag => $attribute_value) {
- $attribute .= sprintf(" %s=\"%s\"", $attribute_tag, $entity instanceof ServerEntity ? $entity->$attribute_value() : $attribute_value);
- }
- $title = $entity->getStatus() != $entity::DEFAULT_STATUS ? "서비스중." : "";
- $title .= $entity->getCustomTitle();
- $html .= sprintf("", $key, $isSelected, $isDisabled, $attribute, $title);
- }
- break;
- default:
- $html = parent::form_dropdown_common_process($field, $value, $viewDatas, $extras, $attributes);
- break;
- }
- return $html;
- }
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
{
switch ($field) {
diff --git a/app/Helpers/Equipment/ServerPartHelper.php b/app/Helpers/Equipment/ServerPartHelper.php
index 8607dcd..ecb8fea 100644
--- a/app/Helpers/Equipment/ServerPartHelper.php
+++ b/app/Helpers/Equipment/ServerPartHelper.php
@@ -2,7 +2,7 @@
namespace App\Helpers\Equipment;
-use App\Entities\Equipment\PartEntity;
+use App\Entities\CommonEntity;
use App\Models\Equipment\ServerPartModel;
class ServerPartHelper extends EquipmentHelper
@@ -17,21 +17,22 @@ class ServerPartHelper extends EquipmentHelper
$html = "";
switch ($field) {
case 'part_uid':
- $attribute = "";
- foreach ($viewDatas['control']['field_optons'][$field] as $key => $entity) {
- $isSelected = $key == $value ? ' selected' : '';
- $isDisabled = "";
- if (in_array($viewDatas['control']['action'], ['create_form', 'index'])) {
- if ($entity->getStatus() != $entity::DEFAULT_STATUS)
- $isDisabled = " disabled";
+ foreach ($viewDatas['control']['field_optons'][$field] as $option_key => $option_value) {
+ $isSelected = $option_key == $value ? ' selected' : '';
+ $isDisabled = "";
+ $attribute = "";
+ $label = "";
+ if ($option_value instanceof CommonEntity) {
+ if (in_array($viewDatas['control']['action'], ['create_form', 'index'])) {
+ if ($option_value->getStatus() != $option_value::DEFAULT_STATUS)
+ $html = " disabled";
+ }
+ $label = $option_value->getStatus() != $option_value::DEFAULT_STATUS ? "X." : "";
+ $label .= $option_value->getCustomTitle();
+ } else {
+ $label = $option_value;
}
- $attribute = "";
- foreach ($attributes as $attribute_tag => $attribute_value) {
- $attribute .= sprintf(" %s=\"%s\"", $attribute_tag, $entity instanceof PartEntity ? $entity->$attribute_value() : $attribute_value);
- }
- $title = $entity->getStatus() != $entity::DEFAULT_STATUS ? "서비스중." : "";
- $title .= $entity->getCustomTitle();
- $html .= sprintf("", $key, $isSelected, $isDisabled, $attribute, $title);
+ $html .= sprintf("", $option_key, $isSelected, $isDisabled, $attribute, $label);
}
break;
default:
@@ -65,6 +66,7 @@ class ServerPartHelper extends EquipmentHelper
$form = parent::getFieldForm($field, $value, $viewDatas, $extras);
break;
}
+ echo "Field:{$field}";
return $form;
}
public function getFieldView(string $field, mixed $value, array $viewDatas, array $extras = []): string|null
diff --git a/app/Services/CommonService.php b/app/Services/CommonService.php
index 65fed65..f513a28 100644
--- a/app/Services/CommonService.php
+++ b/app/Services/CommonService.php
@@ -235,14 +235,7 @@ abstract class CommonService
{
switch ($field) {
default:
- $formOptionDatas = lang($this->getClassName() . '.' . strtoupper($field));
- if (!is_array($formOptionDatas)) {
- throw new \Exception(__FUNCTION__ . "에서 {$field}}의 formOptionDatas 값이 array가 아닙니다.\n" . var_export($formOptionDatas, true));
- }
- $options = [];
- foreach ($formOptionDatas as $key => $value) {
- $options[$key] = new FormOptionEntity(['uid' => $key, 'title' => $value]);
- }
+ $options = lang($this->getClassName() . '.' . strtoupper($field));
break;
}
if (!is_array($options)) {
diff --git a/app/Services/Equipment/ServerPartService.php b/app/Services/Equipment/ServerPartService.php
index bcc9158..ecd604e 100644
--- a/app/Services/Equipment/ServerPartService.php
+++ b/app/Services/Equipment/ServerPartService.php
@@ -57,8 +57,8 @@ class ServerPartService extends EquipmentService
{
return [
"serverinfo_uid",
- "type",
"part_uid",
+ "type",
"billing",
];
}
@@ -122,29 +122,30 @@ class ServerPartService extends EquipmentService
{
switch ($field) {
case 'part_uid':
- $type = $this->getFormDatas()['type'] ?? null;
- switch ($type) {
- case 'CPU':
- case 'RAM':
- case 'DISK':
- case 'OS':
- case 'DB':
- case 'SOFTWARE':
- $options = $this->getPartService()->getEntities(['type' => $type]);
- break;
- case 'SWITCH':
- $options = $this->getSwitchService()->getEntities();
- break;
- case 'IP':
- $options = $this->getIPService()->getEntities();
- break;
- case 'CS':
- $options = $this->getCSService()->getEntities();
- break;
- default:
- $options = [];
- break;
+ $partOptions = [];
+ foreach (SERVERPART['PARTTYPES'] as $partType) {
+ switch ($partType) {
+ case 'CPU':
+ case 'RAM':
+ case 'DISK':
+ case 'OS':
+ case 'DB':
+ case 'SOFTWARE':
+ $partOptions[$partType] = $this->getPartService()->getEntities(['type' => $partType]);
+ break;
+ case 'SWITCH':
+ $partOptions[$partType] = $this->getSwitchService()->getEntities();
+ break;
+ case 'IP':
+ $partOptions[$partType] = $this->getIPService()->getEntities();
+ break;
+ case 'CS':
+ $partOptions[$partType] = $this->getCSService()->getEntities();
+ break;
+ }
}
+ $options = $partOptions;
+ // dd($options);
break;
default:
$options = parent::getFormOption($field, $options);
diff --git a/app/Views/cells/serverpart/part_service.php b/app/Views/cells/serverpart/part_service.php
index 85eea13..0a90203 100644
--- a/app/Views/cells/serverpart/part_service.php
+++ b/app/Views/cells/serverpart/part_service.php
@@ -1,4 +1,4 @@
-getCode()] ?>
+getCode()] ?>
getHelper()->getFieldView($type, '', $serverPartCellDatas, ['return_type' => 'text']); ?>
getHelper()->getListButton($type, '', $serverPartCellDatas) ?>