122 lines
4.6 KiB
PHP
122 lines
4.6 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Admin\Customer;
|
|
|
|
use App\Helpers\Customer\ServiceHelper;
|
|
use App\Services\Customer\ServiceService;
|
|
use App\Services\Equipment\Part\CpuService;
|
|
|
|
use App\Services\Equipment\Part\DefenceService;
|
|
use App\Services\Equipment\Part\DiskService;
|
|
|
|
use App\Services\Equipment\Part\IpService;
|
|
use App\Services\Equipment\Part\LINEService;
|
|
use App\Services\Equipment\Part\RamService;
|
|
use App\Services\Equipment\Part\SoftwareService;
|
|
use App\Services\Equipment\ServereService;
|
|
use CodeIgniter\HTTP\RedirectResponse;
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
class ServiceController extends CustomerController
|
|
{
|
|
private $_adapterService = [];
|
|
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);
|
|
}
|
|
// dd($this->_helper);
|
|
return $this->_helper;
|
|
}
|
|
final public function getAdapterService(string $key): mixed
|
|
{
|
|
if (!array_key_exists($key, $this->_adapterService)) {
|
|
switch ($key) {
|
|
case 'SERVER':
|
|
$this->_adapterService[$key] = new ServereService();
|
|
break;
|
|
case 'CPU':
|
|
$this->_adapterService[$key] = new CpuService();
|
|
break;
|
|
case 'RAM':
|
|
$this->_adapterService[$key] = new RamService();
|
|
break;
|
|
case 'DISK':
|
|
$this->_adapterService[$key] = new DiskService();
|
|
break;
|
|
case 'LINE':
|
|
$this->_adapterService[$key] = new LineService();
|
|
break;
|
|
case 'IP':
|
|
$this->_adapterService[$key] = new IpService();
|
|
break;
|
|
case 'DEFENCE':
|
|
$this->_adapterService[$key] = new DefenceService();
|
|
break;
|
|
case 'SOFTWARE':
|
|
$this->_adapterService[$key] = new SoftwareService();
|
|
break;
|
|
default:
|
|
throw new \Exception("Unknown adapter service key: {$key}");
|
|
}
|
|
}
|
|
return $this->_adapterService[$key];
|
|
}
|
|
protected function getResultPageByActon(string $action, string $message = MESSAGES["SUCCESS"]): RedirectResponse|string
|
|
{
|
|
switch ($action) {
|
|
case 'index':
|
|
$this->getHelper()->setViewDatas($this->getViewDatas());
|
|
$result = view($this->view_path . 'service' . DIRECTORY_SEPARATOR . $action, ['viewDatas' => $this->getViewDatas()]);
|
|
break;
|
|
default:
|
|
$result = parent::getResultPageByActon($action, $message);
|
|
break;
|
|
}
|
|
return $result;
|
|
}
|
|
//Index,FieldForm관련
|
|
|
|
// protected function create_process(): mixed
|
|
// {
|
|
// $entity = parent::create_process();
|
|
// //사용중인 서버로 변경
|
|
// $this->getServerService()->setOccupied($this->getServerService()->getEntity($entity->getServerInfoUID()));
|
|
// return $entity;
|
|
// }
|
|
protected function index_process(): array
|
|
{
|
|
$fields = [
|
|
'fields' => ['clientinfo_uid', 'item_type', 'billing_at', 'rack', 'LINE', 'SERVER', 'IP', 'CPU', 'RAM', 'DISK', 'SOFTWARE', 'DEFENCE', 'start_at', 'status'],
|
|
];
|
|
$this->init('index', $fields);
|
|
$this->adapterFields = ['LINE', 'IP', 'SERVER', 'CPU', 'RAM', 'DISK', 'DEFENCE', 'SOFTWARE'];
|
|
$entities = [];
|
|
foreach (parent::index_process() as $entity) {
|
|
foreach ($this->adapterFields as $field) {
|
|
$entity->setAdaptertEntities($field, $this->getAdapterService($field)->getEntities());
|
|
}
|
|
$entities[] = $entity;
|
|
}
|
|
return $entities;
|
|
}
|
|
}
|