dbmsv2 init...1

This commit is contained in:
choi.jh 2025-08-25 12:07:40 +09:00
parent 08fc13aa1f
commit a0d72710ce
3 changed files with 189 additions and 171 deletions

View File

@ -59,7 +59,7 @@ class ClientController extends CustomerController
$formDatas['user_uid'] = $this->getMyAuth()->getUIDByAuthInfo();
parent::modify_process($entity, $formDatas);
}
protected function setValidation(Validation $validation, string $field, string $rule): Validation
protected function doValidation_process(Validation $validation, string $field, string $rule): Validation
{
switch ($field) {
case 'role':
@ -67,7 +67,7 @@ class ClientController extends CustomerController
$validation->setRule("{$field}.*", $field, $rule);
break;
default:
$validation = parent::setValidation($validation, $field, $rule);
$validation = parent::doValidation_process($validation, $field, $rule);
break;
}
return $validation;

View File

@ -65,7 +65,7 @@ class UserController extends AdminController
}
return $result;
}
protected function setValidation(Validation $validation, string $field, string $rule): Validation
protected function doValidation_process(Validation $validation, string $field, string $rule): Validation
{
switch ($field) {
case 'role':
@ -73,7 +73,7 @@ class UserController extends AdminController
$validation->setRule("{$field}.*", $field, $rule);
break;
default:
$validation = parent::setValidation($validation, $field, $rule);
$validation = parent::doValidation_process($validation, $field, $rule);
break;
}
return $validation;

View File

@ -139,17 +139,21 @@ abstract class CommonController extends BaseController
// echo var_dump($this->getControlDatas('field_rules'));
// exit;
}
protected function setValidation(Validation $validation, string $field, string $rule): Validation
//전체 FormDatas 전달값받기
final protected function getFormDatas(array $fields, array $formDatas = []): array
{
switch ($field) {
default:
$validation->setRule($field, $field, $rule);
break;
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 $validation;
return $formDatas;
}
//Field관련
//데이터 검증
//FormDatas 검증
final protected function doValidate(array $rules, array $formDatas, ?Validation $validation = null): array
{
//변경할 값 확인 : Upload된 파일 검증시 $this->request->getPOST()보다 먼처 체크필요
@ -158,7 +162,7 @@ abstract class CommonController extends BaseController
}
// dd($rules);
foreach ($rules as $field => $rule) {
$validation = $this->setValidation($validation, $field, $rule);
$validation = $this->doValidation_process($validation, $field, $rule);
}
// dd($formDatas);
if (!$validation->run($formDatas)) {
@ -170,50 +174,7 @@ abstract class CommonController extends BaseController
return $formDatas;
// return $validation->getValidated();
}
protected function getResultFail(string $message = MESSAGES["FAILED"]): RedirectResponse
{
LogCollector::debug($message);
$this->getMyLogService()->save($this->getService()->getClassName(), $this->getAction(), $message, $this->getMyAuth()->getUIDByAuthInfo());
if ($this->request->getMethod() === 'POST') {
return redirect()->back()->withInput()->with('error', $message);
}
return redirect()->to($this->getMyAuth()->popPreviousUrl())->with('error', $message);
}
protected function getResultSuccess(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string
{
helper(['form']);
switch ($this->getAction()) {
case 'create':
case 'modify':
$this->getMyLogService()->save($this->getService()->getClassName(), $this->getAction(), $message, $this->getMyAuth()->getUIDByAuthInfo());
$result = $this->view($this->entity->getPK());
break;
case 'create_form':
case 'modify_form':
case 'login_form':
case 'view':
case 'index':
case 'download':
$this->control = $this->getControlDatas();
$this->getHelper()->setViewDatas($this->getViewDatas());
$actionTemplate = $this->request->getVar('ActionTemplate') ?? $actionTemplate;
if ($actionTemplate) {
$view_file = $this->view_path . $actionTemplate . DIRECTORY_SEPARATOR . $this->getAction();
} else {
$view_file = $this->view_path . $this->getAction();
}
$result = view($view_file, ['viewDatas' => $this->getViewDatas()]);
break;
default:
$result = redirect()->to($this->getMyAuth()->popPreviousUrl())->with('error', $message);
break;
}
return $result;
}
//Index,FieldForm관련
// 생성
protected function create_form_process(): void {}
//생성 기본기능
final public function create_form(): RedirectResponse|string
{
try {
@ -229,25 +190,14 @@ abstract class CommonController extends BaseController
return $this->getResultFail($e->getMessage());
}
}
//생성관련
protected function create_process(array $formDatas): void
{
//데이터 검증
$validDatas = $this->doValidate($this->getControlDatas('field_rules'), $formDatas);
$this->entity = $this->getService()->create($validDatas);
}
final public function create(): RedirectResponse|string
{
$this->_db->transStart();
try {
//각 Field 초기화
$this->initAction(__FUNCTION__);
//입력값정의
$formDatas = [];
foreach ($this->getControlDatas('actionFields') as $field) {
$formDatas[$field] = $this->request->getPost($field);
}
// dd($formDatas);
//전달값받기
$formDatas = $this->getFormDatas($this->getControlDatas('actionFields'));
$this->create_process($formDatas);
$this->_db->transCommit();
return $this->getResultSuccess();
@ -256,11 +206,7 @@ abstract class CommonController extends BaseController
return $this->getResultFail($e->getMessage());
}
}
//수정관련
protected function modify_form_process(mixed $entity): void
{
$this->entity = $entity;
}
//수정 기본기능
final public function modify_form(mixed $uid): RedirectResponse|string
{
try {
@ -280,12 +226,6 @@ abstract class CommonController extends BaseController
return $this->getResultFail($e->getMessage());
}
}
protected function modify_process(mixed $entity, array $formDatas): void
{
//데이터 검증
$validDatas = $this->doValidate($this->getControlDatas('field_rules'), $formDatas);
$this->entity = $this->getService()->modify($entity, $validDatas);
}
final public function modify(int $uid): RedirectResponse|string
{
//Transaction Start
@ -311,13 +251,7 @@ abstract class CommonController extends BaseController
return $this->getResultFail($e->getMessage());
}
}
//단일필드작업
final protected function toggle_process(mixed $entity, array $formDatas): void
{
//데이터 검증
$validDatas = $this->doValidate($this->getControlDatas('field_rules'), $formDatas);
$this->entity = $this->getService()->modify($entity, $validDatas);
}
//단일필드작업기능
final public function toggle(mixed $uid, string $field): RedirectResponse|string
{
//Transaction Start
@ -340,23 +274,7 @@ abstract class CommonController extends BaseController
return $this->getResultFail($e->getMessage());
}
}
//일괄처리작업
final protected function batchjob_process(array $uids, array $formDatas): void
{
$entities = [];
foreach ($uids as $uid) {
//기존 Entity 가져오기
$entity = $this->getService()->getEntity($uid);
if (!$entity) {
LogCollector::debug(__METHOD__ . "에서 {$uid}에 대한 정보를 찾을수 없습니다.");
} else {
//데이터 검증
$validDatas = $this->doValidate($this->getControlDatas('field_rules'), $formDatas);
$entities[] = $this->getService()->modify($entity, $validDatas);
}
}
$this->entities = $entities;
}
//일괄처리작업기능
final public function batchjob(): RedirectResponse|string
{
//Transaction Start
@ -391,12 +309,6 @@ abstract class CommonController extends BaseController
return $this->getResultFail($e->getMessage());
}
}
//삭제,일괄삭제 공통사용
protected function delete_process(mixed $entity): void
{
$this->entity = $this->getService()->delete($entity);
}
final public function delete(mixed $uid): RedirectResponse|string
{
//Transaction Start
@ -418,20 +330,6 @@ abstract class CommonController extends BaseController
}
}
//일괄삭제
final protected function batchjob_delete_process(array $uids): void
{
$entities = [];
foreach ($uids as $uid) {
//기존 Entity 가져오기
$entity = $this->getService()->getEntity($uid);
if (!$entity) {
LogCollector::debug(__METHOD__ . "에서 {$uid}에 대한 정보를 찾을수 없습니다.");
} else {
$entities[] = $this->getService()->delete($entity);
}
}
$this->entities = $entities;
}
final public function batchjob_delete(): RedirectResponse|string
{
//Transaction Start
@ -453,12 +351,6 @@ abstract class CommonController extends BaseController
return $this->getResultFail($e->getMessage());
}
}
//View
protected function view_process(mixed $entity): void
{
$this->entity = $entity;
}
final public function view(string $uid): RedirectResponse|string
{
try {
@ -477,10 +369,9 @@ abstract class CommonController extends BaseController
return $this->getResultFail($e->getMessage());
}
}
//리스트
//리스트 기능
//조건절 처리
final protected function setConditionForList(): void
final protected function index_process_condition(): void
{
//Filter 조건절 처리
foreach ($this->_control['actionFilters'] as $field) {
@ -525,43 +416,6 @@ abstract class CommonController extends BaseController
$this->total_page = $pager->getPageCount($pager_group);
return $pager->links($pager_group, $template);
}
protected function index_process(): void
{
//조건절 , OrcerBy , Limit 처리
$this->setConditionForList();
$this->order_field = $this->request->getVar('order_field');
$this->order_value = $this->request->getVar('order_value');
$this->getService()->setOrderBy($this->order_field, $this->order_value);
$this->getService()->setLimit($this->per_page);
$this->getService()->setOffset(($this->page - 1) * $this->per_page);
$this->entities = $this->getService()->getEntities();
}
public function index(): RedirectResponse|string
{
try {
//FieldRule정의
//각 Field 초기화
$this->initAction(__FUNCTION__);
//Return Url정의
$this->getMyAuth()->pushCurrentUrl($this->request->getUri()->getPath() . ($this->request->getUri()->getQuery() ? "?" . $this->request->getUri()->getQuery() : ""));
// 현재 URL을 스택에 저장
helper(['form']);
//조건절 처리
$this->setConditionForList();
//TotalCount (SoftDelete적용이 되려면 countAllResults를 사용해야함)
$this->total_count = $this->getService()->getTotalCount();
//Pagination 처리
$this->pagination = $this->getPaginationForList();
//줄수 처리용
$this->page_options = $this->getPageOptiosForList();
$this->index_process();
return $this->getResultSuccess();
} catch (\Exception $e) {
return $e->getMessage();
// return $this->getResultFail($e->getMessage());
}
}
//OUPUT Document 관련
private function download_document(string $document_type, mixed $loaded_data): array
{
@ -618,4 +472,168 @@ abstract class CommonController extends BaseController
return $this->getResultFail($e->getMessage());
}
}
//공통 기본 기능
//추가 개별 처리 기능
//Field별 전달값받기
protected function getFormData_process(string $field, array $formDatas): array
{
return $formDatas;
}
protected function doValidation_process(Validation $validation, string $field, string $rule): Validation
{
switch ($field) {
default:
$validation->setRule($field, $field, $rule);
break;
}
return $validation;
}
//Field관련
protected function getResultFail(string $message = MESSAGES["FAILED"]): RedirectResponse
{
LogCollector::debug($message);
$this->getMyLogService()->save($this->getService()->getClassName(), $this->getAction(), $message, $this->getMyAuth()->getUIDByAuthInfo());
if ($this->request->getMethod() === 'POST') {
return redirect()->back()->withInput()->with('error', $message);
}
return redirect()->to($this->getMyAuth()->popPreviousUrl())->with('error', $message);
}
protected function getResultSuccess(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string
{
helper(['form']);
switch ($this->getAction()) {
case 'create':
case 'modify':
$this->getMyLogService()->save($this->getService()->getClassName(), $this->getAction(), $message, $this->getMyAuth()->getUIDByAuthInfo());
$result = $this->view($this->entity->getPK());
break;
case 'create_form':
case 'modify_form':
case 'login_form':
case 'view':
case 'index':
case 'download':
$this->control = $this->getControlDatas();
$this->getHelper()->setViewDatas($this->getViewDatas());
$actionTemplate = $this->request->getVar('ActionTemplate') ?? $actionTemplate;
if ($actionTemplate) {
$view_file = $this->view_path . $actionTemplate . DIRECTORY_SEPARATOR . $this->getAction();
} else {
$view_file = $this->view_path . $this->getAction();
}
$result = view($view_file, ['viewDatas' => $this->getViewDatas()]);
break;
default:
$result = redirect()->to($this->getMyAuth()->popPreviousUrl())->with('error', $message);
break;
}
return $result;
}
//Index,FieldForm관련
//생성관련
protected function create_form_process(): void {}
protected function create_process(array $formDatas): void
{
//데이터 검증
$validDatas = $this->doValidate($this->getControlDatas('field_rules'), $formDatas);
$this->entity = $this->getService()->create($validDatas);
}
//수정관련
protected function modify_form_process(mixed $entity): void
{
$this->entity = $entity;
}
protected function modify_process(mixed $entity, array $formDatas): void
{
//데이터 검증
$validDatas = $this->doValidate($this->getControlDatas('field_rules'), $formDatas);
$this->entity = $this->getService()->modify($entity, $validDatas);
}
//단일필드작업기능
protected function toggle_process(mixed $entity, array $formDatas): void
{
//데이터 검증
$validDatas = $this->doValidate($this->getControlDatas('field_rules'), $formDatas);
$this->entity = $this->getService()->modify($entity, $validDatas);
}
//일괄처리작업기능
protected function batchjob_process(array $uids, array $formDatas): void
{
$entities = [];
foreach ($uids as $uid) {
//기존 Entity 가져오기
$entity = $this->getService()->getEntity($uid);
if (!$entity) {
LogCollector::debug(__METHOD__ . "에서 {$uid}에 대한 정보를 찾을수 없습니다.");
} else {
//데이터 검증
$validDatas = $this->doValidate($this->getControlDatas('field_rules'), $formDatas);
$entities[] = $this->getService()->modify($entity, $validDatas);
}
}
$this->entities = $entities;
}
//삭제관련
protected function delete_process(mixed $entity): void
{
$this->entity = $this->getService()->delete($entity);
}
//일괄삭제관련
protected function batchjob_delete_process(array $uids): void
{
$entities = [];
foreach ($uids as $uid) {
//기존 Entity 가져오기
$entity = $this->getService()->getEntity($uid);
if (!$entity) {
LogCollector::debug(__METHOD__ . "에서 {$uid}에 대한 정보를 찾을수 없습니다.");
} else {
$entities[] = $this->getService()->delete($entity);
}
}
$this->entities = $entities;
}
//View 관련
protected function view_process(mixed $entity): void
{
$this->entity = $entity;
}
//리스트관련
protected function index_process(): void
{
//조건절 , OrcerBy , Limit 처리
$this->index_process_condition();
$this->order_field = $this->request->getVar('order_field');
$this->order_value = $this->request->getVar('order_value');
$this->getService()->setOrderBy($this->order_field, $this->order_value);
$this->getService()->setLimit($this->per_page);
$this->getService()->setOffset(($this->page - 1) * $this->per_page);
$this->entities = $this->getService()->getEntities();
}
public function index(): RedirectResponse|string
{
try {
//FieldRule정의
//각 Field 초기화
$this->initAction(__FUNCTION__);
//Return Url정의
$this->getMyAuth()->pushCurrentUrl($this->request->getUri()->getPath() . ($this->request->getUri()->getQuery() ? "?" . $this->request->getUri()->getQuery() : ""));
// 현재 URL을 스택에 저장
helper(['form']);
//조건절 처리
$this->index_process_condition();
//TotalCount (SoftDelete적용이 되려면 countAllResults를 사용해야함)
$this->total_count = $this->getService()->getTotalCount();
//Pagination 처리
$this->pagination = $this->getPaginationForList();
//줄수 처리용
$this->page_options = $this->getPageOptiosForList();
$this->index_process();
return $this->getResultSuccess();
} catch (\Exception $e) {
return $e->getMessage();
// return $this->getResultFail($e->getMessage());
}
}
}