trafficmonitor/app/Controllers/Admin/UserController.php
2025-11-11 11:50:21 +09:00

88 lines
3.6 KiB
PHP

<?php
namespace App\Controllers\Admin;
use App\DTOs\UserDTO;
use App\Entities\UserEntity;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
class UserController extends AdminController
{
public const PATH = 'user';
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
if ($this->service === null) {
$this->service = service('userservice');
}
$this->addActionPaths($this::PATH);
}
//Action작업관련
protected function action_init_process(string $action): void
{
parent::action_init_process($action);
$fields = ['id', 'passwd', 'confirmpassword', 'name', 'email', 'mobile', 'role'];
$filters = ['role', 'status'];
switch ($action) {
case 'create':
case 'create_form':
case 'modify':
case 'modify_form':
break;
case 'view':
$fields = ['id', 'name', 'email', 'mobile', 'role', 'status', 'created_at'];
break;
case 'index':
$fields = ['id', 'name', 'email', 'mobile', 'role', 'status', 'created_at'];
$this->addViewDatas('index_batchjobFields', $this->service->getFormService()->getBatchjobFields($filters));
$this->addViewDatas('index_batchjobButtions', $this->service->getFormService()->getBatchjobButtons());
break;
default:
throw new \Exception("지원하지 않는 action입니다.({$action})");
// break;
}
$this->addViewDatas('helper', $this->service->getHelper());
$this->addViewDatas('formFields', $this->service->getFormService()->getFormFields($action, $fields));
$this->addViewDatas('formFilters', $this->service->getFormService()->getFormFilters($action, $filters));
$this->addViewDatas('formRules', $this->service->getFormService()->getFormRules($action, $fields));
$this->addViewDatas('formOptions', $this->service->getFormService()->getFormOptions($action, $filters));
}
protected function create_form_process(): void
{
//Form Default값 설정
$formDatas = ['role' => [ROLE['USER']['MANAGER']]];
$this->addViewDatas('formDatas', $formDatas);
}
protected function create_process(): array
{
//요청 데이터를 DTO 객체로 변환
$dto = new UserDTO($this->request->getPost());
$entity = $this->service->create($dto);
return array($entity, "{$entity->getTitle()} 계정 생성이 완료되었습니다.");
}
protected function modify_form_process($uid): void
{
if (!$uid) {
throw new \Exception("계정 번호가 정의 되지 않았습니다.");
}
$entity = $this->service->getEntity($uid);
if (!$entity instanceof UserEntity) {
throw new \Exception("{$uid}에 해당하는 계정을 찾을수 없습니다.");
}
$this->addViewDatas('entity', $entity);
}
protected function modify_process($uid): array
{
//요청 데이터를 DTO 객체로 변환
$dto = new UserDTO($this->request->getPost());
$entity = $this->service->modify($uid, $dto);
return array($entity, "{$entity->getTitle()} 계정 수정이 완료되었습니다.");
}
protected function view_process($uid): UserEntity
{
return parent::view_process($uid);
}
}