trafficmonitor init...2

This commit is contained in:
최준흠 2025-11-06 00:32:01 +09:00
parent 96052921e9
commit e5a9f6c86f
6 changed files with 128 additions and 104 deletions

View File

@ -2,6 +2,7 @@
namespace App\Controllers\Admin;
use App\DTOs\UserDTO;
use App\Entities\UserEntity;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface;
@ -35,53 +36,13 @@ class UserController extends AdminController
return parent::getFormRule($action, $field, $rule);
}
//Index,FieldForm관련.
final public function profile_form(mixed $uid): RedirectResponse|string
protected function create_process(string $action, array $viewDatas): string|RedirectResponse
{
try {
$this->getService()->setAction(__FUNCTION__);
$this->getService()->setFormFields();
$this->getService()->setFormFilters();
$this->getService()->setFormRules();
$this->getService()->setFormOptions();
//기본값정의
$this->getService()->setFormDatas($this->request->getGet());
//기존 Entity 가져오기
$entity = $this->getService()->getEntity($uid);
if (!$entity instanceof UserEntity) {
throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다.");
}
$this->entity = $entity;
helper(['form']);
$this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []];
return $this->getResultSuccess();
} catch (\Exception $e) {
return $this->getResultFail($e->getMessage());
}
}
final public function profile(int $uid): RedirectResponse|string
{
//Transaction Start
$db = \Config\Database::connect();
$this->_db->transStart();
try {
$this->getService()->setAction(__FUNCTION__);
$this->getService()->setFormFields();
$this->getService()->setFormFilters();
$this->getService()->setFormRules();
//전달값정의
$this->getService()->setFormDatas($this->request->getPost());
$this->doValidations();
//기존 Entity 가져오기
$entity = $this->getService()->getEntity($uid);
if (!$entity instanceof UserEntity) {
throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다.");
}
$this->entity = $this->modify_process($entity, $this->getService()->getFormDatas());
$this->_db->transCommit();
return $this->getResultSuccess();
} catch (\Exception $e) {
$this->_db->transRollback();
return $this->getResultFail($e->getMessage());
}
$dto = new UserDTO($this->request->getPost());
$this->doValidation($action);
$entity = $this->service->create($dto);
return redirect()
->route('admin/user/view', [$entity->getPK()])
->with('message', "{$entity->getTitle()} 계정이 등록되었습니다.");
}
}

View File

@ -21,29 +21,22 @@ abstract class AuthController extends CommonController
abstract protected function login_process(): UserEntity;
abstract protected function logout_process(): void;
//로그인화면
public function login_form_process(array $viewDatas): array
public function login_form_process(array $viewDatas = []): array
{
return $viewDatas;
}
public function login_form(): string|RedirectResponse
{
try {
//기본값처리
$initFormDatas = [];
//viewData처리
$viewDatas = [];
$viewDatas['action'] = __FUNCTION__;
$viewDatas['formFields'] = $this->service->getFormFields();
$viewDatas['formFilters'] = $this->service->getFormFilters();
$viewDatas['formRules'] = $this->service->getFormRules(__FUNCTION__);
$viewDatas['formOptions'] = $this->service->getFormOptions(__FUNCTION__);
$viewDatas['formDatas'] = $initFormDatas;
//초기화
$action = __FUNCTION__;
$viewDatas = $this->action_init_process($action);
$viewDatas = $this->login_form_process($viewDatas);
return $this->form_post_process($viewDatas);
return $this->action_post_process($action, $viewDatas);
} catch (\Exception $e) {
$viewDatas['error'] = $e->getMessage();
//리디렉션 대신 폼 뷰를 다시 렌더링하도록 form_post_process 호출
return $this->form_post_process($viewDatas);
return $this->action_post_process($action, $viewDatas);
}
}

View File

