160 lines
6.3 KiB
PHP
160 lines
6.3 KiB
PHP
<?php
|
|
|
|
namespace App\Helpers\Equipment;
|
|
|
|
use App\Models\Equipment\ServerPartModel;
|
|
|
|
class ServerPartHelper extends EquipmentHelper
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->setTitleField(field: ServerPartModel::TITLE);
|
|
}
|
|
protected function form_dropdown_common_process(string $field, mixed $value, array $viewDatas, array $extras = [], array $attributes = []): string
|
|
{
|
|
switch ($field) {
|
|
case 'serverinfo_uid':
|
|
$html = "<option value=\"\">" . lang("{$viewDatas['class_path']}.label.{$field}") . " 선택" . "</option>";
|
|
foreach ($viewDatas['control']['field_optons'][$field] as $key => $entity) {
|
|
$isSelected = $key == $value ? ' selected' : '';
|
|
$html .= sprintf("<option value=\"%s\"%s>%s</option>", $key, $isSelected, $entity->getCustomTitle());
|
|
}
|
|
break;
|
|
default:
|
|
$html = parent::form_dropdown_common_process($field, $value, $viewDatas, $extras);
|
|
break;
|
|
}
|
|
return $html;
|
|
}
|
|
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
|
|
{
|
|
switch ($field) {
|
|
case 'SWITCH':
|
|
case 'IP':
|
|
case 'CS':
|
|
case 'CPU':
|
|
case 'RAM':
|
|
case 'DISK':
|
|
case 'DB':
|
|
case 'OS':
|
|
case 'SOFTWARE':
|
|
$extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
|
|
$form = $this->form_dropdown_common($field, $value, $viewDatas, $extras);
|
|
break;
|
|
case 'part_uid':
|
|
$extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
|
|
$form = $this->form_dropdown_common($field, $value, $viewDatas, $extras);
|
|
break;
|
|
default:
|
|
$form = parent::getFieldForm($field, $value, $viewDatas, $extras);
|
|
break;
|
|
}
|
|
return $form;
|
|
}
|
|
public function getFieldView(string $field, mixed $value, array $viewDatas, array $extras = []): string|null
|
|
{
|
|
switch ($field) {
|
|
case 'CPU':
|
|
case 'RAM':
|
|
case 'DISK':
|
|
case 'OS':
|
|
case 'DB':
|
|
case 'SOFTWARE':
|
|
case 'SWITCH':
|
|
case 'IP':
|
|
case 'CS':
|
|
if (!array_key_exists($field, $viewDatas['entities'])) {
|
|
return "";
|
|
}
|
|
$temps = [];
|
|
foreach ($viewDatas['entities'][$field] as $entity) {
|
|
$modal = form_label(
|
|
ICONS['SETUP'],
|
|
$field,
|
|
[
|
|
"data-src" => "/admin/equipment/serverpart/modify/{$entity->getPK()}?type={$entity->getType()}&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,
|
|
$entity->getTitle(),
|
|
$entity->getCnt(),
|
|
!$entity->getExtra() ? "" : "/" . $entity->getExtra()
|
|
);
|
|
}
|
|
$value = implode("<BR>", $temps);
|
|
break;
|
|
case 'SWITCH_SERVICE':
|
|
case 'IP_SERVICE':
|
|
case 'OS_SERVICE':
|
|
$field = str_replace('_SERVICE', '', $field);
|
|
if (!array_key_exists($field, $viewDatas['entities'])) {
|
|
return "";
|
|
}
|
|
$temps = [];
|
|
foreach ($viewDatas['entities'][$field] as $entity) {
|
|
$modal = form_label(
|
|
$entity->getTitle(),
|
|
$field,
|
|
[
|
|
"data-src" => "/admin/equipment/serverpart/modify/{$entity->getPK()}?type={$entity->getType()}&ActionTemplate=popup",
|
|
"data-bs-toggle" => "modal",
|
|
"data-bs-target" => "#index_action_form",
|
|
"class" => "btn btn-sm btn-outline btn-circle",
|
|
"target" => "_self"
|
|
]
|
|
);
|
|
$cnt = $entity->getCnt() > 1 ? "*" . $entity->getCnt() . "개" : "";
|
|
$extra = !$entity->getExtra() ? "" : "/";
|
|
$temps[] = $modal . $cnt . $extra;
|
|
}
|
|
$value = implode(",", $temps);
|
|
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 'SWITCH':
|
|
case 'IP':
|
|
case 'CS':
|
|
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['serverinfo_uid']}&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;
|
|
}
|
|
}
|