87 lines
2.8 KiB
PHP
87 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Admin\Equipment;
|
|
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
use App\Entities\Equipment\LineEntity;
|
|
use App\Helpers\Equipment\LineHelper;
|
|
use App\Services\Equipment\LineService;
|
|
use App\Services\Equipment\IpService;
|
|
use App\Entities\Equipment\IpEntity;
|
|
|
|
class LineController extends EquipmentController
|
|
{
|
|
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->class_path = $this->getService()->getClassPath();
|
|
$this->title = lang("{$this->getService()->getClassPath()}.title");
|
|
$this->helper = $this->getHelper();
|
|
}
|
|
public function getService(): LineService
|
|
{
|
|
if (!$this->_service) {
|
|
$this->_service = new LineService($this->request);
|
|
}
|
|
return $this->_service;
|
|
}
|
|
public function getHelper(): mixed
|
|
{
|
|
if (!$this->_helper) {
|
|
$this->_helper = new LineHelper($this->request);
|
|
}
|
|
return $this->_helper;
|
|
}
|
|
final public function getIpService(): IpService
|
|
{
|
|
if (!$this->_ipService) {
|
|
$this->_ipService = new IpService($this->request);
|
|
}
|
|
return $this->_ipService;
|
|
}
|
|
//Index,FieldForm관련
|
|
|
|
//생성
|
|
protected function create_process(): LineEntity
|
|
{
|
|
//Line 등록
|
|
if (!$this->getHelper()->isValidCIDR($this->formDatas['bandwith'])) {
|
|
throw new \Exception("{$this->formDatas['bandwith']}는 CIDR 형식에 부합되지 않습니다.");
|
|
}
|
|
$entity = parent::create_process();
|
|
// //IP 등록
|
|
foreach ($this->getHelper()->cidrToIpRange($this->formDatas['bandwith']) as $ip) {
|
|
$temps = [];
|
|
$temps['lineinfo_uid'] = $entity->getPK();
|
|
$temps['ip'] = $ip;
|
|
$temps['status'] = lang("{$this->getIpService()->getClassPath()}.DEFAULTS.status");
|
|
$this->getIpService()->create($temps, new IpEntity());
|
|
}
|
|
return $entity;
|
|
}
|
|
|
|
protected function view_process($uid): mixed
|
|
{
|
|
$fields = [
|
|
'fields' => ['clientinfo_uid', 'type', 'title', 'bandwith', 'status', "start_at", 'created_at'],
|
|
];
|
|
$this->init('view', $fields);
|
|
return parent::view_process($uid);
|
|
}
|
|
|
|
protected function index_process(): array
|
|
{
|
|
$fields = [
|
|
'fields' => ['clientinfo_uid', 'type', 'title', 'bandwith', 'status', "start_at", 'created_at'],
|
|
];
|
|
$this->init('index', $fields);
|
|
$this->modal_type = 'modal_iframe';
|
|
return parent::index_process();
|
|
}
|
|
}
|