dbms/app/Controllers/Admin/Equipment/Link/LinkController.php
2025-05-27 11:33:35 +09:00

84 lines
2.8 KiB
PHP

<?php
namespace App\Controllers\Admin\Equipment\Link;
use App\Controllers\Admin\Equipment\EquipmentController;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use App\Services\Equipment\ServerService;
abstract class LinkController extends EquipmentController
{
private ?ServerService $_serverService = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
}
final public function getServerService(): ServerService
{
if (!$this->_serverService) {
$this->_serverService = new ServerService($this->request);
}
return $this->_serverService;
}
abstract public function getPartService(): mixed;
protected function setOrderByForList()
{
//OrderBy 처리
$this->getService()->getModel()->orderBy('serverinfo_uid', 'ASC', false);
parent::setOrderByForList();
}
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 . 'popup' . DIRECTORY_SEPARATOR . $action, ['viewDatas' => $this->getViewDatas()]);
break;
default:
$result = parent::getResultPageByActon($action, $message);
break;
}
return $result;
}
protected function getFormFieldOption(string $field, array $options): array
{
switch ($field) {
case 'serverinfo_uid':
$temps = [];
foreach ($this->getServerService()->getEntities() as $entity) {
$temps[$entity->getPK()] = $entity->getTitle();
}
$options[$field] = $temps;
// dd($options);
break;
case 'lineinfo_uid':
case 'ipinfo_uid':
case 'defenceinfo_uid':
case 'softwareinfo_uid':
case 'domaininfo_uid':
case 'cpuinfo_uid':
case 'raminfo_uid':
case 'diskinfo_uid':
$temps = [];
foreach ($this->getPartService()->getEntities() as $entity) {
$temps[$entity->getPK()] = $entity->getTitle();
}
$options[$field] = $temps;
// dd($options);
break;
default:
$options = parent::getFormFieldOption($field, $options);
break;
}
return $options;
}
}