dbms/app/Controllers/Admin/Customer/AccountController.php
2025-05-06 10:26:18 +09:00

116 lines
3.9 KiB
PHP

<?php
namespace App\Controllers\Admin\Customer;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Validation\Validation;
use Psr\Log\LoggerInterface;
use App\Helpers\Customer\AccountHelper;
use App\Services\Customer\AccountService;
class AccountController extends CustomerController
{
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(): AccountService
{
if (!$this->_service) {
$this->_service = new AccountService($this->request);
}
return $this->_service;
}
public function getHelper(): mixed
{
if (!$this->_helper) {
$this->_helper = new AccountHelper($this->request);
}
return $this->_helper;
}
//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(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':
$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);
}
}