dbmsv2 init...1

This commit is contained in:
choi.jh 2025-09-15 18:48:12 +09:00
parent 93e82b1104
commit 6889d58063
10 changed files with 90 additions and 124 deletions

View File

@ -3,6 +3,7 @@
namespace App\Cells\Equipment; namespace App\Cells\Equipment;
use App\Entities\Equipment\ServerEntity;
use App\Services\Equipment\ServerPartService; use App\Services\Equipment\ServerPartService;
use App\Services\Equipment\ServerService; use App\Services\Equipment\ServerService;
@ -24,40 +25,37 @@ class ServerPartCell extends EquipmentCell
public function parttable(array $params): string 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)) { 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']); $serverEntity = $this->getServerService()->getEntity($params['serverinfo_uid']);
if (!$serverEntity) { if ($serverEntity instanceof ServerEntity) {
return "[{$params['serverinfo_uid']}]에 해당하는 서버정보가 지정되지 않았거나 존재하지 않습니다."; //서버파트정보
} $serverPartEntities = $this->getService()->getEntities(['serverinfo_uid' => $serverEntity->getPK(),]);
//서버파트정보 foreach ($serverPartEntities as $entity) {
$serverPartEntities = $this->getService()->getEntities(['serverinfo_uid' => $serverEntity->getPK(),]); if (!array_key_exists($entity->getType(), $entities)) {
$entities = []; $entities[$entity->getType()] = [];
foreach ($serverPartEntities as $entity) { }
if (!array_key_exists($entity->getType(), $entities)) { $entities[$entity->getType()][] = $entity;
$entities[$entity->getType()] = [];
} }
$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'],
],
]);
} }
} }

View File

