dbmsv2 init...1

This commit is contained in:
choi.jh 2025-08-26 18:42:05 +09:00
parent 9f236f1ed3
commit 9c5371bcaa
8 changed files with 99 additions and 142 deletions

View File

@ -40,19 +40,6 @@ class ServerController extends EquipmentController
}
//Index,FieldForm관련
protected function getResultSuccess(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string
{
switch ($this->getAction()) {
case 'index':
case 'view':
$result = parent::getResultSuccess($message, $this->request->getVar('ActionTemplate') ?? $actionTemplate ?? 'server');
break;
default:
$result = parent::getResultSuccess($message, $actionTemplate);
break;
}
return $result;
}
//생성
protected function create_form_process(): void
{
@ -90,4 +77,21 @@ class ServerController extends EquipmentController
$this->serverPartEntities = $this->getService()->createServerParts($entity, $partDatas);
return $entity;
}
protected function index_process(array $entities = []): array
{
// //부품정보 FormOption 설정용
// $this->serverBaseParts = $this->getService()::BaseParts;
// foreach ($this->getService()::BaseParts as $basePart) {
// $this->setFormFieldOptions("partinfo_{$basePart}_uid", $this->getFormFieldOption_process("partinfo_{$basePart}_uid"));
// }
//
foreach (parent::index_process($entities) as $entity) {
//서버 부품정보 정의
$entity->setServerParts($this->getService()->getServerParts($entity));
//서버 IP정보 정의
//서버 CS정보 정의
$entities[] = $entity;
}
return $entities;
}
}

View File

@ -102,20 +102,17 @@ abstract class CommonController extends BaseController
//Filters 정의
$this->setControlDatas('actionFilters', array_key_exists('filters', $actionFields) ? $actionFields['filters'] : []);
//Field Rule정의
$temps = [];
foreach ($this->getControlDatas('actionFields') as $field) {
$temps[$field] = $this->getFormFieldRule_process($this->getAction(), $field);
$this->setFormFielRule($field, $this->getFormFieldRule_process($this->getAction(), $field));
}
$this->setControlDatas('field_rules', $temps);
//Form용 Options정의
$temps = [];
foreach ($this->getControlDatas('actionFilters') as $field) {
$temps[$field] = [];
foreach ($this->getFormFieldOption_process($field) as $option) {
$temps[$field][$option->getPK()] = $option;
$options = [];
foreach ($this->getFormFieldOption_process($field) as $entity) {
$options[$entity->getPK()] = $entity;
}
$this->setFormFieldOptions($field, $options);
}
$this->setControlDatas('filter_optons', $temps);
//일괄작업용 Fields정의
$this->setControlDatas(
'batchjob_fields',
@ -127,6 +124,22 @@ abstract class CommonController extends BaseController
array_key_exists('batchjob_buttions', $actionFields) ? $actionFields['batchjob_buttions'] : $this->getService()->getBatchjobButtons()
);
}
//FormRules정의
final protected function setFormFielRule($field, string $rule)
{
//기존 Filter Rules 가져와서 field에 해당하는 rule이 없으면 field를 filter_rules 전체 적용
$allRules = $this->getControlDatas('field_rules') ?? [];
$allRules[$field] = $rule;
$this->setControlDatas('field_rules', $allRules);
}
//FormOptions정의
final protected function setFormFieldOptions($field, array $options)
{
//기존 Filter Options 가져와서 field에 해당하는 option이 없으면 field를 key로 배열추가 후 다시 filter_options 전체 적용
$allOptions = $this->getControlDatas('filter_optons') ?? [];
$allOptions[$field] = $options;
$this->setControlDatas('filter_optons', $allOptions);
}
//전체 FormDatas 전달값받기
final protected function getFormDatas(array $fields, array $requestDatas, array $formDatas = []): array
{

View File

@ -25,4 +25,13 @@ class ServerEntity extends EquipmentEntity
{
return $this->attributes['serviceinfo_uid'] ?? null;
}
public function setServerParts(array $datas): void
{
$this->attributes['server_parts'] = $datas;
}
public function getServerParts(): array
{
return $this->attributes['server_parts'] ?? [];
}
}

View File

@ -307,8 +307,13 @@ class CommonHelper
}
$value = implode(" , ", $roles);
break;
case 'created_at':
case 'issue_at':
case 'expired_at':
case 'billing_at':
case 'start_at':
case 'end_at':
case 'updated_at':
case 'created_at':
case 'deleted_at':
$value = $value ? date("Y-m-d", strtotime($value)) : "";
break;

View File

