149 lines
5.6 KiB
PHP
149 lines
5.6 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Admin\Customer;
|
|
|
|
use App\Entities\Equipment\CodeEntity;
|
|
use App\Helpers\Customer\ServiceHelper;
|
|
use App\Services\Customer\ServiceItemService;
|
|
use App\Services\Customer\ServiceService;
|
|
|
|
use App\Services\Equipment\CodeService;
|
|
use CodeIgniter\HTTP\RedirectResponse;
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
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->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':
|
|
foreach ($this->getCodeService()->getEntities() as $entity) {
|
|
$options[$entity->getPK()] = $entity->getTitle();
|
|
}
|
|
break;
|
|
case 'SERVER':
|
|
case 'CPU':
|
|
case 'RAM':
|
|
case 'STORAGE':
|
|
case 'LINE':
|
|
case 'IP':
|
|
case 'DEFENCE':
|
|
case 'SOFTWARE':
|
|
case 'DOMAIN':
|
|
foreach ($this->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"]): RedirectResponse|string
|
|
{
|
|
switch ($this->getAction()) {
|
|
case 'index':
|
|
$this->control = $this->getControlDatas();
|
|
$this->getHelper()->setViewDatas($this->getViewDatas());
|
|
$result = view($this->view_path . 'service' . DIRECTORY_SEPARATOR . $this->getAction(), ['viewDatas' => $this->getViewDatas()]);
|
|
break;
|
|
default:
|
|
$result = parent::getResultSuccess($message);
|
|
break;
|
|
}
|
|
return $result;
|
|
}
|
|
//Index,FieldForm관련
|
|
private function setCodeStatus(string $code, string $status): void
|
|
{
|
|
//coded의 경우 사용가능/사용중으로 설정작업
|
|
$codeEntity = $this->getCodeService()->getEntity($code);
|
|
if (!$codeEntity) {
|
|
throw new \Exception("{$code}에 대한 서버코드정보를 찾을수 없습니다.");
|
|
}
|
|
$codeEntity = $this->getCodeService()->setStatus($codeEntity, $status);
|
|
if (!$codeEntity) {
|
|
throw new \Exception("{$code}에 대한 {$status} 상태설정에 실패하였습니다.");
|
|
}
|
|
}
|
|
protected function create_process(array $formDatas): mixed
|
|
{
|
|
//coded의 경우 서비스중으로 설정작업
|
|
$this->setCodeStatus($formDatas['code'], CodeEntity::STATUS_OCCUPIED);
|
|
return parent::create_process($formDatas);
|
|
}
|
|
protected function delete_process(mixed $entity): mixed
|
|
{
|
|
//coded의 경우 사용가능으로 설정작업
|
|
$this->setCodeStatus($entity->getCode(), CodeEntity::STATUS_AVAILABLE);
|
|
return parent::delete_process($entity);
|
|
}
|
|
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;
|
|
}
|
|
}
|