diff --git a/app/Controllers/Admin/Customer/CustomerController.php b/app/Controllers/Admin/Customer/CustomerController.php
index a5d1714..d60e25f 100644
--- a/app/Controllers/Admin/Customer/CustomerController.php
+++ b/app/Controllers/Admin/Customer/CustomerController.php
@@ -31,6 +31,7 @@ abstract class CustomerController extends AdminController
{
//LINE,IP,SERVER등 추가 FilterOption 셋팅용
foreach (SERVICE_ITEM_TYPES as $item_type => $label) {
+ $this->setFieldRule($item_type, $this->getFormFieldRule($this->getAction(), $item_type));
$this->setFilterFieldOption($item_type, $this->getServiceService()->getFilterOptionsByItemType($item_type));
}
}
diff --git a/app/Controllers/Admin/Customer/ServiceItemController.php b/app/Controllers/Admin/Customer/ServiceItemController.php
index c7028c7..31539ca 100644
--- a/app/Controllers/Admin/Customer/ServiceItemController.php
+++ b/app/Controllers/Admin/Customer/ServiceItemController.php
@@ -27,11 +27,7 @@ class ServiceItemController extends CustomerController
{
parent::initAction($action, $fields);
//LINE,IP,SERVER등 추가 FilterOption 셋팅용
- foreach (SERVICE_ITEM_TYPES as $item_type => $label) {
- $options = $this->getService()->getServiceItemLinkService($item_type)->getEntities();
- $this->setFieldRule($item_type, $this->getFormFieldRule($this->getAction(), $item_type));
- $this->setFilterFieldOption($item_type, $options);
- }
+ $this->setFilterOptionsByItemType();
}
public function getService(): ServiceItemService
{
@@ -74,7 +70,7 @@ class ServiceItemController extends CustomerController
if (!$item_type) {
throw new \Exception(__FUNCTION__ . "에서 item_type이 지정되지 않았습니다.");
}
- $options = $this->getFilterFieldOption($item_type);
+ $options = $this->getFilterFieldOption('item_type');
break;
default:
$options = parent::getFormFieldOption($field, $options);
diff --git a/app/Controllers/Admin/Customer/ServicePaymentController.php b/app/Controllers/Admin/Customer/ServicePaymentController.php
index 13d1c89..629f41c 100644
--- a/app/Controllers/Admin/Customer/ServicePaymentController.php
+++ b/app/Controllers/Admin/Customer/ServicePaymentController.php
@@ -180,8 +180,7 @@ class ServicePaymentController extends CustomerController
$this->initAction(__FUNCTION__);
//LINE,IP,SERVER등 추가 FilterOption 셋팅용
foreach (SERVICE_ITEM_TYPES as $item_type => $label) {
- $options = $this->getService()->getServiceItemLinkService($item_type)->getEntities();
- $this->setFilterFieldOption($item_type, $options);
+ $this->setFilterFieldOption($item_type, $this->getServiceService()->getFilterOptionsByItemType($item_type));
}
$this->invoice_process();
return $this->getResultSuccess();
diff --git a/app/Controllers/CommonController.php b/app/Controllers/CommonController.php
index c34281b..e6c4d83 100644
--- a/app/Controllers/CommonController.php
+++ b/app/Controllers/CommonController.php
@@ -4,20 +4,21 @@ namespace App\Controllers;
use App\Controllers\BaseController;
+use App\Entities\FormOptionEntity;
+use App\Libraries\LogCollector;
+use App\Services\MyLogService;
+use CodeIgniter\HTTP\DownloadResponse;
+
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Validation\Validation;
-
-use CodeIgniter\HTTP\DownloadResponse;
use PhpOffice\PhpSpreadsheet\IOFactory;
+
use PhpOffice\PhpSpreadsheet\Reader\Html;
use PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf;
use Psr\Log\LoggerInterface;
-use App\Libraries\LogCollector;
-use App\Services\MyLogService;
-
abstract class CommonController extends BaseController
{
private $_myAuth = null;
@@ -146,11 +147,18 @@ abstract class CommonController extends BaseController
if (!array_key_exists('filter_optons', $this->_control)) {
$this->_control['filter_optons'] = [];
}
- $this->_control['filter_optons'][$field] = $options;
+ //Filter Options 초기화
+ $this->_control['filter_optons'][$field] = [
+ "" => new FormOptionEntity(["uid" => "", "title" => lang("{$this->getService()->getClassName()}.label.{$field}") . " 선택"])
+ ];
+ foreach ($options as $option) {
+ $this->_control['filter_optons'][$field][$option->getPK()] = $option;
+ }
+ // dd($this->_control['filter_optons'][$field]);
}
final protected function getFilterFieldOption(string $field): array
{
- return $this->_control['filter_optons'][$field] ?? [];
+ return $this->_control['filter_optons'][$field];
}
protected function initAction(string $action, $fields = []): void
diff --git a/app/Entities/FormOptionEntity.php b/app/Entities/FormOptionEntity.php
index e97986e..ef96586 100644
--- a/app/Entities/FormOptionEntity.php
+++ b/app/Entities/FormOptionEntity.php
@@ -4,12 +4,6 @@ namespace App\Entities;
class FormOptionEntity extends CommonEntity
{
- public function getPK(): string
- {
- return $this->attributes['uid'];
- }
- public function getTitle(): string
- {
- return $this->attributes['title'];
- }
+ const PK = "uid";
+ const TITLE = "title";
}
diff --git a/app/Helpers/CommonHelper.php b/app/Helpers/CommonHelper.php
index b04232e..4e92340 100644
--- a/app/Helpers/CommonHelper.php
+++ b/app/Helpers/CommonHelper.php
@@ -210,6 +210,23 @@ class CommonHelper
}
// header.php에서 getFieldForm_Helper사용
+ protected function form_dropdown_disabled(string $field, mixed $value, array $formOptions, array $extras = [], mixed $disabledKey = null): string
+ {
+ // $formOptions는 필터 옵션 배열로, key는 필터 엔티티의 PK, value는 필터 엔티티 객체
+ $extra = "";
+ foreach ($extras as $option_tag => $option_value) {
+ $extra = sprintf(" %s=\"%s\"", $option_tag, htmlspecialchars($option_value, ENT_QUOTES, 'UTF-8'));
+ }
+ $html = sprintf("';
+ return $html;
+ }
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
{
switch ($field) {
@@ -234,12 +251,7 @@ class CommonHelper
}
$form = implode(" ", $forms);
} else {
- $extra_class = isset($extras['class']) ? $extras['class'] . ' select-field' : 'select-field';
- $formOptions = ["" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택'];
- foreach ($viewDatas['control']['filter_optons'][$field] as $key => $filterEntity) {
- $formOptions[$key] = $filterEntity->getTitle();
- }
- $form = form_dropdown($field, $formOptions, $value, [...$extras]);
+ $form = $this->form_dropdown_disabled($field, $value, $viewDatas['control']['filter_optons'][$field], $extras);
}
break;
case 'expired_at':
@@ -247,30 +259,23 @@ class CommonHelper
case 'start_at':
case 'updated_at':
case 'created_at':
- $extra_class = isset($extras['class']) ? $extras['class'] . ' calender' : 'calender';
- $form = form_input($field, $value ?? "", ['class' => $extra_class, ...$extras]);
+ $extras['class'] = sprintf("class=\"%s\"", array_key_exists('class', $extras) ? $extras['class'] . ' calender' : 'calender');
+ $form = form_input($field, $value ?? "", $extras);
break;
case 'description':
case 'content':
- $extra_class = isset($extras['class']) ? $extras['class'] . ' tinymce' : 'tinymce';
- $form = form_textarea($field, $value ?? "", ['id' => $field, 'class' => $extra_class, ...$extras]);
+ $extras['class'] = sprintf("class=\"%s\"", array_key_exists('class', $extras) ? $extras['class'] . ' tinymce' : 'tinymce');
+ $form = form_textarea($field, $value ?? "", ['id' => $field, ...$extras]);
+ break;
+ case 'clientinfo_uid':
+ case 'ownerinfo_uid':
+ case 'user_uid':
+ $extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
+ $form = $this->form_dropdown_disabled($field, $value, $viewDatas['control']['filter_optons'][$field], $extras);
break;
default:
if (in_array($field, $viewDatas['control']['filter_fields'])) {
- if (!is_array($viewDatas['control']['filter_optons'][$field])) {
- throw new \Exception(__METHOD__ . "에서 {$field}의 field_options가 array형태가 아닙니다.");
- }
- $formOptions = ["" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택'];
- // dd($viewDatas['control']['filter_optons'][$field]);
- foreach ($viewDatas['control']['filter_optons'][$field] as $key => $filterEntity) {
- $formOptions[$key] = $filterEntity->getTitle();
- }
- $extra_class = isset($extras['class']) ? $extras['class'] . ' select-field' : 'select-field';
- // create, create_form 액션에서는 기본값:DEFAULTS['STATUS']을 설정
- if (in_array($viewDatas['control']['action'], ['create', 'create_form'])) {
- $value = $value ?? DEFAULTS['STATUS'];
- }
- $form = form_dropdown($field, $formOptions, $value, ['class' => $extra_class, ...$extras]);
+ $form = $this->form_dropdown_disabled($field, $value, $viewDatas['control']['filter_optons'][$field], $extras);
} else {
$form = form_input($field, $value ?? "", $extras);
}
diff --git a/app/Helpers/Customer/ServiceHelper.php b/app/Helpers/Customer/ServiceHelper.php
index 9ea0939..4a1f54c 100644
--- a/app/Helpers/Customer/ServiceHelper.php
+++ b/app/Helpers/Customer/ServiceHelper.php
@@ -48,46 +48,12 @@ class ServiceHelper extends CustomerHelper
{
switch ($field) {
case 'switchinfo_uid':
- if (!is_array($viewDatas['control']['filter_optons'][$field])) {
- throw new \Exception(__METHOD__ . "에서 {$field}의 field_options가 array형태가 아닙니다.");
- }
- //CodeIgniter 4의 form_dropdown()은 options 배열로만 값을 받기 때문에, disabled 속성 같은 개별 옵션에 대한 HTML 속성 추가는 기본적으로 지원하지 않습니다.
- $form_temps = ["';
- $form = implode("", $form_temps);
+ $extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
+ $form = $this->form_dropdown_disabled($field, $value, $viewDatas['control']['filter_optons'][$field], $extras);
break;
case 'codeinfo_uid':
- if (!is_array($viewDatas['control']['filter_optons'][$field])) {
- throw new \Exception(__METHOD__ . "에서 {$field}의 field_options가 array형태가 아닙니다.");
- }
- //CodeIgniter 4의 form_dropdown()은 options 배열로만 값을 받기 때문에, disabled 속성 같은 개별 옵션에 대한 HTML 속성 추가는 기본적으로 지원하지 않습니다.
- $form_temps = ["';
- $form = implode("", $form_temps);
+ $extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
+ $form = $this->form_dropdown_disabled($field, $value, $viewDatas['control']['filter_optons'][$field], $extras, CodeEntity::STATUS_OCCUPIED);
break;
default:
$form = parent::getFieldForm($field, $value, $viewDatas, $extras);
diff --git a/app/Helpers/Customer/ServiceItemHelper.php b/app/Helpers/Customer/ServiceItemHelper.php
index eaa0d2d..95cdb4f 100644
--- a/app/Helpers/Customer/ServiceItemHelper.php
+++ b/app/Helpers/Customer/ServiceItemHelper.php
@@ -2,9 +2,9 @@
namespace App\Helpers\Customer;
+use App\Models\Customer\ServiceItemModel;
use App\Entities\Equipment\Part\DomainEntity;
use App\Entities\Equipment\Part\IpEntity;
-use App\Models\Customer\ServiceItemModel;
class ServiceItemHelper extends CustomerHelper
{
@@ -15,54 +15,25 @@ class ServiceItemHelper extends CustomerHelper
}
//ItemType에 따른 조건부 추가 Index Page
- private function getFieldFormByItemType(string $field, mixed $value, array $viewDatas, array $extras = []): string
+ final function getFieldFormByByItemType(string $field, mixed $value, array $viewDatas, array $extras = []): string
{
- $form = "";
- // dd($viewDatas);
+ // dd($viewDatas['control']);
$item_type = $viewDatas['control']['filter_values']['item_type'];
//Field는 item_uid이지만 , item_tpe에 따라 filter_options가 달라진다.
switch ($item_type) {
case "IP":
- if (!is_array($viewDatas['control']['filter_optons'][$item_type])) {
- throw new \Exception(__METHOD__ . "에서 {$item_type}의 field_options가 array형태가 아닙니다.");
- }
- //CodeIgniter 4의 form_dropdown()은 options 배열로만 값을 받기 때문에, disabled 속성 같은 개별 옵션에 대한 HTML 속성 추가는 기본적으로 지원하지 않습니다.
- $form_temps = ["';
- $form = implode("", $form_temps);
+ // $options = ["" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택'];
+ // // index_content_top_filter가 있으면 disabled를 설정하지 않음
+ // // action이 modify_form이면 disabled로 설정하지 않음
+ // if (array_key_exists('index_content_top_filter', $extras) || ($viewDatas['control']['action'] == "modify_form" && $value == $filterEntity->getPK())) {
+ // $disabledKeys = [];
+ // }
+ $extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
+ $form = $this->form_dropdown_disabled($field, $value, $viewDatas['control']['filter_optons'][$item_type], $extras, IpEntity::STATUS_OCCUPIED);
break;
case 'DOMAIN':
- if (!is_array($viewDatas['control']['filter_optons'][$item_type])) {
- throw new \Exception(__METHOD__ . "에서 {$item_type}의 field_options가 array형태가 아닙니다.");
- }
- //CodeIgniter 4의 form_dropdown()은 options 배열로만 값을 받기 때문에, disabled 속성 같은 개별 옵션에 대한 HTML 속성 추가는 기본적으로 지원하지 않습니다.
- $form_temps = ["';
- $form = implode("", $form_temps);
+ $extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
+ $form = $this->form_dropdown_disabled($field, $value, $viewDatas['control']['filter_optons'][$item_type], $extras, DomainEntity::STATUS_OCCUPIED);
break;
case "LINE":
case "SERVER":
@@ -71,20 +42,8 @@ class ServiceItemHelper extends CustomerHelper
case "STORAGE":
case "SOFTWARE":
case "DEFENCE":
- // dd($viewDatas['control']['filter_optons']);
- if (!is_array($viewDatas['control']['filter_optons'][$item_type])) {
- throw new \Exception(__METHOD__ . "에서 {$item_type}의 field_options가 array형태가 아닙니다.");
- }
- //CodeIgniter 4의 form_dropdown()은 options 배열로만 값을 받기 때문에, disabled 속성 같은 개별 옵션에 대한 HTML 속성 추가는 기본적으로 지원하지 않습니다.
- $form_temps = ["';
- $form = implode("", $form_temps);
+ $extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
+ $form = $this->form_dropdown_disabled($field, $value, $viewDatas['control']['filter_optons'][$item_type], $extras);
break;
default:
$form = parent::getFieldForm($field, $value, $viewDatas, $extras);
@@ -96,7 +55,7 @@ class ServiceItemHelper extends CustomerHelper
{
switch ($field) {
case 'item_uid':
- $form = $this->getFieldFormByItemType($field, $value, $viewDatas, $extras);
+ $form = $this->getFieldFormByByItemType($field, $value, $viewDatas, $extras);
break;
default:
$form = parent::getFieldForm($field, $value, $viewDatas, $extras);
diff --git a/app/Services/Customer/CustomerService.php b/app/Services/Customer/CustomerService.php
index dae9967..dd1203c 100644
--- a/app/Services/Customer/CustomerService.php
+++ b/app/Services/Customer/CustomerService.php
@@ -125,6 +125,11 @@ abstract class CustomerService extends CommonService
}
return $options;
}
+ //ItemType에 따른 FilterOption 설정용
+ final public function getFilterOptionsByItemType(string $item_type): array
+ {
+ return $this->getServiceItemLinkService($item_type)->getEntities();
+ }
final public function getClient(int $uid): ClientEntity
{
$entity = $this->getClientService()->getEntity($uid);
diff --git a/app/Services/Customer/ServiceService.php b/app/Services/Customer/ServiceService.php
index 358ec72..0011a46 100644
--- a/app/Services/Customer/ServiceService.php
+++ b/app/Services/Customer/ServiceService.php
@@ -127,23 +127,15 @@ class ServiceService extends CustomerService
}
return $options;
}
-
- //ItemType에 따른 FilterOption 설정용
- public function getFilterOptionsByItemType(string $item_type): array
- {
- return $this->getServiceItemLinkService($item_type)->getEntities();
- }
//Service마다 ItemEntities 설정용
public function setItemEntitiesByService(ServiceEntity $entity): ServiceEntity
{
foreach (SERVICE_ITEM_TYPES as $item_type => $label) {
- $entity->setItemEntities(
- $item_type,
- $this->getServiceItemService()->getEntities([
- 'serviceinfo_uid' => $entity->getPK(),
- 'item_type' => $item_type
- ])
- );
+ $itemEntities = $this->getServiceItemService()->getEntities([
+ 'serviceinfo_uid' => $entity->getPK(),
+ 'item_type' => $item_type
+ ]);
+ $entity->setItemEntities($item_type, $itemEntities);
}
return $entity;
}