147 lines
5.1 KiB
PHP
147 lines
5.1 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Admin\Customer;
|
|
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
use App\Entities\Customer\ServiceEntity;
|
|
use App\Helpers\Customer\ServiceHelper;
|
|
use App\Services\Customer\ServiceService;
|
|
|
|
use App\Services\Equipment\LineService;
|
|
use App\Services\Equipment\ServerService;
|
|
use App\Entities\Customer\ServiceServerEntity;
|
|
use App\Services\Customer\ServiceServerService;
|
|
use App\Services\Equipment\PartService;
|
|
use App\Services\Customer\ServicePartService;
|
|
use App\Services\Equipment\IpService;
|
|
|
|
|
|
class ServiceController extends CustomerController
|
|
{
|
|
private ?LineService $_lineService = null;
|
|
private ?ServerService $_serverService = null;
|
|
private ?ServiceServerService $_serviceServerService = null;
|
|
private ?PartService $_partService = null;
|
|
private ?ServicePartService $_servicePartService = 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;
|
|
$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 getLineService(): LineService
|
|
{
|
|
if (!$this->_lineService) {
|
|
$this->_lineService = new LineService();
|
|
}
|
|
return $this->_lineService;
|
|
}
|
|
final public function getServerService(): ServerService
|
|
{
|
|
if (!$this->_serverService) {
|
|
$this->_serverService = new ServerService();
|
|
}
|
|
return $this->_serverService;
|
|
}
|
|
final public function getServiceServerService(): ServiceServerService
|
|
{
|
|
if (!$this->_serviceServerService) {
|
|
$this->_serviceServerService = new ServiceServerService($this->request);
|
|
}
|
|
return $this->_serviceServerService;
|
|
}
|
|
final public function getPartService(): PartService
|
|
{
|
|
if (!$this->_partService) {
|
|
$this->_partService = new PartService($this->request);
|
|
}
|
|
return $this->_partService;
|
|
}
|
|
final public function getServicePartService(): ServicePartService
|
|
{
|
|
if (!$this->_servicePartService) {
|
|
$this->_servicePartService = new ServicePartService($this->request);
|
|
}
|
|
return $this->_servicePartService;
|
|
}
|
|
final public function getIpService(): IpService
|
|
{
|
|
if (!$this->_ipService) {
|
|
$this->_ipService = new IpService();
|
|
}
|
|
return $this->_ipService;
|
|
}
|
|
protected function getFormFieldOption(string $field, array $options): array
|
|
{
|
|
switch ($field) {
|
|
case 'lineinfo_uid':
|
|
$options = $this->getLineService()->getFormFieldOption($field);
|
|
break;
|
|
case 'serverinfo_uid':
|
|
$options = $this->getServerService()->getFormFieldOption($field);
|
|
break;
|
|
default:
|
|
$options = parent::getFormFieldOption($field, $options);
|
|
break;
|
|
}
|
|
// dd($options);
|
|
return $options;
|
|
}
|
|
//Index,FieldForm관련
|
|
|
|
private function setPartEntity(ServiceEntity $entity): ServiceEntity
|
|
{
|
|
foreach ($this->getServicePartService()->getEntities(['serviceinfo_uid' => $entity->getPK()]) as $servicePartEntity) {
|
|
$partEntity = $this->getPartService()->getEntity($servicePartEntity->getPartInfo());
|
|
if ($partEntity) {
|
|
$entity->addPartEntity($partEntity->getType(), $partEntity);
|
|
}
|
|
}
|
|
return $entity;
|
|
}
|
|
|
|
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' => ['type', 'clientinfo_uid', 'rack', 'lineinfo_uid', 'serverinfo_uid', 'IP', 'CPU', 'RAM', 'DISK', 'SOFTWARE', 'DEFENCE', 'billing_at', 'start_at', 'status'],
|
|
];
|
|
$this->init('index', $fields);
|
|
$this->modal_type = 'modal_iframe';
|
|
$entities = [];
|
|
foreach (parent::index_process() as $entity) {
|
|
$entities[] = $this->setPartEntity($entity);
|
|
}
|
|
return $entities;
|
|
}
|
|
}
|