229 lines
10 KiB
PHP
229 lines
10 KiB
PHP
<?php
|
|
|
|
namespace App\Helpers\Equipment;
|
|
|
|
use App\Models\Equipment\ServerModel;
|
|
|
|
class ServerHelper extends EquipmentHelper
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->setTitleField(field: ServerModel::TITLE);
|
|
}
|
|
private function getServerPartForm(string $field, mixed $value, array $viewDatas, array $extras, string $partType): string
|
|
{
|
|
$form = "";
|
|
if (array_key_exists('entity', $viewDatas)) {
|
|
foreach ($viewDatas['entity']->getServerPartEntities($partType) as $serverPartEntity) {
|
|
//기존 입력화면에서 return 된것인지?
|
|
if ($value === null && $serverPartEntity !== null) {
|
|
$value = $serverPartEntity->getPartInfoUID();
|
|
}
|
|
$form .= $this->form_dropdown_custom($field, $value, $viewDatas, $extras);
|
|
}
|
|
} else {
|
|
$form .= $this->form_dropdown_custom($field, $value, $viewDatas, $extras);
|
|
}
|
|
return $form;
|
|
}
|
|
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
|
|
{
|
|
switch ($field) {
|
|
case 'code':
|
|
// $extras['readonly'] = in_array($viewDatas['control']['action'], ['modify_form']) ? ' readonly' : '';
|
|
$form = parent::getFieldForm($field, $value, $viewDatas, $extras);
|
|
break;
|
|
case 'switchinfo_uid':
|
|
if (array_key_exists('entity', $viewDatas)) {
|
|
$value = $viewDatas['entity']->getSwitchEntity() !== null ? $viewDatas['entity']->getSwitchEntity()->getPK() : $value;
|
|
}
|
|
$extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
|
|
$form = $this->form_dropdown_custom($field, $value, $viewDatas, $extras);
|
|
break;
|
|
case 'ipinfo_uid':
|
|
$extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
|
|
$form = "";
|
|
if (array_key_exists('entity', $viewDatas)) {
|
|
foreach ($viewDatas['entity']->getIPEntities() as $ipEntity) {
|
|
$form .= "<div>" . $this->form_dropdown_custom($field, $ipEntity->getPK(), $viewDatas, $extras) . "</div>";
|
|
}
|
|
}
|
|
$form .= $this->form_dropdown_custom($field, $value, $viewDatas, $extras);
|
|
break;
|
|
case 'csinfo_uid':
|
|
$extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
|
|
$form = "";
|
|
if (array_key_exists('entity', $viewDatas)) {
|
|
foreach ($viewDatas['entity']->getCSEntities() as $csEntity) {
|
|
$form .= "<div>" . $this->form_dropdown_custom($field, $csEntity->getPK(), $viewDatas, $extras) . "</div>";
|
|
}
|
|
}
|
|
$form .= $this->form_dropdown_custom($field, $value, $viewDatas, $extras);
|
|
break;
|
|
case 'manufactur_at':
|
|
case 'format_at':
|
|
$extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' calender' : 'calender';
|
|
$form = form_input($field, $value ?? "", $extras);
|
|
break;
|
|
case 'CPU':
|
|
$form = $this->getServerPartForm($field, $value, $viewDatas, $extras, 'CPU');
|
|
break;
|
|
case 'CPU_cnt':
|
|
$form = form_dropdown($field, $viewDatas['partinfo_cnt_options'], $value, $extras) . "개";
|
|
break;
|
|
case 'RAM':
|
|
$form = $this->getServerPartForm($field, $value, $viewDatas, $extras, 'RAM',);
|
|
break;
|
|
case 'RAM_cnt':
|
|
$form = form_dropdown($field, $viewDatas['partinfo_cnt_options'], $value, $extras) . "개";
|
|
break;
|
|
case 'DISK':
|
|
$form = $this->getServerPartForm($field, $value, $viewDatas, $extras, 'DISK');
|
|
break;
|
|
case 'DISK_cnt':
|
|
$form = form_dropdown($field, $viewDatas['partinfo_cnt_options'], $value, $extras) . "개";
|
|
break;
|
|
case 'DISK_extra':
|
|
$form = $this->form_dropdown_custom($field, $value, $viewDatas, $extras);
|
|
break;
|
|
case 'OS':
|
|
$form = $this->getServerPartForm($field, $value, $viewDatas, $extras, 'OS');
|
|
break;
|
|
case 'OS_cnt':
|
|
$form = form_dropdown($field, $viewDatas['partinfo_cnt_options'], $value, $extras) . "개";
|
|
break;
|
|
case 'DB':
|
|
$form = $this->getServerPartForm($field, $value, $viewDatas, $extras, 'DB');
|
|
break;
|
|
case 'DB_cnt':
|
|
$form = form_dropdown($field, $viewDatas['partinfo_cnt_options'], $value, $extras) . "개";
|
|
break;
|
|
case 'SOFTWARE':
|
|
$form = $this->getServerPartForm($field, $value, $viewDatas, $extras, 'SOFTWARE');
|
|
break;
|
|
case 'SOFTWARE_cnt':
|
|
$form = form_dropdown($field, $viewDatas['partinfo_cnt_options'], $value, $extras) . "개";
|
|
break;
|
|
default:
|
|
$form = parent::getFieldForm($field, $value, $viewDatas, $extras);
|
|
break;
|
|
}
|
|
return $form;
|
|
}
|
|
private function getServerPartView(string $field, mixed $value, array $viewDatas, array $extras): string
|
|
{
|
|
|
|
return $value;
|
|
}
|
|
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 'CPU':
|
|
case 'RAM':
|
|
case 'DISK':
|
|
case 'OS':
|
|
case 'DB':
|
|
case 'SOFTWARE':
|
|
$temps = [];
|
|
foreach ($viewDatas['entity']->getServerPartEntities($field) as $serverPartEntity) {
|
|
$modal = form_label(
|
|
ICONS['SETUP'],
|
|
$field,
|
|
[
|
|
"data-src" => "/admin/equipment/serverpart/modify/{$serverPartEntity->getPK()}?ActionTemplate=popup",
|
|
"data-bs-toggle" => "modal",
|
|
"data-bs-target" => "#index_action_form",
|
|
"class" => "btn btn-sm btn-outline btn-circle",
|
|
"target" => "_self"
|
|
]
|
|
);
|
|
$temps[] = sprintf(
|
|
"%s%s%s %s",
|
|
$modal,
|
|
$serverPartEntity->getTitle(),
|
|
$serverPartEntity->getCnt() >= 1 ? "*" . $serverPartEntity->getCnt() . "개" : "",
|
|
$serverPartEntity->getExtra() ?? ""
|
|
);
|
|
}
|
|
$value .= implode("<BR>", $temps);
|
|
break;
|
|
case 'ipinfo_uid':
|
|
foreach ($viewDatas['entity']->getIPEntities() as $ipEntity) {
|
|
$value .= sprintf("<div>%s%s %s</div>", $ipEntity->getTitle(), $ipEntity->getAmount());
|
|
}
|
|
break;
|
|
case 'csinfo_uid':
|
|
foreach ($viewDatas['entity']->getCSEntities() as $csEntity) {
|
|
$value .= sprintf("<div>%s%s %s</div>", $csEntity->getTitle(), $csEntity->getAmount());
|
|
}
|
|
break;
|
|
default:
|
|
$value = parent::getFieldView($field, $value, $viewDatas, $extras);
|
|
break;
|
|
}
|
|
if (is_array($value)) {
|
|
echo __METHOD__ . "에서 오류: {$field}의 값이 Array형태입니다";
|
|
exit;
|
|
}
|
|
return $value;
|
|
}
|
|
public function getListButton(string $action, string $label, array $viewDatas, array $extras = []): string
|
|
{
|
|
switch ($action) {
|
|
case 'modify':
|
|
if (!$this->getMyAuth()->isAccessRole(['security'])) {
|
|
$action = $viewDatas['entity']->getCode();
|
|
} else {
|
|
$action = parent::getListButton($action, $label ? $label : $viewDatas['entity']->getCode(), $viewDatas, $extras);
|
|
}
|
|
break;
|
|
case 'create':
|
|
case 'delete':
|
|
case 'batchjob':
|
|
case 'batchjob_delete':
|
|
$action = !$this->getMyAuth()->isAccessRole(['security']) ? "" : parent::getListButton($action, $label, $viewDatas, $extras);
|
|
break;
|
|
case 'history':
|
|
$extras = ["class" => "btn btn-outline btn-primary btn-circle", "target" => "_self", ...$extras];
|
|
$action = $label ? $label : form_label(
|
|
$label ? $label : ICONS['HISTORY'],
|
|
$action,
|
|
[
|
|
"data-src" => "/admin/customer/clienthistory?clientinfo_uid={$viewDatas['entity']->getPK()}",
|
|
"data-bs-toggle" => "modal",
|
|
"data-bs-target" => "#index_action_form",
|
|
...$extras
|
|
]
|
|
);
|
|
break;
|
|
case 'CPU':
|
|
case 'RAM':
|
|
case 'DISK':
|
|
case 'OS':
|
|
case 'DB':
|
|
case 'SOFTWARE':
|
|
$extras = ["class" => "btn btn-sm btn-outline btn-circle", "target" => "_self", ...$extras];
|
|
$action = form_label(
|
|
$label ? $label : ICONS['SETUP'],
|
|
$action,
|
|
[
|
|
"data-src" => "/admin/equipment/serverpart?serverinfo_uid={$viewDatas['entity']->getPK()}&type={$action}&ActionTemplate=popup",
|
|
"data-bs-toggle" => "modal",
|
|
"data-bs-target" => "#index_action_form",
|
|
...$extras
|
|
]
|
|
);
|
|
break;
|
|
default:
|
|
$action = parent::getListButton($action, $label, $viewDatas, $extras);
|
|
break;
|
|
}
|
|
return $action;
|
|
}
|
|
}
|