77 lines
2.5 KiB
PHP
77 lines
2.5 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()) . DIRECTORY_SEPARATOR;
|
|
$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, Validation $validation): Validation
|
|
{
|
|
switch ($field) {
|
|
case 'role':
|
|
//아래 Rule Array는 필드명.* checkbox를 사용
|
|
$validation->setRule("{$field}.*", $field, $this->getService()->getModel()->getFieldRule($action, $field));
|
|
break;
|
|
default:
|
|
$validation = parent::setValidation($action, $field, $validation);
|
|
break;
|
|
}
|
|
return $validation;
|
|
}
|
|
//Index,FieldForm관련
|
|
|
|
//생성
|
|
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_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);
|
|
}
|
|
}
|