161 lines
6.8 KiB
PHP
161 lines
6.8 KiB
PHP
<?php
|
|
|
|
namespace App\Helpers\Equipment;
|
|
|
|
use App\Entities\FormOptionEntity;
|
|
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 'part_uid':
|
|
$html = "<option value=\"\">" . lang("{$viewDatas['class_path']}.label.{$field}") . " 선택" . "</option>";
|
|
foreach ($viewDatas['control']['field_optons'][$field] as $key => $entity) {
|
|
$isSelected = $key == $value ? ' selected' : '';
|
|
$attribute = "";
|
|
foreach ($attributes as $attribute_tag => $attribute_value) {
|
|
switch ($attribute_tag) {
|
|
case 'disabled':
|
|
$attribute .= in_array($viewDatas['control']['action'], ['create_form', 'index']) && $entity->getStatus() !== ($attribute_value ?? $entity::DEFAULT_STATUS) ? ' disabled' : '';
|
|
break;
|
|
default:
|
|
$attribute .= sprintf(" %s=\"%s\"", $attribute_tag, $entity->$attribute_value);
|
|
break;
|
|
}
|
|
}
|
|
$html .= sprintf("<option value=\"%s\"%s%s>%s</option>", $key, $isSelected, $attribute, $entity->getCustomTitle());
|
|
}
|
|
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) {
|
|
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 'CPU_cnt':
|
|
case 'RAM_cnt':
|
|
case 'DISK_cnt':
|
|
case 'DB_cnt':
|
|
case 'OS_cnt':
|
|
case 'SOFTWARE_cnt':
|
|
$form = "*" . form_dropdown($field, SERVERPART['CNT_RANGE'], $value, $extras) . "개";
|
|
break;
|
|
case 'DISK_extra':
|
|
$formOptionDatas = lang("Equipment/ServerPart.EXTRA");
|
|
if (!is_array($formOptionDatas)) {
|
|
throw new \Exception(__FUNCTION__ . "에서 {$field}}의 formOptionDatas 값이 array가 아닙니다.\n" . var_export($formOptionDatas, true));
|
|
}
|
|
$options = ["" => lang("Equipment/ServerPart.label.extra") . " 선택", ...$formOptionDatas];
|
|
$form = form_dropdown($field, $options, $value, $extras);
|
|
break;
|
|
case 'part_uid':
|
|
$extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
|
|
$extras['onChange'] = "document.getElementById('amount').value=this.options[this.selectedIndex].getAttribute('data-price')";
|
|
$attributes = ['disabled' => null, 'data-price' => 'getPrice'];
|
|
$form = $this->form_dropdown_common($field, $value, $viewDatas, $extras, $attributes);
|
|
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':
|
|
$temps = [];
|
|
foreach ($viewDatas['serverPartEntities'] as $partEntity) {
|
|
$modal = form_label(
|
|
ICONS['SETUP'],
|
|
$field,
|
|
[
|
|
"data-src" => "/admin/equipment/serverpart/modify/{$partEntity->getPK()}?type={$partEntity->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,
|
|
$partEntity->getTitle(),
|
|
$partEntity->getCnt(),
|
|
!$partEntity->getExtra() ? "" : "/" . $partEntity->getExtra()
|
|
);
|
|
}
|
|
$value = implode("<BR>", $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/create?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;
|
|
}
|
|
}
|