dbmsv2 init...1

This commit is contained in:
choi.jh 2025-08-26 11:22:26 +09:00
parent 9eb78fb61e
commit 189fc3da7f
8 changed files with 127 additions and 128 deletions

View File

@ -135,7 +135,9 @@ class PaymentController extends CustomerController
public function invoice(): RedirectResponse|string public function invoice(): RedirectResponse|string
{ {
try { try {
$this->initAction(__FUNCTION__); //각 Field 초기화
$this->setAction(__FUNCTION__);
$this->initAction();
$this->invoice_process(); $this->invoice_process();
return $this->getResultSuccess(); return $this->getResultSuccess();
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@ -59,7 +59,7 @@ class ServerController extends EquipmentController
if (!$format) { if (!$format) {
throw new \Exception(__METHOD__ . "에서 code의 format[Server.Prefix.code.format]이 정의되지 않았습니다."); throw new \Exception(__METHOD__ . "에서 code의 format[Server.Prefix.code.format]이 정의되지 않았습니다.");
} }
$this->setFormDatasDefault('code', $this->getService()->getLastestCode($format, (int)env("Server.Default.code", 0))); $this->setFieldDefaultValue('code', $this->getService()->getLastestCode($format, (int)env("Server.Default.code", 0)));
parent::create_form_process(); parent::create_form_process();
} }
protected function create_process(array $formDatas): void protected function create_process(array $formDatas): void

View File

@ -68,7 +68,9 @@ class Home extends AdminController
//Index,FieldForm관련 //Index,FieldForm관련
public function index(): RedirectResponse|string public function index(): RedirectResponse|string
{ {
$this->initAction(__FUNCTION__); //각 Field 초기화
$this->setAction(__FUNCTION__);
$this->initAction();
//Total 서버 현황 //Total 서버 현황
$this->totalCounts = $this->getService()->getTotalCountsByType(); $this->totalCounts = $this->getService()->getTotalCountsByType();
//interval을 기준으로 최근 신규 서비스정보 가져오기 //interval을 기준으로 최근 신규 서비스정보 가져오기

View File

@ -79,16 +79,13 @@ class UserController extends AdminController
return $validation; return $validation;
} }
//Index,FieldForm관련. //Index,FieldForm관련.
protected function profile_modify_form_process(mixed $entity): mixed
{
return $entity;
}
final public function profile_modify_form(mixed $uid): RedirectResponse|string final public function profile_modify_form(mixed $uid): RedirectResponse|string
{ {
try { try {
//각 Field 초기화 //각 Field 초기화
$this->initAction(__FUNCTION__, [ $this->setAction(__FUNCTION__);
'formFields' => ['id', 'passwd', 'confirmpassword', 'name', 'email', 'mobile'], $this->initAction([
'fields' => ['id', 'passwd', 'confirmpassword', 'name', 'email', 'mobile'],
]); ]);
helper(['form']); helper(['form']);
//기존 Entity 가져오기 //기존 Entity 가져오기
@ -96,39 +93,31 @@ class UserController extends AdminController
if (!$entity) { if (!$entity) {
throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다.");
} }
$this->entity = $this->profile_modify_form_process($entity); $this->modify_form_process($entity);
$this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []];
return $this->getResultSuccess(); return $this->getResultSuccess();
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->getResultFail($e->getMessage()); return $this->getResultFail($e->getMessage());
} }
} }
protected function profile_modify_process(mixed $entity, array $formDatas): mixed
{
//데이터 검증
$validDatas = $this->doValidate($this->getControlDatas('field_rules'), $formDatas);
return $this->getService()->modify($entity, $validDatas);
}
final public function profile_modify(int $uid): RedirectResponse|string final public function profile_modify(int $uid): RedirectResponse|string
{ {
//Transaction Start //Transaction Start
$this->_db->transStart(); $this->_db->transStart();
try { try {
//각 Field 초기화 //각 Field 초기화
$this->initAction(__FUNCTION__, [ $this->setAction(__FUNCTION__);
'formFields' => ['id', 'passwd', 'confirmpassword', 'name', 'email', 'mobile'], $this->initAction([
'fields' => ['id', 'passwd', 'confirmpassword', 'name', 'email', 'mobile'],
]); ]);
//입력값정의 //전달값받기
$formDatas = []; $formDatas = $this->getFormDatas($this->getControlDatas('actionFields'));
foreach ($this->getControlDatas('actionFields') as $field) {
$formDatas[$field] = $this->request->getPost($field);
}
//기존 Entity 가져오기 //기존 Entity 가져오기
$entity = $this->getService()->getEntity($uid); $entity = $this->getService()->getEntity($uid);
if (!$entity) { if (!$entity) {
throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다.");
} }
$this->entity = $this->profile_modify_process($entity, $formDatas); $this->modify_process($entity, $formDatas);
$this->_db->transCommit(); $this->_db->transCommit();
return $this->getResultSuccess(); return $this->getResultSuccess();
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@ -58,18 +58,6 @@ abstract class CommonController extends BaseController
} }
return $this->_myAuth; return $this->_myAuth;
} }
final public function getViewDatas(): array
{
return $this->_viewDatas;
}
final public function getMyLogService(): mixed
{
if (!$this->_myLogService) {
$this->_myLogService = new MyLogService();
}
return $this->_myLogService;
}
//Index,FieldForm관련
final protected function getControlDatas(?string $key = null): mixed final protected function getControlDatas(?string $key = null): mixed
{ {
if (!$key) { if (!$key) {
@ -77,76 +65,61 @@ abstract class CommonController extends BaseController
} }
return array_key_exists($key, $this->_control) ? $this->_control[$key] : null; return array_key_exists($key, $this->_control) ? $this->_control[$key] : null;
} }
private function setControlDatas(string $key, mixed $values): void
{
if (!array_key_exists($key, $this->_control)) {
$this->_control[$key] = [];
}
$this->_control[$key] = $values;
}
final protected function getViewDatas(): array
{
return $this->_viewDatas;
}
final protected function getMyLogService(): mixed
{
if (!$this->_myLogService) {
$this->_myLogService = new MyLogService();
}
return $this->_myLogService;
}
//Index,FieldForm관련
final protected function setAction(string $action): void final protected function setAction(string $action): void
{ {
$this->_control['action'] = $action; $this->_control['action'] = $action;
} }
final protected function getAction(): string final protected function getAction(): string
{ {
$action = $this->getControlDatas('action'); if (!array_key_exists('action', $this->_control)) {
if (!$action) {
throw new \Exception("action이 정의되지 않았습니다."); throw new \Exception("action이 정의되지 않았습니다.");
} }
return $action; return $this->_control['action'];
} }
final protected function initAction(string $action, ?array $actionFields = null): void final protected function initAction(array $actionFields = []): void
{ {
$this->setAction($action);
//action Fields정의용 //action Fields정의용
switch ($this->getAction()) { $this->initAction_process(actionFields: $actionFields);
case 'view': $temps = [];
$actionFields = is_array($actionFields) && array_key_exists('fields', $actionFields) ? $actionFields : $this->getService()->getViewFields(); foreach ($this->getControlDatas('actionFields') as $field) {
break; $temps[$field] = $this->getFormFieldRule_process($this->getAction(), $field);
case 'index':
$actionFields = is_array($actionFields) && array_key_exists('fields', $actionFields) ? $actionFields : $this->getService()->getIndexFields();
$this->_control['batchjob_fields'] = array_key_exists('batchjob_fields', $actionFields) ? $actionFields['batchjob_fields'] : [];
$this->_control['batchjob_buttions'] = array_key_exists('batchjob_buttions', $actionFields) ? $actionFields['batchjob_buttions'] : [];
break;
default:
$actionFields = is_array($actionFields) && array_key_exists('fields', $actionFields) ? $actionFields : $this->getService()->getFormFields();
break;
}
//action Field정의용
$fields = $this->_control['actionFields'] = array_key_exists('fields', $actionFields) ? $actionFields['fields'] : [];
//action Filters정의용
$filters = $this->_control['actionFilters'] = array_key_exists('filters', $actionFields) ? $actionFields['filters'] : [];
//Field Rules정의
$this->_control['field_rules'] = [];
foreach ($fields as $field) {
$this->_control['field_rules'][$field] = $this->getFormFieldRule($action, $field);
} }
// echo var_dump($temps);
// echo "TEST3";
// exit;
$this->setControlDatas('field_rules', $temps);
//Form용 Options정의 //Form용 Options정의
$this->_control['filter_optons'] = []; $temps = [];
foreach ($this->getControlDatas('actionFilters') as $field) { foreach ($this->getControlDatas('actionFilters') as $field) {
$this->_control['filter_optons'][$field] = []; $temps[$field] = [];
foreach ($this->getFormFieldOption($field) as $option) { foreach ($this->getFormFieldOption_process($field) as $option) {
$this->_control['filter_optons'][$field][$option->getPK()] = $option; $temps[$field][$option->getPK()] = $option;
} }
} }
$this->setControlDatas('filter_optons', $temps);
} }
//전체 FormDatas 전달값받기 //입력 데이터 검증
final protected function getFormDatas(array $fields, array $formDatas = []): array private function doValidate(array $rules, array $formDatas, ?Validation $validation = null): array
{
foreach ($fields as $field) {
//Post값이 null이면 formDatas에서 해당하는 default값이 있는지 확인후 넣고,없으면 최종적으로 null
$datas = $this->request->getPost($field);
if ($datas !== null) {
$formDatas[$field] = $datas;
} else {
$formDatas = $this->getFormData_process($field, $formDatas);
}
}
return $formDatas;
}
final protected function setFormDatasDefault(string $field, mixed $default): void
{
if (array_key_exists('form_data_defaults', $this->_control)) {
$this->_control['form_data_defaults'] = [];
}
$this->_control['form_data_defaults'][$field] = $default;
}
//FormDatas 검증
final protected function doValidate(array $rules, array $formDatas, ?Validation $validation = null): array
{ {
//변경할 값 확인 : Upload된 파일 검증시 $this->request->getPOST()보다 먼처 체크필요 //변경할 값 확인 : Upload된 파일 검증시 $this->request->getPOST()보다 먼처 체크필요
if (!$validation) { if (!$validation) {
@ -166,15 +139,37 @@ abstract class CommonController extends BaseController
return $formDatas; return $formDatas;
// return $validation->getValidated(); // return $validation->getValidated();
} }
//전체 FormDatas 전달값받기
final protected function getFormDatas(array $fields, array $formDatas = []): array
{
foreach ($fields as $field) {
//Post값이 null이면 formDatas에서 해당하는 default값이 있는지 확인후 넣고,없으면 최종적으로 null
$datas = $this->request->getPost($field);
if ($datas !== null) {
$formDatas[$field] = $datas;
} else {
$formDatas = $this->getFormData_process($field, $formDatas);
}
}
return $formDatas;
}
final protected function setFieldDefaultValue(string $field, mixed $default): void
{
if (array_key_exists('field_default_values', $this->_control)) {
$this->_control['field_default_values'] = [];
}
$this->_control['field_default_values'][$field] = $default;
}
//FormDatas 검증
//생성 기본기능 //생성 기본기능
final public function create_form(): RedirectResponse|string final public function create_form(): RedirectResponse|string
{ {
try { try {
//각 Field 초기화 //각 Field 초기화
// $this->getMyAuth()->pushCurrentUrl($this->request->getUri()->getPath() . ($this->request->getUri()->getQuery() ? "?" . $this->request->getUri()->getQuery() : "")); $this->setAction(__FUNCTION__);
$this->initAction(__FUNCTION__); $this->initAction();
//actionFilters에 해당하는 값이 있을 경우 정의
$this->create_form_process(); $this->create_form_process();
//actionFilters에 해당하는 값이 있을 경우 정의
helper(['form']); helper(['form']);
$this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []];
return $this->getResultSuccess(); return $this->getResultSuccess();
@ -187,7 +182,8 @@ abstract class CommonController extends BaseController
$this->_db->transStart(); $this->_db->transStart();
try { try {
//각 Field 초기화 //각 Field 초기화
$this->initAction(__FUNCTION__); $this->setAction(__FUNCTION__);
$this->initAction();
//전달값받기 //전달값받기
$formDatas = $this->getFormDatas($this->getControlDatas('actionFields')); $formDatas = $this->getFormDatas($this->getControlDatas('actionFields'));
$this->create_process($formDatas); $this->create_process($formDatas);
@ -203,8 +199,8 @@ abstract class CommonController extends BaseController
{ {
try { try {
//각 Field 초기화 //각 Field 초기화
// $this->getMyAuth()->pushCurrentUrl($this->request->getUri()->getPath() . ($this->request->getUri()->getQuery() ? "?" . $this->request->getUri()->getQuery() : "")); $this->setAction(__FUNCTION__);
$this->initAction(__FUNCTION__); $this->initAction();
//기존 Entity 가져오기 //기존 Entity 가져오기
$entity = $this->getService()->getEntity($uid); $entity = $this->getService()->getEntity($uid);
if (!$entity) { if (!$entity) {
@ -224,12 +220,10 @@ abstract class CommonController extends BaseController
$this->_db->transStart(); $this->_db->transStart();
try { try {
//각 Field 초기화 //각 Field 초기화
$this->initAction(__FUNCTION__); $this->setAction(__FUNCTION__);
//입력값정의 $this->initAction();
$formDatas = []; //전달값받기
foreach ($this->getControlDatas('actionFields') as $field) { $formDatas = $this->getFormDatas($this->getControlDatas('actionFields'));
$formDatas[$field] = $this->request->getPost($field);
}
//기존 Entity 가져오기 //기존 Entity 가져오기
$entity = $this->getService()->getEntity($uid); $entity = $this->getService()->getEntity($uid);
if (!$entity) { if (!$entity) {
@ -250,7 +244,8 @@ abstract class CommonController extends BaseController
$this->_db->transStart(); $this->_db->transStart();
try { try {
//각 Field 초기화:조건항목 Field는 한개만 존재하므로 Field와 Rule을 정의 //각 Field 초기화:조건항목 Field는 한개만 존재하므로 Field와 Rule을 정의
$this->initAction(__FUNCTION__, ['fields' => [$field], 'filters' => [$field]]); $this->setAction(__FUNCTION__);
$this->initAction(['fields' => [$field], 'filters' => [$field]]);
//입력값정의 //입력값정의
$formDatas = [$field => $this->request->getVar($field)]; $formDatas = [$field => $this->request->getVar($field)];
//기존 Entity 가져오기 //기존 Entity 가져오기
@ -291,7 +286,8 @@ abstract class CommonController extends BaseController
throw new \Exception("적용할 리스트을 선택하셔야합니다."); throw new \Exception("적용할 리스트을 선택하셔야합니다.");
} }
//각 Field 초기화: 일괄작업은 선택된 조건항목 Field만 존재하므로 Field와 Rule을 정의 //각 Field 초기화: 일괄작업은 선택된 조건항목 Field만 존재하므로 Field와 Rule을 정의
$this->initAction(__FUNCTION__, ['fields' => [$selectedFields], 'filters' => [$selectedFields]]); $this->setAction(__FUNCTION__);
$this->initAction(['fields' => [$selectedFields], 'filters' => [$selectedFields]]);
$entities = []; $entities = [];
foreach ($uids as $uid) { foreach ($uids as $uid) {
$entities = $this->batchjob_process($uid, $formDatas, $entities); $entities = $this->batchjob_process($uid, $formDatas, $entities);
@ -355,7 +351,8 @@ abstract class CommonController extends BaseController
{ {
try { try {
//각 Field 초기화 //각 Field 초기화
$this->initAction(__FUNCTION__); $this->setAction(__FUNCTION__);
$this->initAction();
//기존 Entity 가져오기 //기존 Entity 가져오기
$entity = $this->getService()->getEntity($uid); $entity = $this->getService()->getEntity($uid);
if (!$entity) { if (!$entity) {
@ -392,7 +389,8 @@ abstract class CommonController extends BaseController
{ {
try { try {
//각 Field 초기화 //각 Field 초기화
$this->initAction(__FUNCTION__); $this->setAction(__FUNCTION__);
$this->initAction();
//URL처리 //URL처리
// $this->uri = $this->request->getUri(); // $this->uri = $this->request->getUri();
switch ($output_type) { switch ($output_type) {
@ -428,8 +426,31 @@ abstract class CommonController extends BaseController
//공통 기본 기능 //공통 기본 기능
//추가 개별 처리 기능 //추가 개별 처리 기능
//action Fields정의용
protected function initAction_process(array $actionFields = []): void
{
switch ($this->getAction()) {
case 'view':
$temps = is_array($actionFields) && array_key_exists('fields', $actionFields) ? $actionFields : $this->getService()->getViewFields();
$this->setControlDatas('actionFields', is_array($temps) && array_key_exists('fields', $temps) ? $temps['fields'] : []);
$this->setControlDatas('actionFilters', is_array($temps) && array_key_exists('filters', $temps) ? $temps['filters'] : []);
break;
case 'index':
$temps = is_array($actionFields) && array_key_exists('fields', $actionFields) ? $actionFields : $this->getService()->getIndexFields();
$this->setControlDatas('actionFields', is_array($temps) && array_key_exists('fields', $temps) ? $temps['fields'] : []);
$this->setControlDatas('actionFilters', is_array($temps) && array_key_exists('filters', $temps) ? $temps['filters'] : []);
$this->setControlDatas('batchjob_fields', array_key_exists('batchjob_fields', $temps) ? $temps['batchjob_fields'] : []);
$this->setControlDatas('batchjob_buttions', array_key_exists('batchjob_buttions', $temps) ? $temps['batchjob_buttions'] : []);
break;
default:
$temps = is_array($actionFields) && array_key_exists('fields', $actionFields) ? $actionFields : $this->getService()->getFormFields();
$this->setControlDatas('actionFields', is_array($temps) && array_key_exists('fields', $temps) ? $temps['fields'] : []);
$this->setControlDatas('actionFilters', is_array($temps) && array_key_exists('filters', $temps) ? $temps['filters'] : []);
break;
}
}
//FieldForm관련용 //FieldForm관련용
protected function getFormFieldOption(string $field, array $options = []): array protected function getFormFieldOption_process(string $field, array $options = []): array
{ {
switch ($field) { switch ($field) {
default: default:
@ -441,7 +462,7 @@ abstract class CommonController extends BaseController
} }
return $options; return $options;
} }
protected function getFormFieldRule(string $action, string $field): string protected function getFormFieldRule_process(string $action, string $field): string
{ {
if (is_array($field)) { if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true)); throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
@ -458,10 +479,6 @@ abstract class CommonController extends BaseController
{ {
return $formDatas; return $formDatas;
} }
protected function getFormDataDefault_process(string $field, array $formDatas): array
{
return $formDatas;
}
protected function doValidation_process(Validation $validation, string $field, string $rule): Validation protected function doValidation_process(Validation $validation, string $field, string $rule): Validation
{ {
switch ($field) { switch ($field) {
@ -471,7 +488,7 @@ abstract class CommonController extends BaseController
} }
return $validation; return $validation;
} }
//Field관련 //Process Result처리
protected function getResultFail(string $message = MESSAGES["FAILED"]): RedirectResponse protected function getResultFail(string $message = MESSAGES["FAILED"]): RedirectResponse
{ {
LogCollector::debug($message); LogCollector::debug($message);
@ -484,7 +501,7 @@ abstract class CommonController extends BaseController
protected function getResultSuccess(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string protected function getResultSuccess(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string
{ {
helper(['form']); helper(['form']);
switch ($this->getAction()) { switch ($this->getControlDatas('action')) {
case 'create': case 'create':
case 'modify': case 'modify':
$this->getMyLogService()->save($this->getService()->getClassName(), $this->getAction(), $message, $this->getMyAuth()->getUIDByAuthInfo()); $this->getMyLogService()->save($this->getService()->getClassName(), $this->getAction(), $message, $this->getMyAuth()->getUIDByAuthInfo());
@ -647,9 +664,9 @@ abstract class CommonController extends BaseController
public function index(): RedirectResponse|string public function index(): RedirectResponse|string
{ {
try { try {
//FieldRule정의
//각 Field 초기화 //각 Field 초기화
$this->initAction(__FUNCTION__); $this->setAction(__FUNCTION__);
$this->initAction();
helper(['form']); helper(['form']);
//Return Url정의 //Return Url정의
$this->getMyAuth()->pushCurrentUrl($this->request->getUri()->getPath() . ($this->request->getUri()->getQuery() ? "?" . $this->request->getUri()->getQuery() : "")); $this->getMyAuth()->pushCurrentUrl($this->request->getUri()->getPath() . ($this->request->getUri()->getQuery() ? "?" . $this->request->getUri()->getQuery() : ""));

View File

@ -1,11 +0,0 @@
<?php
namespace App\Controllers;
class Home extends BaseController
{
public function index(): string
{
return view('welcome_message');
}
}

View File

@ -10,7 +10,7 @@
<tr> <tr>
<th nowrap class="text-end"><?= $viewDatas['helper']->getFieldLabel($field, lang("{$viewDatas['class_path']}.label.{$field}"), $viewDatas) ?></th> <th nowrap class="text-end"><?= $viewDatas['helper']->getFieldLabel($field, lang("{$viewDatas['class_path']}.label.{$field}"), $viewDatas) ?></th>
<td nowrap class="text-start"> <td nowrap class="text-start">
<?= $viewDatas['helper']->getFieldForm($field, old($field) ?? ($viewDatas['control']['form_data_defaults'][$field] ?? null), $viewDatas) ?> <?= $viewDatas['helper']->getFieldForm($field, old($field) ?? ($viewDatas['control']['field_default_values'][$field] ?? null), $viewDatas) ?>
<span><?= validation_show_error($field); ?></span> <span><?= validation_show_error($field); ?></span>
</td> </td>
</tr> </tr>

View File

@ -10,7 +10,7 @@
<tr> <tr>
<th nowrap class="text-end"><?= $viewDatas['helper']->getFieldLabel($field, lang("{$viewDatas['class_path']}.label.{$field}"), $viewDatas) ?></th> <th nowrap class="text-end"><?= $viewDatas['helper']->getFieldLabel($field, lang("{$viewDatas['class_path']}.label.{$field}"), $viewDatas) ?></th>
<td nowrap class="text-start"> <td nowrap class="text-start">
<?= $viewDatas['helper']->getFieldForm($field, old($field) ?? ($viewDatas['control']['form_data_defaults'][$field] ?? null), $viewDatas) ?> <?= $viewDatas['helper']->getFieldForm($field, old($field) ?? ($viewDatas['control']['field_default_values'][$field] ?? null), $viewDatas) ?>
<span><?= validation_show_error($field); ?></span> <span><?= validation_show_error($field); ?></span>
</td> </td>
</tr> </tr>