dbms/app/Controllers/Admin/Equipment/ServerPartController.php
2025-05-20 17:14:59 +09:00

94 lines
3.1 KiB
PHP

<?php
namespace App\Controllers\Admin\Equipment;
use App\Helpers\Equipment\ServerPartHelper;
use App\Services\Equipment\PartService;
use App\Services\Equipment\ServerPartService;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
class ServerPartController extends EquipmentController
{
private ?PartService $_partService = 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(): ServerPartService
{
if (!$this->_service) {
$this->_service = new ServerPartService($this->request);
}
return $this->_service;
}
public function getHelper(): mixed
{
if (!$this->_helper) {
$this->_helper = new ServerPartHelper($this->request);
}
return $this->_helper;
}
final public function getPartService(): PartService
{
if (!$this->_partService) {
$this->_partService = new PartService($this->request);
}
return $this->_partService;
}
protected function getFormFieldOption(string $field, array $options = []): array
{
switch ($field) {
case 'serverinfo_uid':
$options[$field] = $this->getServerService()->getFormFieldOption($field);
break;
case 'partinfo_uid':
$options[$field] = $this->getPartService()->getFormFieldOption($field);
break;
default:
$options = parent::getFormFieldOption($field, $options);
break;
}
return $options;
}
protected function getResultPageByActon(string $action, string $message = MESSAGES["SUCCESS"]): RedirectResponse|string
{
switch ($action) {
case 'index':
case 'view':
$this->getHelper()->setViewDatas($this->getViewDatas());
$result = view($this->view_path . "popup" . DIRECTORY_SEPARATOR . $action, ['viewDatas' => $this->getViewDatas()]);
break;
default:
$result = parent::getResultPageByActon($action, $message);
break;
}
return $result;
}
//Index,FieldForm관련
protected function setOrderByForList()
{
//OrderBy 처리
$this->getService()->getModel()->orderBy('serverinfo_uid', 'ASC', false);
parent::setOrderByForList();
}
protected function index_process(): array
{
$fields = [
'fields' => ['serverinfo_uid', 'type', 'partinfo_uid'],
];
$this->init('index', $fields);
$this->modal_type = 'modal_iframe';
return parent::index_process();
}
}