117 lines
4.3 KiB
PHP
117 lines
4.3 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 initAction(string $action): void
|
|
{
|
|
//$item_type(CPU,RAM,STORAGE등)에 따라 선언된 getFormFieldOption용 사용됨 (initAction보다 먼저 호출해야 됨)
|
|
$this->initServiceItemOptions();
|
|
parent::initAction($action);
|
|
}
|
|
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;
|
|
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
|
|
{
|
|
$entities = [];
|
|
foreach (parent::index_process() as $entity) {
|
|
foreach (SERVICE_ITEM_TYPES as $item_type) {
|
|
$entity->setItemEntities(
|
|
$item_type,
|
|
$this->getServiceItemService()->getEntities(['serviceinfo_uid' => $entity->getPK(), 'item_type' => $item_type])
|
|
);
|
|
}
|
|
$entities[] = $entity;
|
|
}
|
|
// $this->modal_type = 'modal_fetch_v2'; //기본은 modal_iframe임
|
|
return $entities;
|
|
}
|
|
}
|