dbms/app/Controllers/Admin/Customer/ServiceController.php
2025-06-11 17:14:53 +09:00

129 lines
4.8 KiB
PHP

<?php
namespace App\Controllers\Admin\Customer;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use App\Helpers\Customer\ServiceHelper;
use App\Services\Customer\ServiceService;
use App\Services\Customer\ServiceItemService;
use App\Entities\Equipment\CodeEntity;
use App\Services\Equipment\CodeService;
class ServiceController extends CustomerController
{
private ?ServiceItemService $_serviceItemService = null;
private ?CodeService $_codeService = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->content_title = lang("{$this->getService()->getClassName()}.title");
$this->class_path .= $this->getService()->getClassName();
$this->uri_path .= strtolower($this->getService()->getClassName('/')) . '/';
// $this->view_path .= strtolower($this->getService()->getClassName()) . DIRECTORY_SEPARATOR;
}
public function getService(): ServiceService
{
if (!$this->_service) {
$this->_service = new ServiceService($this->request);
}
return $this->_service;
}
public function getHelper(): ServiceHelper
{
if (!$this->_helper) {
$this->_helper = new ServiceHelper($this->request);
}
return $this->_helper;
}
public function getCodeService(): CodeService
{
if (!$this->_codeService) {
$this->_codeService = new CodeService($this->request);
}
return $this->_codeService;
}
public function getServiceItemService(): ServiceItemService
{
if (!$this->_serviceItemService) {
$this->_serviceItemService = new ServiceItemService($this->request);
}
return $this->_serviceItemService;
}
protected function getFormFieldOption(string $field, array $options = []): array
{
switch ($field) {
case 'ownerinfo_uid':
foreach ($this->getClientService()->getEntities() as $entity) {
$options[$entity->getPK()] = $entity->getTitle();
}
break;
case 'code':
$occupied_codes = [];
foreach ($this->getCodeService()->getEntities() as $entity) {
$options[$entity->getPK()] = $entity->getTitle();
if ($entity->getStatus() === CodeEntity::STATUS_OCCUPIED) {
$occupied_codes[] = $entity->getPK();
}
}
//code의 경우 사용중인 filter_options코드전달용
$this->occupied_codes = $occupied_codes;
break;
case 'SERVER':
case 'CPU':
case 'RAM':
case 'STORAGE':
case 'LINE':
case 'IP':
case 'DEFENCE':
case 'SOFTWARE':
case 'DOMAIN':
foreach ($this->getService()->getEquipmentService($field)->getEntities() as $entity) {
$options[$entity->getPK()] = $entity->getTitle();
}
break;
default:
$options = parent::getFormFieldOption($field, $options);
break;
}
return $options;
}
protected function getResultSuccess(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string
{
switch ($this->getAction()) {
case 'index':
$result = parent::getResultSuccess($message, $this->request->getVar('ActionTemplate') ?? $actionTemplate ?? 'service');
break;
default:
$result = parent::getResultSuccess($message, $actionTemplate);
break;
}
return $result;
}
//Index,FieldForm관련
protected function index_process(): array
{
//추가 Field작업 처리
$this->item_types = lang($this->getServiceItemService()->getClassName() . '.' . strtoupper('ITEM_TYPE'));
foreach ($this->item_types as $field => $label) {
$this->setFilterFieldOption($field, $this->getFormFieldOption($field));
}
$entities = [];
foreach (parent::index_process() as $entity) {
foreach ($this->item_types as $field => $label) {
$entity->setItemEntities(
$field,
$this->getServiceItemService()->getEntities(['serviceinfo_uid' => $entity->getPK(), 'item_type' => $field])
);
}
$entities[] = $entity;
}
// $this->modal_type = 'modal_fetch_v2'; //기본은 modal_iframe임
return $entities;
}
}