93 lines
3.6 KiB
PHP
93 lines
3.6 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\ServiceItemHelper;
|
|
use App\Services\Customer\ServiceItemService;
|
|
use App\Services\Customer\ServiceService;
|
|
|
|
class ServiceItemController extends CustomerController
|
|
{
|
|
private ?ServiceService $_serviceService = null;
|
|
private $_equipmentService = [];
|
|
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(): ServiceItemService
|
|
{
|
|
if (!$this->_service) {
|
|
$this->_service = new ServiceItemService($this->request);
|
|
}
|
|
return $this->_service;
|
|
}
|
|
public function getHelper(): ServiceItemHelper
|
|
{
|
|
if (!$this->_helper) {
|
|
$this->_helper = new ServiceItemHelper($this->request);
|
|
}
|
|
return $this->_helper;
|
|
}
|
|
public function getServiceService(): ServiceService
|
|
{
|
|
if (!$this->_serviceService) {
|
|
$this->_serviceService = new ServiceService($this->request);
|
|
}
|
|
return $this->_serviceService;
|
|
}
|
|
|
|
protected function getFormFieldOption(string $field, array $options = []): array
|
|
{
|
|
switch ($field) {
|
|
case 'serviceinfo_uid':
|
|
foreach ($this->getServiceService()->getEntities() as $entity) {
|
|
$options[$entity->getPK()] = $entity->getTitle();
|
|
}
|
|
break;
|
|
case 'item_uid':
|
|
$item_type = $this->request->getVar('item_type');
|
|
if (!$item_type) {
|
|
throw new \Exception(__FUNCTION__ . "에서 item_type이 지정되지 않았습니다.");
|
|
}
|
|
//$item_type(CPU,RAM,STORAGE등)에 따라 선언된 getFormFieldOption사용 됨
|
|
foreach ($this->getEquipmentService($item_type)->getEntities() as $entity) {
|
|
$options[$entity->getPK()] = $entity->getTitle();
|
|
}
|
|
break;
|
|
default:
|
|
$options = parent::getFormFieldOption($field, $options);
|
|
break;
|
|
}
|
|
return $options;
|
|
}
|
|
//Index,FieldForm관련
|
|
protected function create_process(array $formDatas): mixed
|
|
{
|
|
//도메인의 경우 domaininfo에 등록 후 ServiceItemEntity의 item_uid에 넣고 create해야함
|
|
if ($formDatas['item_type'] === 'DOMAIN') {
|
|
$serviceEntity = $this->getServiceService()->getEntity($formDatas['serviceinfo_uid']);
|
|
if (!$serviceEntity) {
|
|
throw new \Exception("{$formDatas['serviceinfo_uid']}에 대한 서비스정보를 찾을수 없습니다.");
|
|
}
|
|
$equipmentEntity = $this->getEquipmentService($formDatas['item_type'])->create([
|
|
'clientinfo_uid' => $serviceEntity->getClientUID(),
|
|
'domain' => $formDatas['item_uid']
|
|
]);
|
|
//도메인용 항목의 item_uid로 전달함
|
|
$formDatas['item_uid'] = $equipmentEntity->getPK();
|
|
}
|
|
return parent::create_process($formDatas);
|
|
}
|
|
}
|