149 lines
6.6 KiB
PHP
149 lines
6.6 KiB
PHP
<?php
|
|
|
|
namespace App\Helpers\Customer;
|
|
|
|
use App\Models\Customer\ServicePaymentModel;
|
|
use CodeIgniter\HTTP\IncomingRequest;
|
|
|
|
class ServicePaymentHelper extends CustomerHelper
|
|
{
|
|
protected ?IncomingRequest $request = null;
|
|
public function __construct(?IncomingRequest $request = null)
|
|
{
|
|
parent::__construct($request);
|
|
$this->setTitleField(field: ServicePaymentModel::TITLE);
|
|
}
|
|
|
|
//ItemType에 따른 조건부 추가 Index Page
|
|
public function getFieldFormByItemType(string $field, mixed $value, array $viewDatas, array $extras = []): string
|
|
{
|
|
if (in_array($viewDatas['control']['action'], ['create', 'modify', 'create_form', 'modify_form'])) {
|
|
$extras = (strpos($viewDatas['control']['field_rules'][$field], 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras];
|
|
}
|
|
switch ($field) {
|
|
case "LINE":
|
|
case "IP":
|
|
case "SERVER":
|
|
case "CPU":
|
|
case "RAM":
|
|
case "STORAGE":
|
|
case "SOFTWARE":
|
|
case "DEFENCE":
|
|
case "DOMAIN":
|
|
if (!is_array($viewDatas['control']['filter_optons'][$field])) {
|
|
throw new \Exception(__METHOD__ . "에서 {$field}의 field_options가 array형태가 아닙니다.");
|
|
}
|
|
$formOptions = ["" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택'];
|
|
foreach ($viewDatas['control']['filter_optons'][$field] as $key => $label) {
|
|
$formOptions[$key] = $label;
|
|
}
|
|
$extra_class = isset($extras['class']) ? $extras['class'] . ' select-field' : 'select-field';
|
|
// create, modify, create_form, modify_form 액션에서는 기본값:DEFAULTS['STATUS']을 설정
|
|
if (in_array($viewDatas['control']['action'], ['create', 'modify', 'create_form', 'modify_form'])) {
|
|
$value = $value ?? DEFAULTS['STATUS'];
|
|
}
|
|
$form = form_dropdown($field, $formOptions, $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]);
|
|
break;
|
|
default:
|
|
$form = parent::getFieldForm($field, $value, $viewDatas, $extras);
|
|
break;
|
|
}
|
|
return $form;
|
|
}
|
|
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
|
|
{
|
|
if (in_array($viewDatas['control']['action'], ['create', 'modify', 'create_form', 'modify_form'])) {
|
|
$extras = (strpos($viewDatas['control']['field_rules'][$field], 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras];
|
|
}
|
|
switch ($field) {
|
|
case 'item_uid':
|
|
if (array_key_exists('entity', $viewDatas)) {
|
|
$form = $this->getFieldFormByItemType($viewDatas['entity']->getItemType(), $value, $viewDatas, $extras);
|
|
} else {
|
|
$form = parent::getFieldForm($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 "countdown": //결제일Countdown
|
|
$value = $viewDatas['entity']->getView_CounDueAt();
|
|
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, array $viewDatas, array $extras = []): string
|
|
{
|
|
switch ($action) {
|
|
case 'modify':
|
|
$checkbox = '';
|
|
//상태가 미지급이 경우만 checkbox를 표시
|
|
if ($viewDatas['entity']->getStatus() === DEFAULTS['STATUS']) {
|
|
$oldBatchJobUids = old("batchjob_uids", null);
|
|
$oldBatchJobUids = is_array($oldBatchJobUids) ? $oldBatchJobUids : [$oldBatchJobUids];
|
|
$checkbox = form_checkbox([
|
|
"id" => "checkbox_uid_{$viewDatas['entity']->getPK()}",
|
|
"name" => "batchjob_uids[]",
|
|
"value" => $viewDatas['entity']->getPK(),
|
|
"class" => "batchjobuids_checkboxs",
|
|
"checked" => in_array($viewDatas['entity']->getPK(), $oldBatchJobUids)
|
|
]);
|
|
}
|
|
$action = $checkbox . form_label(
|
|
$viewDatas['cnt'],
|
|
$action,
|
|
[
|
|
"data-src" => current_url() . '/' . $action . '/' . $viewDatas['entity']->getPK() . '?' . $this->request->getUri()->getQuery(),
|
|
"data-bs-toggle" => "modal",
|
|
"data-bs-target" => "#index_action_form",
|
|
...$extras
|
|
]
|
|
);
|
|
break;
|
|
case 'invoice_email':
|
|
$extras = ["class" => "btn btn-outline btn-success btn-circle", "target" => "_self", ...$extras];
|
|
$action = form_label(
|
|
ICONS['MAIL'],
|
|
$action,
|
|
[
|
|
"data-src" => "/admin/customer/payment/invoice?ActionTemplate=email",
|
|
"data-bs-toggle" => "modal",
|
|
"data-bs-target" => "#index_action_form",
|
|
...$extras
|
|
]
|
|
);
|
|
break;
|
|
case 'invoice_mobile':
|
|
$extras = ["class" => "btn btn-outline btn-success btn-circle", "target" => "_self", ...$extras];
|
|
$action = form_label(
|
|
ICONS['PHONE'],
|
|
$action,
|
|
[
|
|
"data-src" => "/admin/customer/payment/invoice?ActionTemplate=mobile",
|
|
"data-bs-toggle" => "modal",
|
|
"data-bs-target" => "#index_action_form",
|
|
...$extras
|
|
]
|
|
);
|
|
break;
|
|
default:
|
|
$action = parent::getListButton($action, $viewDatas, $extras);
|
|
break;
|
|
}
|
|
return $action;
|
|
}
|
|
}
|