111 lines
3.8 KiB
PHP
111 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Admin;
|
|
|
|
use App\Helpers\UserHelper;
|
|
use App\Models\UserModel;
|
|
use App\Services\UserService;
|
|
use CodeIgniter\HTTP\DownloadResponse;
|
|
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->title = lang("{$this->getService()->class_path}.title");
|
|
$this->helper = new UserHelper();
|
|
}
|
|
protected function getModel(): UserModel
|
|
{
|
|
if ($this->_model === null) {
|
|
$this->_model = new UserModel();
|
|
}
|
|
return $this->_model;
|
|
}
|
|
protected function getService(): UserService
|
|
{
|
|
if ($this->service === null) {
|
|
$this->service = new UserService();
|
|
}
|
|
return $this->service;
|
|
}
|
|
protected function setValidationRule($field, Validation $validation, string $action): Validation
|
|
{
|
|
switch ($field) {
|
|
case 'role':
|
|
//아래 Rule Array는 필드명.* checkbox를 사용
|
|
$validation->setRule($field . ".*", $field, $this->getModel()->getFieldRule($action, $field));
|
|
break;
|
|
default:
|
|
$validation = parent::setValidationRule($field, $validation, $action);
|
|
break;
|
|
}
|
|
return $validation;
|
|
}
|
|
private function init(string $action, array $fields = []): void
|
|
{
|
|
$this->action = $action;
|
|
$this->fields = count($fields) ? $fields : ['id', $this->getModel()::TITLE, 'email', 'mobile', 'role', 'updated_at', 'created_at'];
|
|
$this->field_rules = $this->getModel()->getFieldRules($action, $this->fields);
|
|
$this->filter_fields = ['role', 'status'];
|
|
$this->field_options = $this->getFormFieldOptions($this->filter_fields);
|
|
$this->batchjob_fields = ['status'];
|
|
}
|
|
//생성
|
|
public function create_form(): RedirectResponse|string
|
|
{
|
|
$this->init('create', ['id', 'passwd', 'confirmpassword', $this->getModel()::TITLE, 'email', 'mobile', 'role']);
|
|
return $this->create_form_procedure();
|
|
}
|
|
public function create(): RedirectResponse|string
|
|
{
|
|
$this->init(__FUNCTION__, ['id', 'passwd', 'confirmpassword', $this->getModel()::TITLE, 'email', 'mobile', 'role']);
|
|
return $this->create_procedure();
|
|
}
|
|
//수정
|
|
public function modify_form(int $uid): RedirectResponse|string
|
|
{
|
|
$this->init('modify', ['passwd', 'confirmpassword', $this->getModel()::TITLE, 'email', 'mobile', 'role']);
|
|
return $this->modify_form_procedure($uid);
|
|
}
|
|
public function modify(int $uid): RedirectResponse|string
|
|
{
|
|
$this->init(__FUNCTION__, ['passwd', 'confirmpassword', $this->getModel()::TITLE, 'email', 'mobile', 'role']);
|
|
return $this->modify_procedure($uid);
|
|
}
|
|
public function toggle(mixed $uid, string $field): RedirectResponse
|
|
{
|
|
return $this->toggle_procedure($uid, $field);
|
|
}
|
|
//일괄작업
|
|
public function batchjob(): RedirectResponse
|
|
{
|
|
$this->init(__FUNCTION__);
|
|
return $this->batchjob_procedure();
|
|
}
|
|
//View
|
|
public function view(int $uid): RedirectResponse|string
|
|
{
|
|
$this->init(__FUNCTION__);
|
|
return $this->view_procedure($uid);
|
|
}
|
|
// 리스트
|
|
public function index(): string
|
|
{
|
|
$this->init(__FUNCTION__);
|
|
return $this->list_procedure();
|
|
}
|
|
// Download
|
|
public function download(string $output_type, mixed $uid = false): DownloadResponse|string
|
|
{
|
|
$this->init(__FUNCTION__);
|
|
return $this->download_procedure($output_type, $uid);
|
|
}
|
|
}
|