dbmsv2 init...1

This commit is contained in:
choi.jh 2025-09-11 16:55:44 +09:00
parent ba6dfd23b4
commit 51c1dbf72e
3 changed files with 57 additions and 13 deletions

View File

@ -196,7 +196,7 @@ class CommonHelper
return $ips; return $ips;
} }
final public function form_dropdown_common(string $field, mixed $value, array $viewDatas, array $extras = []): string final public function form_dropdown_common(string $field, mixed $value, array $viewDatas, array $extras = [], array $attributes = []): string
{ {
// 필터 옵션이 없으면 빈 배열로 초기화 // 필터 옵션이 없으면 빈 배열로 초기화
if (!array_key_exists($field, $viewDatas['control']['field_optons'])) { if (!array_key_exists($field, $viewDatas['control']['field_optons'])) {
@ -208,7 +208,7 @@ class CommonHelper
} }
// $formOptions는 필터 옵션 배열로, key는 필터 엔티티의 PK, value는 필터 엔티티 객체 // $formOptions는 필터 옵션 배열로, key는 필터 엔티티의 PK, value는 필터 엔티티 객체
$html = sprintf("<select name=\"%s\" %s>", $field, $extra); $html = sprintf("<select name=\"%s\" %s>", $field, $extra);
$html .= $this->form_dropdown_common_process($field, $value, $viewDatas, $extras); $html .= $this->form_dropdown_common_process($field, $value, $viewDatas, $extras, $attributes);
$html .= '</select>'; $html .= '</select>';
return $html; return $html;
} }
@ -225,7 +225,7 @@ class CommonHelper
return $label; return $label;
} }
// header.php에서 getFieldForm_Helper사용 // header.php에서 getFieldForm_Helper사용
protected function form_dropdown_common_process(string $field, mixed $value, array $viewDatas, array $extras = []): string protected function form_dropdown_common_process(string $field, mixed $value, array $viewDatas, array $extras = [], array $attributes = []): string
{ {
switch ($field) { switch ($field) {
default: default:
@ -237,7 +237,11 @@ class CommonHelper
if ($entity->getStatus() != $entity::DEFAULT_STATUS) if ($entity->getStatus() != $entity::DEFAULT_STATUS)
$isDisabled = ' disabled'; $isDisabled = ' disabled';
} }
$html .= sprintf("<option value=\"%s\"%s%s>%s</option>", $key, $isSelected, $isDisabled, $entity->getCustomTitle()); $attribute = "";
foreach ($attributes as $attribute_tag => $attribute_value) {
$attribute .= sprintf(" %s=\"%s\"", $attribute_tag, $attribute_value);
}
$html .= sprintf("<option value=\"%s\"%s%s%s>%s</option>", $key, $isSelected, $isDisabled, $attribute, $entity->getCustomTitle());
} }
break; break;
} }

View File

@ -2,30 +2,56 @@
namespace App\Helpers\Customer; namespace App\Helpers\Customer;
use App\Helpers\Equipment\ServerHelper; use App\Entities\Equipment\ServerEntity;
use App\Models\Customer\ServiceModel; use App\Models\Customer\ServiceModel;
class ServiceHelper extends CustomerHelper class ServiceHelper extends CustomerHelper
{ {
private ?ServerHelper $_serverHelper = null;
public function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
$this->setTitleField(field: ServiceModel::TITLE); $this->setTitleField(field: ServiceModel::TITLE);
$this->_serverHelper = new ServerHelper();
} }
private function getServerHelper(): ServerHelper protected function form_dropdown_common_process(string $field, mixed $value, array $viewDatas, array $extras = [], array $attributes = []): string
{ {
return $this->_serverHelper; 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' : '';
$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);
}
$html .= sprintf("<option value=\"%s\"%s%s%s>%s</option>", $key, $isSelected, $isDisabled, $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 public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
{ {
switch ($field) { switch ($field) {
case 'site':
$extras['onChange'] = "$('select[name=\'clientinfo_uid\']').select2('open')";
$form = $this->form_dropdown_common($field, $value, $viewDatas, $extras);
break;
case 'serverinfo_uid': case 'serverinfo_uid':
if ($value === null && array_key_exists('entity', $viewDatas)) { if ($value === null && array_key_exists('entity', $viewDatas)) {
$value = $viewDatas['entity']->getServerEntity()->getPK(); $value = $viewDatas['entity']->getServerEntity()->getPK();
} }
$form = parent::getFieldForm($field, $value, $viewDatas, $extras); $extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
$extras['onChange'] = "document.querySelector('input[name=\'amount\']').value = this.options[this.selectedIndex].getAttribute('data-price')";
$attributes = ['data-price' => 'getPrice'];
$form = $this->form_dropdown_common($field, $value, $viewDatas, $extras, $attributes);
break; break;
default: default:
$form = parent::getFieldForm($field, $value, $viewDatas, $extras); $form = parent::getFieldForm($field, $value, $viewDatas, $extras);

View File

@ -11,7 +11,7 @@ class ServerPartHelper extends EquipmentHelper
parent::__construct(); parent::__construct();
$this->setTitleField(field: ServerPartModel::TITLE); $this->setTitleField(field: ServerPartModel::TITLE);
} }
protected function form_dropdown_common_process(string $field, mixed $value, array $viewDatas, array $extras = []): string protected function form_dropdown_common_process(string $field, mixed $value, array $viewDatas, array $extras = [], array $attributes = []): string
{ {
switch ($field) { switch ($field) {
case 'serverinfo_uid': case 'serverinfo_uid':
@ -97,8 +97,22 @@ class ServerPartHelper extends EquipmentHelper
if (!array_key_exists($field, $viewDatas['entities'])) { if (!array_key_exists($field, $viewDatas['entities'])) {
return ""; return "";
} }
$temps = [];
foreach ($viewDatas['entities'][$field] as $entity) { foreach ($viewDatas['entities'][$field] as $entity) {
$temps[] = $entity->getTitle(); $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); $value = implode(",", $temps);
break; break;
@ -129,7 +143,7 @@ class ServerPartHelper extends EquipmentHelper
$label ? $label : ICONS['SETUP'], $label ? $label : ICONS['SETUP'],
$action, $action,
[ [
"data-src" => "/admin/equipment/serverpart/create?serverinfo_uid={$viewDatas['serverinfo_uid']}&type={$action}&ActionTemplate=popup", "data-src" => "/admin/equipment/serverpart?serverinfo_uid={$viewDatas['serverinfo_uid']}&type={$action}&ActionTemplate=popup",
"data-bs-toggle" => "modal", "data-bs-toggle" => "modal",
"data-bs-target" => "#index_action_form", "data-bs-target" => "#index_action_form",
...$extras, ...$extras,