@ -6,12 +6,12 @@ use CodeIgniter\Entity\Entity;
abstract class CommonEntity extends Entity abstract class CommonEntity extends Entity
{ {
const DEFAULT_STATUS = "";
protected $datamap = []; protected $datamap = [];
protected $dates = ['created_at', 'updated_at', 'deleted_at']; protected $dates = ['created_at', 'updated_at', 'deleted_at'];
//사용법 : $client->created_at->format('Y-m-d') //사용법 : $client->created_at->format('Y-m-d')
//비교방법 : if ($client->created_at < new \DateTime('2024-01-01')) { //비교방법 : if ($client->created_at < new \DateTime('2024-01-01')) {
protected $casts = []; protected $casts = [];
public function __construct(array|null $data = null) public function __construct(array|null $data = null)
{ {
parent::__construct($data); parent::__construct($data);

View File

@ -8,8 +8,6 @@ class ServerPartEntity extends EquipmentEntity
{ {
const PK = ServerPartModel::PK; const PK = ServerPartModel::PK;
const TITLE = ServerPartModel::TITLE; const TITLE = ServerPartModel::TITLE;
const DEFAULT_STATUS = null;
public function setPartEntity(mixed $entity): ServerPartEntity public function setPartEntity(mixed $entity): ServerPartEntity
{ {
$this->attributes['partEntity'] = $entity; $this->attributes['partEntity'] = $entity;
@ -56,4 +54,8 @@ class ServerPartEntity extends EquipmentEntity
{ {
return $this->attributes['extra'] ?? ""; return $this->attributes['extra'] ?? "";
} }
public function getStatus(): string
{
return self::DEFAULT_STATUS;
}
} }

View File

@ -1,10 +0,0 @@
<?php
namespace App\Entities;
class FormOptionEntity extends CommonEntity
{
const PK = "uid";
const TITLE = "title";
const DEFAULT_STATUS = null;
}

View File

@ -2,6 +2,8 @@
namespace App\Helpers; namespace App\Helpers;
use App\Entities\CommonEntity;
class CommonHelper class CommonHelper
{ {
private $_myAuth = null; private $_myAuth = null;
@ -231,16 +233,22 @@ class CommonHelper
$html = ""; $html = "";
switch ($field) { switch ($field) {
default: default:
foreach ($viewDatas['control']['field_optons'][$field] as $key => $entity) { foreach ($viewDatas['control']['field_optons'][$field] as $option_key => $option_value) {
$isSelected = $key == $value ? ' selected' : ''; $isSelected = $option_key == $value ? ' selected' : '';
$isDisabled = ""; $isDisabled = "";
$attribute = ""; $attribute = "";
foreach ($attributes as $attribute_tag => $attribute_value) { $label = "";
$attribute .= sprintf(" %s=\"%s\"", $attribute_tag, $attribute_value); 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 ? "서비스중." : ""; $html .= sprintf("<option value=\"%s\"%s%s%s>%s</option>", $option_key, $isSelected, $isDisabled, $attribute, $label);
$title .= $entity->getCustomTitle();
$html .= sprintf("<option value=\"%s\"%s%s%s>%s</option>", $key, $isSelected, $isDisabled, $attribute, $title);
} }
break; break;
} }

View File

@ -12,34 +12,6 @@ class ServiceHelper extends CustomerHelper
parent::__construct(); parent::__construct();
$this->setTitleField(field: ServiceModel::TITLE); $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("<option value=\"%s\"%s%s%s>%s</option>", $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 public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
{ {
switch ($field) { switch ($field) {

View File

@ -2,7 +2,7 @@
namespace App\Helpers\Equipment; namespace App\Helpers\Equipment;
use App\Entities\Equipment\PartEntity; use App\Entities\CommonEntity;
use App\Models\Equipment\ServerPartModel; use App\Models\Equipment\ServerPartModel;
class ServerPartHelper extends EquipmentHelper class ServerPartHelper extends EquipmentHelper
@ -17,21 +17,22 @@ class ServerPartHelper extends EquipmentHelper
$html = ""; $html = "";
switch ($field) { switch ($field) {
case 'part_uid': case 'part_uid':
$attribute = ""; foreach ($viewDatas['control']['field_optons'][$field] as $option_key => $option_value) {
foreach ($viewDatas['control']['field_optons'][$field] as $key => $entity) { $isSelected = $option_key == $value ? ' selected' : '';
$isSelected = $key == $value ? ' selected' : ''; $isDisabled = "";
$isDisabled = ""; $attribute = "";
if (in_array($viewDatas['control']['action'], ['create_form', 'index'])) { $label = "";
if ($entity->getStatus() != $entity::DEFAULT_STATUS) if ($option_value instanceof CommonEntity) {
$isDisabled = " disabled"; 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 = ""; $html .= sprintf("<option value=\"%s\"%s%s%s>%s</option>", $option_key, $isSelected, $isDisabled, $attribute, $label);
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("<option value=\"%s\"%s%s%s>%s</option>", $key, $isSelected, $isDisabled, $attribute, $title);
} }
break; break;
default: default:
@ -65,6 +66,7 @@ class ServerPartHelper extends EquipmentHelper
$form = parent::getFieldForm($field, $value, $viewDatas, $extras); $form = parent::getFieldForm($field, $value, $viewDatas, $extras);
break; break;
} }
echo "Field:{$field}";
return $form; return $form;
} }
public function getFieldView(string $field, mixed $value, array $viewDatas, array $extras = []): string|null public function getFieldView(string $field, mixed $value, array $viewDatas, array $extras = []): string|null

View File

@ -235,14 +235,7 @@ abstract class CommonService
{ {
switch ($field) { switch ($field) {
default: default:
$formOptionDatas = lang($this->getClassName() . '.' . strtoupper($field)); $options = 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]);
}
break; break;
} }
if (!is_array($options)) { if (!is_array($options)) {

View File

@ -57,8 +57,8 @@ class ServerPartService extends EquipmentService
{ {
return [ return [
"serverinfo_uid", "serverinfo_uid",
"type",
"part_uid", "part_uid",
"type",
"billing", "billing",
]; ];
} }
@ -122,29 +122,30 @@ class ServerPartService extends EquipmentService
{ {
switch ($field) { switch ($field) {
case 'part_uid': case 'part_uid':
$type = $this->getFormDatas()['type'] ?? null; $partOptions = [];
switch ($type) { foreach (SERVERPART['PARTTYPES'] as $partType) {
case 'CPU': switch ($partType) {
case 'RAM': case 'CPU':
case 'DISK': case 'RAM':
case 'OS': case 'DISK':
case 'DB': case 'OS':
case 'SOFTWARE': case 'DB':
$options = $this->getPartService()->getEntities(['type' => $type]); case 'SOFTWARE':
break; $partOptions[$partType] = $this->getPartService()->getEntities(['type' => $partType]);
case 'SWITCH': break;
$options = $this->getSwitchService()->getEntities(); case 'SWITCH':
break; $partOptions[$partType] = $this->getSwitchService()->getEntities();
case 'IP': break;
$options = $this->getIPService()->getEntities(); case 'IP':
break; $partOptions[$partType] = $this->getIPService()->getEntities();
case 'CS': break;
$options = $this->getCSService()->getEntities(); case 'CS':
break; $partOptions[$partType] = $this->getCSService()->getEntities();
default: break;
$options = []; }
break;
} }
$options = $partOptions;
// dd($options);
break; break;
default: default:
$options = parent::getFormOption($field, $options); $options = parent::getFormOption($field, $options);

View File

@ -1,4 +1,4 @@
<?php $htmls = $texts = [$serverPartCellDatas['serverEntity']->getCode()] ?> <?php $htmls = $texts = [!$serverPartCellDatas['serverEntity'] ? "" : $serverPartCellDatas['serverEntity']->getCode()] ?>
<?php foreach (['SWITCH', 'IP', 'OS'] as $type): ?> <?php foreach (['SWITCH', 'IP', 'OS'] as $type): ?>
<?php $texts[] = $serverPartCellDatas['service']->getHelper()->getFieldView($type, '', $serverPartCellDatas, ['return_type' => 'text']); ?> <?php $texts[] = $serverPartCellDatas['service']->getHelper()->getFieldView($type, '', $serverPartCellDatas, ['return_type' => 'text']); ?>
<?php $button = $serverPartCellDatas['service']->getHelper()->getListButton($type, '', $serverPartCellDatas) ?> <?php $button = $serverPartCellDatas['service']->getHelper()->getListButton($type, '', $serverPartCellDatas) ?>