@ -21,8 +21,10 @@ class ServerHelper extends EquipmentHelper
break;
case 'partinfo_cpu_uid':
case 'partinfo_ram_uid':
case 'partinfo_software_uid':
case 'partinfo_disk_uid':
case 'partinfo_software_uid':
case 'partinfo_os_uid':
case 'partinfo_db_uid':
$form = $this->form_dropdown_custom($field, $value, $viewDatas, $extras);
$form .= " " . form_dropdown("{$field}_cnt", $viewDatas['partinfo_cnt_range'], $value ?? 1) . "";
if ($field === 'partinfo_disk_uid') {
@ -43,6 +45,31 @@ class ServerHelper extends EquipmentHelper
}
return $form;
}
public function getFieldView(string $field, mixed $value, array $viewDatas, array $extras = []): string|null
{
switch ($field) {
case 'manufactur_at':
case 'format_at':
$value = $value ? date("Y-m-d", strtotime($value)) : "";
break;
case 'partinfo_uid':
$value = "";
foreach ($viewDatas['entity']->getServerParts() as $part) {
// $value .= "<div>" . $this->getFieldForm("partinfo_" . strtolower($part->type) . "_uid", $part->partinfo_uid, $viewDatas, $extras) . "</div>";
$value .= sprintf("<div>%s%s %s</div>", $part->title, $part->cnt > 1 ? "*" . $part->cnt . "" : "", $part->extra ?? "");
}
// dd($value);
break;
default:
$value = parent::getFieldView($field, $value, $viewDatas, $extras);
break;
}
if (is_array($value)) {
echo __METHOD__ . "에서 오류: {$field}의 값이 Array형태입니다";
exit;
}
return $value;
}
public function getListFilter(string $field, mixed $value, array $viewDatas, array $extras = []): string
{
switch ($field) {

View File

@ -14,7 +14,6 @@ class ServerService extends EquipmentService
private ?CSService $_csService = null;
private ?ServerPartModel $_serverPartModel = null;
const BaseParts = ['cpu', 'ram', 'disk', 'os'];
const AddtionalParts = ['ram', 'disk', 'db', 'software', 'ip', 'cs'];
public function __construct()
{
parent::__construct(new ServerModel());
@ -32,6 +31,7 @@ class ServerService extends EquipmentService
"partinfo_disk_uid",
"partinfo_os_uid",
"price",
"amount",
"manufactur_at",
"format_at",
"status",
@ -55,10 +55,11 @@ class ServerService extends EquipmentService
'fields' => [
'clientinfo_uid',
'serviceinfo_uid',
'partinfo_uid',
"type",
'title',
"partinfo_uid",
'price',
'amount',
'manufactur_at',
"format_at",
'status'
@ -104,34 +105,22 @@ class ServerService extends EquipmentService
{
switch ($field) {
case 'partinfo_cpu_uid':
$options = $this->getPartService()->getEntities([
'type' => 'CPU'
]);
$options = $this->getPartService()->getEntities(['type' => 'CPU']);
break;
case 'partinfo_ram_uid':
$options = $this->getPartService()->getEntities([
'type' => 'RAM'
]);
$options = $this->getPartService()->getEntities(['type' => 'RAM']);
break;
case 'partinfo_disk_uid':
$options = $this->getPartService()->getEntities([
'type' => 'DISK'
]);
$options = $this->getPartService()->getEntities(['type' => 'DISK']);
break;
case 'partinfo_os_uid':
$options = $this->getPartService()->getEntities([
'type' => 'OS'
]);
$options = $this->getPartService()->getEntities(['type' => 'OS']);
break;
case 'partinfo_db_uid':
$options = $this->getPartService()->getEntities([
'type' => 'DB'
]);
$options = $this->getPartService()->getEntities(['type' => 'DB']);
break;
case 'partinfo_software_uid':
$options = $this->getPartService()->getEntities([
'type' => 'SOFTWARE'
]);
$options = $this->getPartService()->getEntities(['type' => 'SOFTWARE']);
break;
case 'partinfo_uid': //수정때문에 전체가 필요
$options = $this->getPartService()->getEntities();
@ -154,6 +143,7 @@ class ServerService extends EquipmentService
return $this->getModel()->getLastestCode($format, $default);
}
//Server Part별 저장
public function createServerParts(ServerEntity $entity, array $partDatas): array
{
$serverPartEntities = [];
@ -162,9 +152,16 @@ class ServerService extends EquipmentService
$partDatas[$basePart]["serviceinfo_uid"] = $entity->getServiceInfoUID();
$serverPartEntities[] = $this->getServerPartModel()->create($partDatas[$basePart]);
}
// dd($serverPartEntities);
return $serverPartEntities;
}
//Server Part별 정보가져오기
public function getServerParts(ServerEntity $entity): array
{
$sql = "SELECT serverinfo_partinfo.*,partinfo.title as title,partinfo.price,partinfo.type FROM serverinfo_partinfo
LEFT JOIN partinfo ON serverinfo_partinfo.partinfo_uid = partinfo.uid
WHERE serverinfo_partinfo.serverinfo_uid = ?";
return $this->getModel()->query($sql, [$entity->getPK()])->getResult();
}
//List 검색용
//OrderBy 처리

View File

@ -1,70 +0,0 @@
<?= $this->extend(LAYOUTS[$viewDatas['layout']]['path']) ?>
<?= $this->section('content') ?>
<?php if ($error = session('error')): echo $viewDatas['helper']->alert($error) ?><?php endif ?>
<div class="layout_top"><?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/top'); ?></div>
<!-- Layout Middle Start -->
<table class="layout_middle">
<tr>
<td class="layout_left">
<!-- Layout Left Start -->
<?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/left_menu'); ?>
<!-- Layout Left End -->
</td>
<td class="layout_right">
<!-- Layout Right Start -->
<div class="layout_header"><?= $this->include("templates/{$viewDatas['layout']}/index_header"); ?></div>
<div id="container" class="layout_content">
<link href="/css/<?= $viewDatas['layout'] ?>/index.css" media="screen" rel="stylesheet" type="text/css" />
<div class="index_body">
<?= $this->include("templates/{$viewDatas['layout']}/index_content_top"); ?>
<?= form_open(current_url(), ['id' => 'batchjob_form', 'method' => "post"]) ?>
<table class="index_table data table table-bordered table-hover table-striped" data-rtc-resizable-table="reisze_table">
<thead>
<tr>
<th class="index_head_short_column">번호</th>
<?php foreach ($viewDatas['control']['actionFields'] as $field): ?>
<th data-rtc-resizable="<?= $field ?>"><?= $viewDatas['helper']->getListLabel($field, lang("{$viewDatas['class_path']}.label.{$field}"), $viewDatas) ?></th>
<?php endforeach ?>
<th class="index_head_short_column">작업</th>
</tr>
</thead>
<tbody>
<?php $cnt = 0 ?>
<?php foreach ($viewDatas['entities'] as $entity): ?>
<?php $viewDatas['entity'] = $entity; ?>
<tr <?= $viewDatas['helper']->getListRowColor($entity) ?>>
<?php $viewDatas['cnt'] = $viewDatas['total_count'] - (($viewDatas['page'] - 1) * $viewDatas['per_page'] + $cnt); ?>
<td nowrap><?= $viewDatas['helper']->getListButton('modify', '', $viewDatas) ?></td>
<?php foreach ($viewDatas['control']['actionFields'] as $field): ?>
<td><?= $viewDatas['helper']->getFieldView($field, $entity->$field, $viewDatas) ?></td>
<?php endforeach ?>
<td nowrap>
<?= $viewDatas['helper']->getListButton('view', '', $viewDatas) ?>&nbsp;
<?= $viewDatas['helper']->getListButton('history', '', $viewDatas) ?>&nbsp;
<?= $viewDatas['helper']->getListButton('delete', '', $viewDatas) ?>
</td>
</tr>
<tr>
<td colspan="<?= count($viewDatas['control']['actionFields']) + 2 ?>">
<table class="table table-bordered table-hover table-striped">
<tr><?php foreach (SERVER_LINK_ITEMS as $item_type => $label): ?><th data-rtc-resizable="<?= $item_type ?>" nowrap><?= $viewDatas['helper']->getFieldLabel($item_type, $label, $viewDatas) ?></th><?php endforeach ?></tr>
<tr><?php foreach (SERVER_LINK_ITEMS as $item_type => $label): ?><td class="text-nowrap"><?= $viewDatas['helper']->getFieldView($item_type, $entity->$item_type, $viewDatas) ?></td><?php endforeach ?></tr>
</table>
</td>
</tr>
<?php $cnt++ ?>
<?php endforeach ?>
</tbody>
</table>
<?= $this->include("templates/{$viewDatas['layout']}/index_content_bottom"); ?>
<?= form_close() ?>
</div>
</div>
<div class="layout_footer"><?= $this->include("templates/{$viewDatas['layout']}/index_footer"); ?></div>
<!-- Layout Right End -->
</td>
</tr>
</table>
<!-- Layout Middle End -->
<div class="layout_bottom"><?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/bottom'); ?></div>
<?= $this->endSection() ?>

View File

@ -1,28 +0,0 @@
<?= $this->extend(LAYOUTS[$viewDatas['layout']]['path']) ?>
<?= $this->section('content') ?>
<?php if ($error = session('error')): echo $viewDatas['helper']->alert($error) ?><?php endif ?>
<div id="container" class="content action_form">
<div class="row">
<div class="col-sm-4">
<table class="table table-bordered">
<?php foreach ($viewDatas['control']['actionFields'] as $field): ?>
<tr>
<th nowrap class="text-end" width="15%"><?= $viewDatas['helper']->getFieldLabel($field, lang("{$viewDatas['class_path']}.label.{$field}"), $viewDatas) ?></th>
<td nowrap class="text-start" width="15%"><?= $viewDatas['helper']->getFieldView($field, $viewDatas['entity']->$field, $viewDatas) ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
<div class="col-sm-8">
<table class="table table-bordered table-hover table-striped">
<?php foreach (SERVICE_ITEM_TYPES as $item_type => $label): ?>
<tr>
<th nowrap class="text-end" width="15%" data-rtc-resizable="<?= $item_type ?>" nowrap><?= $viewDatas['helper']->getFieldLabel($item_type, $label, $viewDatas) ?></th>
<td nowrap class="text-start"><?= $viewDatas['helper']->getFieldView($item_type, $viewDatas['entity']->$item_type, $viewDatas) ?></td>
</tr>
<?php endforeach ?>
</table>
</div>
</div>
</div>
<?= $this->endSection() ?>