dbms/app/Controllers/Admin/UserController.php
2025-05-06 19:08:29 +09:00

90 lines
2.9 KiB
PHP

<?php
namespace App\Controllers\Admin;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Validation\Validation;
use Psr\Log\LoggerInterface;
use App\Helpers\UserHelper;
use App\Services\UserService;
class UserController extends AdminController
{
private $_service = null;
private $_helper = 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();
}
final public function getService(): UserService
{
if (!$this->_service) {
$this->_service = new UserService($this->request);
}
return $this->_service;
}
public function getHelper(): mixed
{
if (!$this->_helper) {
$this->_helper = new UserHelper($this->request);
}
return $this->_helper;
}
//Index,FieldForm관련
protected function setValidation(Validation $validation, string $action, string $field, ?string $rule = null): Validation
{
switch ($field) {
case 'role':
//아래 Rule Array는 필드명.* checkbox를 사용
$validation->setRule("{$field}.*", $field, $rule);
break;
default:
$validation = parent::setValidation($validation, $action, $field, $rule);
break;
}
return $validation;
}
//Index,FieldForm관련.
protected function getResultPageByActon(string $action, string $message = MESSAGES["SUCCESS"]): RedirectResponse|string
{
switch ($action) {
case 'create':
case 'modify':
$this->getHelper()->setViewDatas($this->getViewDatas());
$result = view($this->view_path . 'view', ['viewDatas' => $this->getViewDatas()]);;
break;
default:
$result = parent::getResultPageByActon($action, $message);
break;
}
return $result;
}
//View관련
protected function view_process($uid): mixed
{
$fields = [
'fields' => ['id', $this->getService()->getModel()::TITLE, 'email', 'mobile', 'role', 'status'],
];
$this->init('view', $fields);
return parent::view_process($uid);
}
protected function index_process(): array
{
$fields = [
'fields' => ['id', $this->getService()->getModel()::TITLE, 'email', 'mobile', 'role', 'status'],
];
$this->init('index', $fields);
return parent::index_process();
}
}