108 lines
3.6 KiB
PHP
108 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Admin\Equipment;
|
|
|
|
use App\Entities\Equipment\ServerEntity;
|
|
use App\Helpers\Equipment\ServerHelper;
|
|
use App\Services\Equipment\ServerService;
|
|
use CodeIgniter\HTTP\RedirectResponse;
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
class ServerController extends EquipmentController
|
|
{
|
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
|
{
|
|
parent::initController($request, $response, $logger);
|
|
$this->content_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(): ServerService
|
|
{
|
|
if (!$this->_service) {
|
|
$this->_service = new ServerService();
|
|
}
|
|
return $this->_service;
|
|
}
|
|
public function getHelper(): ServerHelper
|
|
{
|
|
if (!$this->_helper) {
|
|
$this->_helper = new ServerHelper();
|
|
}
|
|
return $this->_helper;
|
|
}
|
|
//Index,FieldForm관련
|
|
protected function getResultSuccess(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string
|
|
{
|
|
switch ($this->getAction()) {
|
|
case 'view':
|
|
case 'index':
|
|
$this->control = $this->getControlDatas();
|
|
$this->getHelper()->setViewDatas($this->getViewDatas());
|
|
$actionTemplate = $this->request->getVar('ActionTemplate') ?? $actionTemplate ?? 'server';
|
|
if ($actionTemplate) {
|
|
$view_file = $this->view_path . $actionTemplate . DIRECTORY_SEPARATOR . $this->getAction();
|
|
} else {
|
|
$view_file = $this->view_path . $this->getAction();
|
|
}
|
|
$result = view($view_file, ['viewDatas' => $this->getViewDatas()]);
|
|
break;
|
|
default:
|
|
$result = parent::getResultSuccess($message, $actionTemplate);
|
|
break;
|
|
}
|
|
return $result;
|
|
}
|
|
protected function setFormData(string $field, array $requestDatas, array $formDatas): array
|
|
{
|
|
switch ($field) {
|
|
case 'CPU':
|
|
case 'RAM':
|
|
$formDatas[$field] = $requestDatas[$field] ?? null;
|
|
$formDatas["{$field}_cnt"] = $requestDatas["{$field}_cnt"] ?? null;
|
|
break;
|
|
case 'DISK':
|
|
$formDatas[$field] = $requestDatas[$field] ?? null;
|
|
$formDatas["{$field}_cnt"] = $requestDatas["{$field}_cnt"] ?? null;
|
|
$formDatas["{$field}_extra"] = $requestDatas["{$field}_extra"] ?? null;
|
|
break;
|
|
default:
|
|
$formDatas = parent::setFormData($field, $requestDatas, $formDatas);
|
|
}
|
|
return $formDatas;
|
|
}
|
|
//생성
|
|
protected function create_form_process(): void
|
|
{
|
|
$format = env("Server.Prefix.code.format", false);
|
|
if (!$format) {
|
|
throw new \Exception(__METHOD__ . "에서 code의 format[Server.Prefix.code.format]이 정의되지 않았습니다.");
|
|
}
|
|
//기본값정의
|
|
$this->setFormDatas([
|
|
'code' => $this->getService()->getLastestCode(
|
|
$format,
|
|
(int)env("Server.Default.code", 0)
|
|
)
|
|
]);
|
|
parent::create_form_process();
|
|
}
|
|
//생성
|
|
protected function create_process(array $formDatas): ServerEntity
|
|
{
|
|
//코드 패턴체크
|
|
$this->getService()->codeCheck($formDatas);
|
|
return parent::create_process($formDatas);
|
|
}
|
|
//수정
|
|
protected function modify_process(mixed $entity, array $formDatas): ServerEntity
|
|
{
|
|
//코드 패턴체크
|
|
$this->getService()->codeCheck($formDatas);
|
|
return parent::modify_process($entity, $formDatas);
|
|
}
|
|
}
|