181 lines
8.5 KiB
PHP
181 lines
8.5 KiB
PHP
<?php
|
|
|
|
namespace App\Helpers\Customer;
|
|
|
|
use App\Models\Customer\ServiceModel;
|
|
|
|
class ServiceHelper extends CustomerHelper
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->setTitleField(field: ServiceModel::TITLE);
|
|
}
|
|
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
|
|
{
|
|
switch ($field) {
|
|
case 'serverinfo_uid':
|
|
if (array_key_exists('entity', $viewDatas)) {
|
|
$value = $viewDatas['entity']->getServerEntity() !== null ? $viewDatas['entity']->getServerEntity()->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 'switchinfo_uid':
|
|
if (array_key_exists('entity', $viewDatas)) {
|
|
if ($viewDatas['entity']->getServerEntity() !== null) {
|
|
$value = $viewDatas['entity']->getServerEntity()->getSwitchEntity() !== null ? $viewDatas['entity']->getServerEntity()->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)) {
|
|
if ($viewDatas['entity']->getServerEntity() !== null) {
|
|
foreach ($viewDatas['entity']->getServerEntity()->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)) {
|
|
if ($viewDatas['entity']->getServerEntity() !== null) {
|
|
foreach ($viewDatas['entity']->getServerEntity()->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;
|
|
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':
|
|
// $temp = parent::getFieldForm($field, $value, $viewDatas, $extras);
|
|
// $value = $temp . form_label(
|
|
// ICONS['HISTORY'],
|
|
// 'client_history',
|
|
// [
|
|
// "data-src" => "/admin/customer/clienthistory?clientinfo_uid={$value}",
|
|
// "data-bs-toggle" => "modal",
|
|
// "data-bs-target" => "#index_action_form",
|
|
// "class" => "btn btn-outline btn-primary btn-circle",
|
|
// "target" => "_self"
|
|
// ]
|
|
// );
|
|
// break;
|
|
case 'CPU':
|
|
case 'RAM':
|
|
case 'DISK':
|
|
case 'OS':
|
|
case 'DB':
|
|
case 'SOFTWARE':
|
|
$temps = [];
|
|
foreach ($viewDatas['entity']->getServerEntity()->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']->getServerEntity()->getIPEntities() as $ipEntity) {
|
|
$value .= sprintf("<div>%s%s %s</div>", $ipEntity->getTitle(), $ipEntity->getAmount());
|
|
}
|
|
break;
|
|
case 'csinfo_uid':
|
|
foreach ($viewDatas['entity']->getServerEntity()->getCSEntities() as $csEntity) {
|
|
$value .= sprintf("<div>%s%s %s</div>", $csEntity->getTitle(), $csEntity->getAmount());
|
|
}
|
|
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;
|
|
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, $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;
|
|
case 'CPU':
|
|
case 'RAM':
|
|
case 'DISK':
|
|
case 'OS':
|
|
case 'DB':
|
|
case 'SOFTWARE':
|
|
$serverEntity = $viewDatas['entity']->getServerEntity();
|
|
$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={$serverEntity->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;
|
|
}
|
|
}
|