220 lines
10 KiB
PHP
220 lines
10 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);
|
|
}
|
|
private function getServerPartForm(string $field, mixed $value, array $viewDatas, array $extras, string $partType): string
|
|
{
|
|
//Type별로 부품연결정보가 있는지 확인
|
|
$serverpartEntity = null;
|
|
if (array_key_exists('entity', $viewDatas)) {
|
|
$serverpartEntity = $viewDatas['entity']->getServerPartEntity($partType);
|
|
}
|
|
$form = "";
|
|
//수정시 Type별 사용할 hidden partinfo_uid
|
|
if ($serverpartEntity !== null) {
|
|
$form .= form_hidden("partinfo_uid_{$partType}", $serverpartEntity->getPK());
|
|
}
|
|
//기존 입력화면에서 return 된것인지?
|
|
if ($value === null && $serverpartEntity !== null) {
|
|
$value = $serverpartEntity->getPartInfoUID();
|
|
}
|
|
$form .= $this->form_dropdown_custom($field, $value, $viewDatas, $extras);
|
|
return $form;
|
|
}
|
|
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;
|
|
case 'partinfo_uid_CPU':
|
|
$form = $this->getServerPartForm($field, $value, $viewDatas, $extras, 'CPU');
|
|
break;
|
|
case 'partinfo_uid_CPU_cnt':
|
|
$form = form_dropdown($field, $viewDatas['partinfo_cnt_options'], $value, $extras) . "개";
|
|
break;
|
|
case 'partinfo_uid_RAM':
|
|
$form = $this->getServerPartForm($field, $value, $viewDatas, $extras, 'RAM',);
|
|
break;
|
|
case 'partinfo_uid_RAM_cnt':
|
|
$form = form_dropdown($field, $viewDatas['partinfo_cnt_options'], $value, $extras) . "개";
|
|
break;
|
|
case 'partinfo_uid_DISK':
|
|
$form = $this->getServerPartForm($field, $value, $viewDatas, $extras, 'DISK');
|
|
break;
|
|
case 'partinfo_uid_DISK_cnt':
|
|
$form = form_dropdown($field, $viewDatas['partinfo_cnt_options'], $value, $extras) . "개";
|
|
break;
|
|
case 'partinfo_uid_DISK_extra':
|
|
$form = $this->form_dropdown_custom($field, $value, $viewDatas, $extras);
|
|
break;
|
|
case 'partinfo_uid_OS':
|
|
$form = $this->getServerPartForm($field, $value, $viewDatas, $extras, 'OS');
|
|
break;
|
|
case 'partinfo_uid_OS_cnt':
|
|
$form = form_dropdown($field, $viewDatas['partinfo_cnt_options'], $value, $extras) . "개";
|
|
break;
|
|
case 'partinfo_uid_DB':
|
|
$form = $this->getServerPartForm($field, $value, $viewDatas, $extras, 'DB');
|
|
break;
|
|
case 'partinfo_uid_DB_cnt':
|
|
$form = form_dropdown($field, $viewDatas['partinfo_cnt_options'], $value, $extras) . "개";
|
|
break;
|
|
case 'partinfo_uid_SOFTWARE':
|
|
$form = $this->getServerPartForm($field, $value, $viewDatas, $extras, 'SOFTWARE');
|
|
break;
|
|
case 'partinfo_uid_SOFTWARE_cnt':
|
|
$form = form_dropdown($field, $viewDatas['partinfo_cnt_options'], $value, $extras) . "개";
|
|
break;
|
|
// case 'ipinfo_uid':
|
|
// case 'csinfo_uid':
|
|
// $extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
|
|
// $form = $this->form_dropdown_custom($field, $value, $viewDatas, $extras);
|
|
// break;
|
|
default:
|
|
$form = parent::getFieldForm($field, $value, $viewDatas, $extras);
|
|
break;
|
|
}
|
|
return $form;
|
|
}
|
|
private function getServerPartView(string $field, mixed $value, array $viewDatas, array $extras, string $partType): string
|
|
{
|
|
$serverPartEntity = $viewDatas['entity']->getServerEntity()->getServerPartEntity($partType);
|
|
if ($serverPartEntity !== null) {
|
|
$value .= sprintf(
|
|
"<div>%s%s %s</div>",
|
|
$serverPartEntity->getTitle(),
|
|
$serverPartEntity->getCnt() >= 1 ? "*" . $serverPartEntity->getCnt() . "개" : "",
|
|
$serverPartEntity->getExtra() ?? ""
|
|
);
|
|
}
|
|
return $value;
|
|
}
|
|
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':
|
|
$value = $this->getServerPartView($field, $value, $viewDatas, $extras, $field);
|
|
break;
|
|
case 'ipinfo_uid':
|
|
$value = "";
|
|
foreach ($viewDatas['entity']->getServerEntity()->getIPEntities() as $ipEntity) {
|
|
$value .= sprintf("<div>%s%s %s</div>", $ipEntity->getTitle(), $ipEntity->getAmount());
|
|
}
|
|
break;
|
|
case 'csinfo_uid':
|
|
$value = "";
|
|
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()}",
|
|
"data-bs-toggle" => "modal",
|
|
"data-bs-target" => "#index_action_form",
|
|
...$extras
|
|
]
|
|
);
|
|
break;
|
|
default:
|
|
$action = parent::getListButton($action, $label, $viewDatas, $extras);
|
|
break;
|
|
}
|
|
return $action;
|
|
}
|
|
}
|