@ -60,26 +60,93 @@ abstract class CommonController extends BaseController
}
return array($field, $rule);
}
protected function form_post_process(array $viewDatas): string
protected function action_init_process(string $action, array $viewDatas = []): array
{
$paths = $this->getPaths();
$self_path = array_pop($paths);
$view_path = implode(DIRECTORY_SEPARATOR, [
...$paths,
$this->request->getVar('ActionTemplate') ?? $self_path,
$viewDatas['action'] ?? 'index'
]);
$view_datas = [
'control' => $viewDatas,
'forms' => ['attributes' => ['method' => "post",], 'hiddens' => []],
];
helper(['form', __FUNCTION__]);
// echo $view_path;
// dd($viewDatas);
// echo "TEST";
// exit;
return view($view_path, ['viewDatas' => $view_datas]);
$viewDatas['action'] = $action;
$viewDatas['view_paths'] = $this->getPaths();
$viewDatas['view_file'] = $this->request->getVar('ActionTemplate') ?? $viewDatas['action'];
$viewDatas['formFields'] = $this->service->getFormFields();
$viewDatas['formFilters'] = $this->service->getFormFilters();
$viewDatas['formRules'] = $this->service->getFormRules($viewDatas['action']);
$viewDatas['formOptions'] = $this->service->getFormOptions($viewDatas['action']);
if (array_key_exists('formDatas', $viewDatas)) {
$viewDatas['formDatas'] = [];
}
return $viewDatas;
}
protected function action_post_process(string $action, array $viewDatas): string|RedirectResponse
{
$view_paths = array_key_exists('view_paths', $viewDatas) ? $viewDatas['paths'] : $this->getPaths();
$lastest_path = array_pop($view_paths); //paths는 마지막을 뺀 앞단까지만 남음
switch ($action) {
case 'create_form':
case 'modify_form':
// ✅ 중간 안내 화면으로
// return view('posts/success_redirect', [
// 'message' => '게시글이 성공적으로 등록되었습니다.',
// 'redirectUrl' => route_to('posts_list')
// ]);
// 중요한 작업 (결제 완료, 오류 등) → “로딩 페이지(View)”로 안내 후 JS redirect
$full_path = implode(DIRECTORY_SEPARATOR, [
...$view_paths,
$this->request->getVar('ActionTemplate') ?? $lastest_path,
array_key_exists('view_file', $viewDatas) ? $viewDatas['view_file'] : $action
]);
$view_datas = [
'control' => $viewDatas,
'forms' => ['attributes' => ['method' => "post",], 'hiddens' => []],
];
helper(['form', __FUNCTION__]);
$result = view($full_path, ['viewDatas' => $view_datas]);
break;
default:
// ✅ Flashdata로 성공 메시지 저장
// 일반 CRUD (create/update/delete) → Flashdata + redirect()
session()->setFlashdata('success', array_key_exists('message', $viewDatas) ?: static::class . "/{$action}이 완료되었습니다.");
$result = redirect()->route(
implode(DIRECTORY_SEPARATOR, $view_paths)
);
break;
}
return $result;
}
protected function create_form_process(array $viewDatas): array
{
return $viewDatas;
}
public function create_form(): string|RedirectResponse
{
try {
//초기화
$action = __FUNCTION__;
$viewDatas = ['formDatas' => []];
$viewDatas = $this->action_init_process($action, $viewDatas);
$viewDatas = $this->create_form_process($viewDatas);
return $this->action_post_process($action, $viewDatas);
} catch (\Exception $e) {
$viewDatas['error'] = $e->getMessage();
//리디렉션 대신 폼 뷰를 다시 렌더링하도록 form_post_process 호출
return $this->action_post_process($action, $viewDatas);
}
}
protected function create_process(string $action, array $viewDatas): string|RedirectResponse
{
$this->doValidation($action);
return $this->action_post_process($action, $viewDatas);
}
public function create(): string|RedirectResponse
{
try {
//초기화
$action = __FUNCTION__;
$viewDatas = ['formDatas' => $this->request->getPost()];
$viewDatas = $this->action_init_process($action, $viewDatas);
return $this->create_process($action, $viewDatas);
} catch (\Exception $e) {
return redirect()->back()->withInput()->with('error', $e->getMessage());
}
}
//리스트관련
//조건절 처리
// protected function index_condition_process(): void

View File

@ -2,7 +2,6 @@
namespace App\DTOs;
use App\DTOs\CommonDTO;
use App\Services\Auth\AuthService;
class AuthDTO extends CommonDTO

28
app/DTOs/UserDTO.php Normal file
View File

@ -0,0 +1,28 @@
<?php
namespace App\DTOs;
class UserDTO extends CommonDTO
{
public ?int $uid = null;
public ?string $name = null;
public ?string $role = null;
public function __construct(array $datas = [])
{
foreach ($datas as $key => $value) {
if (property_exists($this, $key)) {
$this->{$key} = $value;
}
}
}
public function toArray(): array
{
return [
'uid' => $this->uid,
'title' => $this->name,
'role' => $this->role,
];
}
}

View File

@ -2,6 +2,7 @@
namespace App\Services;
use CodeIgniter\HTTP\RedirectResponse;
use App\Models\CommonModel;
abstract class CommonService
@ -11,13 +12,6 @@ abstract class CommonService
protected $formServiceInstance = null;
protected function __construct(protected CommonModel $model) {}
abstract public function getFormService(): mixed;
final public function getLogService(): MyLogService
{
if (!$this->_logService) {
$this->_logService = service('myLogService');
}
return $this->_logService;
}
final protected function addClassPath(string $className): void
{
$this->classPaths[] = $className;
@ -128,22 +122,6 @@ abstract class CommonService
return $entities;
}
//Action관련
public function create(array $formDatas): mixed
{
try {
$this->getService()->setAction(__FUNCTION__);
$this->getService()->setFormFields();
//전달값정의
$this->getService()->setFormDatas($this->request->getPost());
$this->getService()->setFormFilters();
$this->getService()->setFormRules();
$this->doValidations();
$this->entity = $this->create_process($this->getService()->getFormDatas());
return $this->getResultSuccess();
} catch (\Exception $e) {
return $this->getResultFail($e->getMessage());
}
}
//Index용
final public function getTotalCount(): int
{
@ -159,8 +137,6 @@ abstract class CommonService
{
$this->model->offset($offset);
}
//기본 기능부분
//FormFilter 조건절 처리
public function index_condition_filterField(string $field, mixed $filter_value): void
{
switch ($field) {