dbmsv2 init...1
This commit is contained in:
parent
9eb78fb61e
commit
189fc3da7f
@ -135,7 +135,9 @@ class PaymentController extends CustomerController
|
||||
public function invoice(): RedirectResponse|string
|
||||
{
|
||||
try {
|
||||
$this->initAction(__FUNCTION__);
|
||||
//각 Field 초기화
|
||||
$this->setAction(__FUNCTION__);
|
||||
$this->initAction();
|
||||
$this->invoice_process();
|
||||
return $this->getResultSuccess();
|
||||
} catch (\Exception $e) {
|
||||
|
||||
@ -59,7 +59,7 @@ class ServerController extends EquipmentController
|
||||
if (!$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();
|
||||
}
|
||||
protected function create_process(array $formDatas): void
|
||||
|
||||
@ -68,7 +68,9 @@ class Home extends AdminController
|
||||
//Index,FieldForm관련
|
||||
public function index(): RedirectResponse|string
|
||||
{
|
||||
$this->initAction(__FUNCTION__);
|
||||
//각 Field 초기화
|
||||
$this->setAction(__FUNCTION__);
|
||||
$this->initAction();
|
||||
//Total 서버 현황
|
||||
$this->totalCounts = $this->getService()->getTotalCountsByType();
|
||||
//interval을 기준으로 최근 신규 서비스정보 가져오기
|
||||
|
||||
@ -79,16 +79,13 @@ class UserController extends AdminController
|
||||
return $validation;
|
||||
}
|
||||
//Index,FieldForm관련.
|
||||
protected function profile_modify_form_process(mixed $entity): mixed
|
||||
{
|
||||
return $entity;
|
||||
}
|
||||
final public function profile_modify_form(mixed $uid): RedirectResponse|string
|
||||
{
|
||||
try {
|
||||
//각 Field 초기화
|
||||
$this->initAction(__FUNCTION__, [
|
||||
'formFields' => ['id', 'passwd', 'confirmpassword', 'name', 'email', 'mobile'],
|
||||
$this->setAction(__FUNCTION__);
|
||||
$this->initAction([
|
||||
'fields' => ['id', 'passwd', 'confirmpassword', 'name', 'email', 'mobile'],
|
||||
]);
|
||||
helper(['form']);
|
||||
//기존 Entity 가져오기
|
||||
@ -96,39 +93,31 @@ class UserController extends AdminController
|
||||
if (!$entity) {
|
||||
throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다.");
|
||||
}
|
||||
$this->entity = $this->profile_modify_form_process($entity);
|
||||
$this->modify_form_process($entity);
|
||||
$this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []];
|
||||
return $this->getResultSuccess();
|
||||
} catch (\Exception $e) {
|
||||
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
|
||||
{
|
||||
//Transaction Start
|
||||
$this->_db->transStart();
|
||||
try {
|
||||
//각 Field 초기화
|
||||
$this->initAction(__FUNCTION__, [
|
||||
'formFields' => ['id', 'passwd', 'confirmpassword', 'name', 'email', 'mobile'],
|
||||
$this->setAction(__FUNCTION__);
|
||||
$this->initAction([
|
||||
'fields' => ['id', 'passwd', 'confirmpassword', 'name', 'email', 'mobile'],
|
||||
]);
|
||||
//입력값정의
|
||||
$formDatas = [];
|
||||
foreach ($this->getControlDatas('actionFields') as $field) {
|
||||
$formDatas[$field] = $this->request->getPost($field);
|
||||
}
|
||||
//전달값받기
|
||||
$formDatas = $this->getFormDatas($this->getControlDatas('actionFields'));
|
||||
//기존 Entity 가져오기
|
||||
$entity = $this->getService()->getEntity($uid);
|
||||
if (!$entity) {
|
||||
throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다.");
|
||||
}
|
||||
$this->entity = $this->profile_modify_process($entity, $formDatas);
|
||||
$this->modify_process($entity, $formDatas);
|
||||
$this->_db->transCommit();
|
||||
return $this->getResultSuccess();
|
||||
} catch (\Exception $e) {
|
||||
|
||||
@ -58,18 +58,6 @@ abstract class CommonController extends BaseController
|
||||
}
|
||||
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
|
||||
{
|
||||
if (!$key) {
|
||||
@ -77,76 +65,61 @@ abstract class CommonController extends BaseController
|
||||
}
|
||||
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
|
||||
{
|
||||
$this->_control['action'] = $action;
|
||||
}
|
||||
final protected function getAction(): string
|
||||
{
|
||||
$action = $this->getControlDatas('action');
|
||||
if (!$action) {
|
||||
if (!array_key_exists('action', $this->_control)) {
|
||||
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정의용
|
||||
switch ($this->getAction()) {
|
||||
case 'view':
|
||||
$actionFields = is_array($actionFields) && array_key_exists('fields', $actionFields) ? $actionFields : $this->getService()->getViewFields();
|
||||
break;
|
||||
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);
|
||||
$this->initAction_process(actionFields: $actionFields);
|
||||
$temps = [];
|
||||
foreach ($this->getControlDatas('actionFields') as $field) {
|
||||
$temps[$field] = $this->getFormFieldRule_process($this->getAction(), $field);
|
||||
}
|
||||
// echo var_dump($temps);
|
||||
// echo "TEST3";
|
||||
// exit;
|
||||
$this->setControlDatas('field_rules', $temps);
|
||||
|
||||
//Form용 Options정의
|
||||
$this->_control['filter_optons'] = [];
|
||||
$temps = [];
|
||||
foreach ($this->getControlDatas('actionFilters') as $field) {
|
||||
$this->_control['filter_optons'][$field] = [];
|
||||
foreach ($this->getFormFieldOption($field) as $option) {
|
||||
$this->_control['filter_optons'][$field][$option->getPK()] = $option;
|
||||
$temps[$field] = [];
|
||||
foreach ($this->getFormFieldOption_process($field) as $option) {
|
||||
$temps[$field][$option->getPK()] = $option;
|
||||
}
|
||||
}
|
||||
$this->setControlDatas('filter_optons', $temps);
|
||||
}
|
||||
//전체 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 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
|
||||
//입력 데이터 검증
|
||||
private function doValidate(array $rules, array $formDatas, ?Validation $validation = null): array
|
||||
{
|
||||
//변경할 값 확인 : Upload된 파일 검증시 $this->request->getPOST()보다 먼처 체크필요
|
||||
if (!$validation) {
|
||||
@ -166,15 +139,37 @@ abstract class CommonController extends BaseController
|
||||
return $formDatas;
|
||||
// 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
|
||||
{
|
||||
try {
|
||||
//각 Field 초기화
|
||||
// $this->getMyAuth()->pushCurrentUrl($this->request->getUri()->getPath() . ($this->request->getUri()->getQuery() ? "?" . $this->request->getUri()->getQuery() : ""));
|
||||
$this->initAction(__FUNCTION__);
|
||||
//actionFilters에 해당하는 값이 있을 경우 정의
|
||||
$this->setAction(__FUNCTION__);
|
||||
$this->initAction();
|
||||
$this->create_form_process();
|
||||
//actionFilters에 해당하는 값이 있을 경우 정의
|
||||
helper(['form']);
|
||||
$this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []];
|
||||
return $this->getResultSuccess();
|
||||
@ -187,7 +182,8 @@ abstract class CommonController extends BaseController
|
||||
$this->_db->transStart();
|
||||
try {
|
||||
//각 Field 초기화
|
||||
$this->initAction(__FUNCTION__);
|
||||
$this->setAction(__FUNCTION__);
|
||||
$this->initAction();
|
||||
//전달값받기
|
||||
$formDatas = $this->getFormDatas($this->getControlDatas('actionFields'));
|
||||
$this->create_process($formDatas);
|
||||
@ -203,8 +199,8 @@ abstract class CommonController extends BaseController
|
||||
{
|
||||
try {
|
||||
//각 Field 초기화
|
||||
// $this->getMyAuth()->pushCurrentUrl($this->request->getUri()->getPath() . ($this->request->getUri()->getQuery() ? "?" . $this->request->getUri()->getQuery() : ""));
|
||||
$this->initAction(__FUNCTION__);
|
||||
$this->setAction(__FUNCTION__);
|
||||
$this->initAction();
|
||||
//기존 Entity 가져오기
|
||||
$entity = $this->getService()->getEntity($uid);
|
||||
if (!$entity) {
|
||||
@ -224,12 +220,10 @@ abstract class CommonController extends BaseController
|
||||
$this->_db->transStart();
|
||||
try {
|
||||
//각 Field 초기화
|
||||
$this->initAction(__FUNCTION__);
|
||||
//입력값정의
|
||||
$formDatas = [];
|
||||
foreach ($this->getControlDatas('actionFields') as $field) {
|
||||
$formDatas[$field] = $this->request->getPost($field);
|
||||
}
|
||||
$this->setAction(__FUNCTION__);
|
||||
$this->initAction();
|
||||
//전달값받기
|
||||
$formDatas = $this->getFormDatas($this->getControlDatas('actionFields'));
|
||||
//기존 Entity 가져오기
|
||||
$entity = $this->getService()->getEntity($uid);
|
||||
if (!$entity) {
|
||||
@ -250,7 +244,8 @@ abstract class CommonController extends BaseController
|
||||
$this->_db->transStart();
|
||||
try {
|
||||
//각 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)];
|
||||
//기존 Entity 가져오기
|
||||
@ -291,7 +286,8 @@ abstract class CommonController extends BaseController
|
||||
throw new \Exception("적용할 리스트을 선택하셔야합니다.");
|
||||
}
|
||||
//각 Field 초기화: 일괄작업은 선택된 조건항목 Field만 존재하므로 Field와 Rule을 정의
|
||||
$this->initAction(__FUNCTION__, ['fields' => [$selectedFields], 'filters' => [$selectedFields]]);
|
||||
$this->setAction(__FUNCTION__);
|
||||
$this->initAction(['fields' => [$selectedFields], 'filters' => [$selectedFields]]);
|
||||
$entities = [];
|
||||
foreach ($uids as $uid) {
|
||||
$entities = $this->batchjob_process($uid, $formDatas, $entities);
|
||||
@ -355,7 +351,8 @@ abstract class CommonController extends BaseController
|
||||
{
|
||||
try {
|
||||
//각 Field 초기화
|
||||
$this->initAction(__FUNCTION__);
|
||||
$this->setAction(__FUNCTION__);
|
||||
$this->initAction();
|
||||
//기존 Entity 가져오기
|
||||
$entity = $this->getService()->getEntity($uid);
|
||||
if (!$entity) {
|
||||
@ -392,7 +389,8 @@ abstract class CommonController extends BaseController
|
||||
{
|
||||
try {
|
||||
//각 Field 초기화
|
||||
$this->initAction(__FUNCTION__);
|
||||
$this->setAction(__FUNCTION__);
|
||||
$this->initAction();
|
||||
//URL처리
|
||||
// $this->uri = $this->request->getUri();
|
||||
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관련용
|
||||
protected function getFormFieldOption(string $field, array $options = []): array
|
||||
protected function getFormFieldOption_process(string $field, array $options = []): array
|
||||
{
|
||||
switch ($field) {
|
||||
default:
|
||||
@ -441,7 +462,7 @@ abstract class CommonController extends BaseController
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
protected function getFormFieldRule(string $action, string $field): string
|
||||
protected function getFormFieldRule_process(string $action, string $field): string
|
||||
{
|
||||
if (is_array($field)) {
|
||||
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
|
||||
@ -458,10 +479,6 @@ abstract class CommonController extends BaseController
|
||||
{
|
||||
return $formDatas;
|
||||
}
|
||||
protected function getFormDataDefault_process(string $field, array $formDatas): array
|
||||
{
|
||||
return $formDatas;
|
||||
}
|
||||
protected function doValidation_process(Validation $validation, string $field, string $rule): Validation
|
||||
{
|
||||
switch ($field) {
|
||||
@ -471,7 +488,7 @@ abstract class CommonController extends BaseController
|
||||
}
|
||||
return $validation;
|
||||
}
|
||||
//Field관련
|
||||
//Process Result처리
|
||||
protected function getResultFail(string $message = MESSAGES["FAILED"]): RedirectResponse
|
||||
{
|
||||
LogCollector::debug($message);
|
||||
@ -484,7 +501,7 @@ abstract class CommonController extends BaseController
|
||||
protected function getResultSuccess(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string
|
||||
{
|
||||
helper(['form']);
|
||||
switch ($this->getAction()) {
|
||||
switch ($this->getControlDatas('action')) {
|
||||
case 'create':
|
||||
case 'modify':
|
||||
$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
|
||||
{
|
||||
try {
|
||||
//FieldRule정의
|
||||
//각 Field 초기화
|
||||
$this->initAction(__FUNCTION__);
|
||||
$this->setAction(__FUNCTION__);
|
||||
$this->initAction();
|
||||
helper(['form']);
|
||||
//Return Url정의
|
||||
$this->getMyAuth()->pushCurrentUrl($this->request->getUri()->getPath() . ($this->request->getUri()->getQuery() ? "?" . $this->request->getUri()->getQuery() : ""));
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
class Home extends BaseController
|
||||
{
|
||||
public function index(): string
|
||||
{
|
||||
return view('welcome_message');
|
||||
}
|
||||
}
|
||||
@ -10,7 +10,7 @@
|
||||
<tr>
|
||||
<th nowrap class="text-end"><?= $viewDatas['helper']->getFieldLabel($field, lang("{$viewDatas['class_path']}.label.{$field}"), $viewDatas) ?></th>
|
||||
<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>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
<tr>
|
||||
<th nowrap class="text-end"><?= $viewDatas['helper']->getFieldLabel($field, lang("{$viewDatas['class_path']}.label.{$field}"), $viewDatas) ?></th>
|
||||
<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>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user