174 lines
6.3 KiB
PHP
174 lines
6.3 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Admin\Customer;
|
|
|
|
use App\Entities\Customer\ServicePartEntity;
|
|
use App\Helpers\Customer\ServiceHelper;
|
|
use App\Services\Customer\ServiceService;
|
|
use App\Services\Equipment\PartService;
|
|
use App\Services\Equipment\IpService;
|
|
|
|
use App\Services\Equipment\ServerService;
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use CodeIgniter\Validation\Validation;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
class ServiceController extends CustomerController
|
|
{
|
|
private ?ServerService $_serverService = null;
|
|
private ?PartService $_partService = null;
|
|
private ?IpService $_ipService = null;
|
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
|
{
|
|
parent::initController($request, $response, $logger);
|
|
$this->uri_path .= strtolower($this->getService()->getClassName()) . '/';
|
|
$this->view_path .= strtolower($this->getService()->getClassName()) . DIRECTORY_SEPARATOR;
|
|
// echo $this->view_path;
|
|
// exit;
|
|
$this->class_path = $this->getService()->getClassPath();
|
|
$this->title = lang("{$this->getService()->getClassPath()}.title");
|
|
$this->helper = $this->getHelper();
|
|
$this->individualStylesheets = ['server_partinfo.css'];;
|
|
$this->individualScripts = ['server_partinfo.js'];
|
|
}
|
|
public function getService(): ServiceService
|
|
{
|
|
if (!$this->_service) {
|
|
$this->_service = new ServiceService($this->request);
|
|
}
|
|
return $this->_service;
|
|
}
|
|
public function getHelper(): mixed
|
|
{
|
|
if (!$this->_helper) {
|
|
$this->_helper = new ServiceHelper($this->request);
|
|
}
|
|
return $this->_helper;
|
|
}
|
|
final public function getServerService(): ServerService
|
|
{
|
|
if (!$this->_serverService) {
|
|
$this->_serverService = new ServerService();
|
|
}
|
|
return $this->_serverService;
|
|
}
|
|
final public function getPartService(): PartService
|
|
{
|
|
if (!$this->_partService) {
|
|
$this->_partService = new PartService($this->request);
|
|
}
|
|
return $this->_partService;
|
|
}
|
|
final public function getIpService(): IpService
|
|
{
|
|
if (!$this->_ipService) {
|
|
$this->_ipService = new IpService();
|
|
}
|
|
return $this->_ipService;
|
|
}
|
|
|
|
//Index,FieldForm관련
|
|
protected function getFieldRule(string $action, string $field): string
|
|
{
|
|
if (is_array($field)) {
|
|
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
|
|
}
|
|
switch ($field) {
|
|
case 'CPU':
|
|
case 'RAM':
|
|
case 'DISK':
|
|
$rule = "if_exist|permit_empty|numeric";
|
|
break;
|
|
default:
|
|
$rule = parent::getFieldRule($action, $field);
|
|
break;
|
|
}
|
|
return $rule;
|
|
}
|
|
protected function getFormFieldOption(string $field, array $options = []): array
|
|
{
|
|
switch ($field) {
|
|
case 'SERVER':
|
|
$options[$field] = $this->getServerService()->getFormFieldOption($field);
|
|
break;
|
|
case 'CPU':
|
|
case 'RAM':
|
|
case 'DISK':
|
|
$options[$field] = $this->getPartService()->getFormFieldOption($field);
|
|
break;
|
|
case 'IP':
|
|
$options[$field] = $this->getIPService()->getFormFieldOption($field);
|
|
break;
|
|
default:
|
|
$options = parent::getFormFieldOption($field, $options);
|
|
break;
|
|
}
|
|
return $options;
|
|
}
|
|
protected function setValidation(Validation $validation, string $action, string $field, ?string $rule = null): Validation
|
|
{
|
|
switch ($field) {
|
|
case 'SERVER':
|
|
case 'CPU':
|
|
case 'RAM':
|
|
case 'DISK':
|
|
case 'IP':
|
|
//아래 Rule Array는 필드명.* checkbox를 사용
|
|
$validation->setRule("{$field}.*", $field, $rule);
|
|
break;
|
|
default:
|
|
$validation = parent::setValidation($validation, $action, $field, $rule);
|
|
break;
|
|
}
|
|
return $validation;
|
|
}
|
|
//Index,FieldForm관련
|
|
|
|
protected function create_process(): mixed
|
|
{
|
|
$entity = parent::create_process();
|
|
//변경할 UIDS
|
|
$cpu_uids = $this->request->getVar('CPU[]');
|
|
if (!is_array($cpu_uids)) {
|
|
throw new \Exception("CPU가 정의되지 않았습니다.");
|
|
}
|
|
foreach ($cpu_uids as $uid) {
|
|
$temps = ['serviceinfo_uid' => $entity->getPK(), 'partinfo_uid' => $uid];
|
|
$this->getService()->create($temps, new ServicePartEntity());
|
|
}
|
|
$ram_uids = $this->request->getVar('RAM[]');
|
|
if (!is_array($ram_uids)) {
|
|
throw new \Exception("RAM가 정의되지 않았습니다.");
|
|
}
|
|
foreach ($ram_uids as $uid) {
|
|
$temps = ['serviceinfo_uid' => $entity->getPK(), 'partinfo_uid' => $uid];
|
|
$this->getService()->create($temps, new ServicePartEntity());
|
|
}
|
|
$disk_uids = $this->request->getVar('DISK[]');
|
|
if (!is_array($disk_uids)) {
|
|
throw new \Exception("DISK가 정의되지 않았습니다.");
|
|
}
|
|
foreach ($disk_uids as $uid) {
|
|
$temps = ['serviceinfo_uid' => $entity->getPK(), 'partinfo_uid' => $uid];
|
|
$this->getService()->create($temps, new ServicePartEntity());
|
|
}
|
|
return $entity;
|
|
}
|
|
protected function index_process(): array
|
|
{
|
|
$fields = [
|
|
'fields' => ['clientinfo_uid', 'type', $this->getService()->getModel()->getTitleField(), 'billing_at', 'start_at', 'end_at', 'status'],
|
|
];
|
|
$this->init('index', $fields);
|
|
$this->modal_type = 'modal_iframe';
|
|
$entities = parent::index_process();
|
|
foreach ($entities as $key => $entity) {
|
|
$entity->CPU = $this->getServerService()->getEntities(['serverinfo_uid' => $entity->getPK()]);
|
|
$entity->RAM = $this->getServerService()->getEntities(['serverinfo_uid' => $entity->getPK()]);
|
|
$entity->DISK = $this->getServerService()->getEntities(['serverinfo_uid' => $entity->getPK()]);
|
|
}
|
|
return $entities;
|
|
}
|
|
}
|