dbms/app/Controllers/Admin/UserController.php
2025-05-01 11:16:56 +09:00

108 lines
3.6 KiB
PHP

<?php
namespace App\Controllers\Admin;
use App\Helpers\UserHelper as Helper;
use App\Services\UserService as Service;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Validation\Validation;
use Psr\Log\LoggerInterface;
class UserController extends AdminController
{
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->uri_path .= strtolower($this->getService()->getClassName()) . '/';
$this->title = lang("{$this->getService()->getClassPath()}.title");
$this->helper = new Helper($this->getService());
}
protected function getServiceClass(): Service
{
if ($this->service === null) {
$this->service = new Service($this->request);
}
return $this->service;
}
//Index,FieldForm관련
public function getFields(): array
{
return ['id', $this->getService()->getModel()::TITLE, 'email', 'mobile', 'role', 'status'];
}
public function getFilterFields(): array
{
return ['role', 'status'];
}
public function getBatchJobFields(): array
{
return ['status'];
}
protected function setValidation(string $action, string $field, string $rule, Validation $validation): Validation
{
switch ($field) {
case 'role':
//아래 Rule Array는 필드명.* checkbox를 사용
$validation->setRule("{$field}.*", $field, $rule);
break;
default:
$validation = parent::setValidation($action, $field, $rule, $validation);
break;
}
return $validation;
}
//Index,FieldForm관련.
protected function getResultPageByActon(string $action, string $message = MESSAGES["SUCCESS"]): RedirectResponse|string
{
switch ($action) {
case 'create':
case 'modify':
$url = base_url() . $this->uri_path . "view/" . $this->entity->getPK();
$result = redirect()->to($url)->with('error', $message);
break;
default:
$result = parent::getResultPageByActon($action, $message);
break;
}
return $result;
}
//생성
protected function create_form_process(): void
{
$fields = [
'fields' => ['id', 'passwd', 'confirmpassword', $this->getService()->getModel()::TITLE, 'email', 'mobile', 'role'],
];
$this->init('create_form', $fields);
parent::create_form_process();
}
protected function create_process(): mixed
{
$fields = [
'fields' => ['id', 'passwd', 'confirmpassword', $this->getService()->getModel()::TITLE, 'email', 'mobile', 'role'],
];
$this->init('create', $fields);
return parent::create_process();
}
//수정
protected function modify_form_process(mixed $uid): mixed
{
$fields = [
'fields' => ['id', 'passwd', 'confirmpassword', $this->getService()->getModel()::TITLE, 'email', 'mobile', 'role'],
];
$this->init('modify_form', $fields);
return parent::modify_form_process($uid);
}
protected function modify_process($uid): mixed
{
$fields = [
'fields' => ['id', 'passwd', 'confirmpassword', $this->getService()->getModel()::TITLE, 'email', 'mobile', 'role', 'status'],
];
$this->init('modify', $fields);
return parent::modify_process($uid);
}
}