dbmsv2/app/Helpers/Customer/ServiceHelper.php
2025-09-15 14:35:17 +09:00

118 lines
5.4 KiB
PHP

<?php
namespace App\Helpers\Customer;
use App\Entities\Equipment\ServerEntity;
use App\Models\Customer\ServiceModel;
class ServiceHelper extends CustomerHelper
{
public function __construct()
{
parent::__construct();
$this->setTitleField(field: ServiceModel::TITLE);
}
protected function form_dropdown_common_process(string $field, mixed $value, array $viewDatas, array $extras = [], array $attributes = []): string
{
$html = "";
switch ($field) {
case 'serverinfo_uid':
$attribute = "";
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);
}
$title = $entity->getStatus() != $entity::DEFAULT_STATUS ? "서비스중." : "";
$title .= $entity->getCustomTitle();
$html .= sprintf("<option value=\"%s\"%s%s%s>%s</option>", $key, $isSelected, $isDisabled, $attribute, $title);
}
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 'site':
$extras['onChange'] = "$('select[name=\'clientinfo_uid\']').select2('open')";
$form = $this->form_dropdown_common($field, $value, $viewDatas, $extras);
break;
case 'serverinfo_uid':
if ($value === null && array_key_exists('entity', $viewDatas)) {
$value = $viewDatas['entity']->getServerEntity()->getPK();
}
$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;
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 'clientinfo_uid':
$value = "<a href=\"/admin/customer/client/detail/{$value}\">" . $viewDatas['control']['field_optons'][$field][$value]->getTitle() . "</a>";
break;
case 'billing_at':
if (array_key_exists('unPaids', $viewDatas)) {
if (array_key_exists($viewDatas['entity']->getPK(), $viewDatas['unPaids'])) {
$value .= "<div><a href=\"/admin/customer/payment?={$viewDatas['entity']->getPK()}\">미지급: <span style=\"color:red;\">" . $viewDatas['unPaids'][$viewDatas['entity']->getPK()] . "</span>개</a></div>";
}
}
break;
case 'history':
$value = nl2br($value);
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':
$action = parent::getListButton($action, $label ? $label : $viewDatas['entity']->getCode(), $viewDatas, $extras);
break;
case 'history':
$extras = ["class" => "btn btn-outline btn-primary btn-circle", "target" => "_self", ...$extras];
$action = form_label(
$label ? $label : ICONS['HISTORY'],
$action,
[
"data-src" => "/admin/customer/servicehistory?serviceinfo_uid={$viewDatas['entity']->getPK()}&serviceinfo_uid={$viewDatas['entity']->getPK()}&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;
}
}