trafficmonitor init...2
This commit is contained in:
parent
46955cf337
commit
e29f36f5a5
@ -36,18 +36,24 @@ class UserController extends AdminController
|
|||||||
break;
|
break;
|
||||||
case 'index':
|
case 'index':
|
||||||
$fields = ['id', 'name', 'email', 'mobile', 'role', 'status', 'created_at'];
|
$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;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new \Exception("지원하지 않는 action입니다.({$action})");
|
throw new \Exception("지원하지 않는 action입니다.({$action})");
|
||||||
// break;
|
// break;
|
||||||
}
|
}
|
||||||
|
$this->service->getFormService()->setFormFields($fields);
|
||||||
|
$this->service->getFormService()->setFormRules($action, $fields);
|
||||||
|
$this->service->getFormService()->setFormFilters($filters);
|
||||||
|
$this->service->getFormService()->getFormOptions($filters);
|
||||||
|
$this->service->getFormService()->setBatchjobFilters($filters);
|
||||||
|
|
||||||
$this->addViewDatas('helper', $this->service->getHelper());
|
$this->addViewDatas('helper', $this->service->getHelper());
|
||||||
$this->addViewDatas('formFields', $this->service->getFormService()->getFormFields($action, $fields));
|
$this->addViewDatas('formFields', $this->service->getFormService()->getFormFields());
|
||||||
$this->addViewDatas('formFilters', $this->service->getFormService()->getFormFilters($action, $filters));
|
$this->addViewDatas('formRules', $this->service->getFormService()->getFormRules());
|
||||||
$this->addViewDatas('formRules', $this->service->getFormService()->getFormRules($action, $fields));
|
$this->addViewDatas('formFilters', $this->service->getFormService()->getFormFilters());
|
||||||
$this->addViewDatas('formOptions', $this->service->getFormService()->getFormOptions($action, $filters));
|
$this->addViewDatas('formOptions', $this->service->getFormService()->getFormOptions());
|
||||||
|
$this->addViewDatas('index_batchjobFields', $this->service->getFormService()->getBatchjobFields());
|
||||||
|
$this->addViewDatas('index_batchjobButtions', $this->service->getFormService()->getBatchjobButtons());
|
||||||
}
|
}
|
||||||
protected function create_form_process(): void
|
protected function create_form_process(): void
|
||||||
{
|
{
|
||||||
|
|||||||
@ -36,9 +36,7 @@ abstract class AuthController extends CommonController
|
|||||||
abstract protected function login_process(): UserEntity;
|
abstract protected function login_process(): UserEntity;
|
||||||
final public function login(): RedirectResponse
|
final public function login(): RedirectResponse
|
||||||
{
|
{
|
||||||
$action = __FUNCTION__;
|
|
||||||
try {
|
try {
|
||||||
$this->action_init_process($action);
|
|
||||||
$this->login_process();
|
$this->login_process();
|
||||||
$redirect_url = $this->getAuthContext()->popPreviousUrl() ?? implode(DIRECTORY_SEPARATOR, $this->getActionPaths());
|
$redirect_url = $this->getAuthContext()->popPreviousUrl() ?? implode(DIRECTORY_SEPARATOR, $this->getActionPaths());
|
||||||
return redirect()->to($redirect_url)->with('message', MESSAGES['LOGIN']);
|
return redirect()->to($redirect_url)->with('message', MESSAGES['LOGIN']);
|
||||||
|
|||||||
@ -32,11 +32,17 @@ class GoogleController extends AuthController
|
|||||||
throw new \Exception("지원하지 않는 action입니다.({$action})");
|
throw new \Exception("지원하지 않는 action입니다.({$action})");
|
||||||
// break;
|
// break;
|
||||||
}
|
}
|
||||||
|
$this->service->getFormService()->setFormFields($fields);
|
||||||
|
$this->service->getFormService()->setFormRules($action, $fields);
|
||||||
|
$this->service->getFormService()->setFormFilters($filters);
|
||||||
|
$this->service->getFormService()->getFormOptions($filters);
|
||||||
|
$this->service->getFormService()->setBatchjobFilters($filters);
|
||||||
|
|
||||||
$this->addViewDatas('helper', $this->service->getHelper());
|
$this->addViewDatas('helper', $this->service->getHelper());
|
||||||
$this->addViewDatas('formFields', $this->service->getFormService()->getFormFields($action, $fields));
|
$this->addViewDatas('formFields', $this->service->getFormService()->getFormFields());
|
||||||
$this->addViewDatas('formFilters', $this->service->getFormService()->getFormFilters($action, $filters));
|
$this->addViewDatas('formRules', $this->service->getFormService()->getFormRules());
|
||||||
$this->addViewDatas('formRules', $this->service->getFormService()->getFormRules($action, $fields));
|
$this->addViewDatas('formFilters', $this->service->getFormService()->getFormFilters());
|
||||||
$this->addViewDatas('formOptions', $this->service->getFormService()->getFormOptions($action, $filters));
|
$this->addViewDatas('formOptions', $this->service->getFormService()->getFormOptions());
|
||||||
}
|
}
|
||||||
public function login_form_process(): void
|
public function login_form_process(): void
|
||||||
{
|
{
|
||||||
|
|||||||
@ -37,15 +37,22 @@ class LocalController extends AuthController
|
|||||||
throw new \Exception("지원하지 않는 action입니다.({$action})");
|
throw new \Exception("지원하지 않는 action입니다.({$action})");
|
||||||
// break;
|
// break;
|
||||||
}
|
}
|
||||||
|
$this->service->getFormService()->setFormFields($fields);
|
||||||
|
$this->service->getFormService()->setFormRules($action, $fields);
|
||||||
|
$this->service->getFormService()->setFormFilters($filters);
|
||||||
|
$this->service->getFormService()->getFormOptions($filters);
|
||||||
|
$this->service->getFormService()->setBatchjobFilters($filters);
|
||||||
|
|
||||||
$this->addViewDatas('helper', $this->service->getHelper());
|
$this->addViewDatas('helper', $this->service->getHelper());
|
||||||
$this->addViewDatas('formFields', $this->service->getFormService()->getFormFields($action, $fields));
|
$this->addViewDatas('formFields', $this->service->getFormService()->getFormFields());
|
||||||
$this->addViewDatas('formFilters', $this->service->getFormService()->getFormFilters($action, $filters));
|
$this->addViewDatas('formRules', $this->service->getFormService()->getFormRules());
|
||||||
$this->addViewDatas('formRules', $this->service->getFormService()->getFormRules($action, $fields));
|
$this->addViewDatas('formFilters', $this->service->getFormService()->getFormFilters());
|
||||||
$this->addViewDatas('formOptions', $this->service->getFormService()->getFormOptions($action, $filters));
|
$this->addViewDatas('formOptions', $this->service->getFormService()->getFormOptions());
|
||||||
}
|
}
|
||||||
//로그인처리
|
//로그인처리
|
||||||
protected function login_process(): UserEntity
|
protected function login_process(): UserEntity
|
||||||
{
|
{
|
||||||
|
$this->action_init_process('login');
|
||||||
$dto = new LocalDTO($this->request->getPost());
|
$dto = new LocalDTO($this->request->getPost());
|
||||||
return $this->service->login($dto);
|
return $this->service->login($dto);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,16 +11,15 @@ class GoogleForm extends CommonForm
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFormRule(string $action, string $field, array $rules = []): array
|
public function getFormRule(string $action, string $field): string
|
||||||
{
|
{
|
||||||
$rules = parent::getFormRule($action, $field, $rules);
|
|
||||||
switch ($field) {
|
switch ($field) {
|
||||||
case "access_code":
|
case "access_code":
|
||||||
$rules[$field] = "required|trim|string";
|
$rule = "required|trim|string";
|
||||||
default:
|
default:
|
||||||
$rules = parent::getFormRule($action, $field, $rules);
|
$rule = parent::getFormRule($action, $field);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return $rules;
|
return $rule;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,22 +11,20 @@ class LocalForm extends CommonForm
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFormRule(string $action, string $field, array $rules = []): array
|
public function getFormRule(string $action, string $field): string
|
||||||
{
|
{
|
||||||
$rules = parent::getFormRule($action, $field, $rules);
|
|
||||||
switch ($field) {
|
switch ($field) {
|
||||||
case "id":
|
case "id":
|
||||||
$rule = "required|trim|min_length[4]|max_length[20]";
|
$rule = "required|trim|min_length[4]|max_length[20]";
|
||||||
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
|
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
|
||||||
$rules[$field] = $rule;
|
|
||||||
break;
|
break;
|
||||||
case "passwd":
|
case "passwd":
|
||||||
$rules[$field] = in_array($action, ["create", "create_form"]) ? "required|trim|string" : "permit_empty|trim|string";
|
$rule = in_array($action, ["create", "create_form"]) ? "required|trim|string" : "permit_empty|trim|string";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$rules = parent::getFormRule($action, $field, $rules);
|
$rule = parent::getFormRule($action, $field);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return $rules;
|
return $rule;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,7 @@ class CollectorForm extends CommonForm
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFormRule(string $action, string $field, array $rules = []): array
|
public function getFormRule(string $action, string $field): string
|
||||||
{
|
{
|
||||||
switch ($field) {
|
switch ($field) {
|
||||||
case "trafficinfo_uid":
|
case "trafficinfo_uid":
|
||||||
@ -20,27 +20,26 @@ class CollectorForm extends CommonForm
|
|||||||
case "raw_in":
|
case "raw_in":
|
||||||
case "raw_out":
|
case "raw_out":
|
||||||
$rule = "required|trim|neumeric";
|
$rule = "required|trim|neumeric";
|
||||||
$rules[$field] = $rule;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$rules = parent::getFormRule($action, $field, $rules);
|
$rule = parent::getFormRule($action, $field);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return $rules;
|
return $rule;
|
||||||
}
|
}
|
||||||
public function getFormOption(string $action, string $field, array $options = []): array
|
public function getFormOption(string $field, array $options = ['options' => [], 'extras' => [], 'atttributes' => []]): array
|
||||||
{
|
{
|
||||||
|
$tempOptions = ['' => lang("{$this->getAttribute('class_path')}.label.{$field}") . " 선택"];
|
||||||
switch ($field) {
|
switch ($field) {
|
||||||
case 'trafficinfo_uid':
|
case 'trafficinfo_uid':
|
||||||
$tempOptions = ['' => lang("{$this->getAttribute('class_path')}.label.{$field}") . " 선택"];
|
|
||||||
foreach (service('trafficservice')->getEntities() as $entity) {
|
foreach (service('trafficservice')->getEntities() as $entity) {
|
||||||
$tempOptions[$entity->getPK()] = $entity->getTitle();
|
$tempOptions[$entity->getPK()] = $entity->getTitle();
|
||||||
}
|
}
|
||||||
$options[$field]['options'] = $tempOptions;
|
$options[$field]['options'] = $tempOptions;
|
||||||
$options[$field]['extras'] = ['class' => 'select-field'];
|
$options[$field]['extras'] = ['class' => 'form-control select-field'];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$options = parent::getFormOption($action, $field, $options);
|
$options = parent::getFormOption($field, $options);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return $options;
|
return $options;
|
||||||
|
|||||||
@ -8,6 +8,11 @@ use RuntimeException;
|
|||||||
abstract class CommonForm
|
abstract class CommonForm
|
||||||
{
|
{
|
||||||
private array $_attributes = [];
|
private array $_attributes = [];
|
||||||
|
private array $_formFields = [];
|
||||||
|
private array $_formRules = [];
|
||||||
|
private array $_formFilters = [];
|
||||||
|
private array $_batchjobFilters = [];
|
||||||
|
private array $_formOptions = [];
|
||||||
protected function __construct() {}
|
protected function __construct() {}
|
||||||
final public function setAttributes(array $attributes): void
|
final public function setAttributes(array $attributes): void
|
||||||
{
|
{
|
||||||
@ -20,34 +25,73 @@ abstract class CommonForm
|
|||||||
}
|
}
|
||||||
return $this->_attributes[$key];
|
return $this->_attributes[$key];
|
||||||
}
|
}
|
||||||
final public function getFormFields(string $action, array $fields, $tempFormFields = []): array
|
final public function setFormFields(array $fields): void
|
||||||
{
|
{
|
||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
$tempFormFields = $this->getFormField($action, $field, $tempFormFields);
|
$this->_formFields[$field] = $this->getFormFieldLabel($field);
|
||||||
}
|
}
|
||||||
return $tempFormFields;
|
|
||||||
}
|
}
|
||||||
final public function getFormFilters(string $action, array $fields = []): array
|
//$fields 매치된것만 반환, []->전체
|
||||||
|
final public function getFormFields(array $fields = []): array
|
||||||
{
|
{
|
||||||
return $fields;
|
// 1. $fields 배열이 비어있는지 확인합니다.
|
||||||
|
// getFormFields('create') 와 같이 호출될 경우 $fields는 빈 배열[]이 됩니다.
|
||||||
|
if (empty($fields)) {
|
||||||
|
// 비어있다면, _formFields 전체를 반환합니다.
|
||||||
|
return $this->_formFields;
|
||||||
|
}
|
||||||
|
// $fields의 값(원하는 필드명)을 키로 변환합니다.
|
||||||
|
// 예: ['test1'] -> ['test1' => 0]
|
||||||
|
$fieldsAsKeys = array_flip($fields);
|
||||||
|
// _formFields와 $fieldsAsKeys 간의 키를 비교하여 교집합을 반환합니다.
|
||||||
|
// 즉, $fields에 지정된 필드 정의만 추출됩니다.
|
||||||
|
return array_intersect_key($this->_formFields, $fieldsAsKeys);
|
||||||
}
|
}
|
||||||
final public function getFormRules(string $action, array $fields, array $rules = []): array
|
final public function setFormRules(string $action, array $fields): void
|
||||||
{
|
{
|
||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
$rules = $this->getFormRule($action, $field, $rules);
|
$this->_formRules[$field] = $this->getFormRule($action, $field);
|
||||||
}
|
}
|
||||||
return $rules;
|
|
||||||
}
|
}
|
||||||
final public function getFormOptions(string $action, array $fields, array $options = []): array
|
//$fields 매치된것만 반환, []->전체
|
||||||
|
final public function getFormRules(array $fields = []): array
|
||||||
|
{
|
||||||
|
if (empty($fields)) {
|
||||||
|
return $this->_formRules;
|
||||||
|
}
|
||||||
|
$fieldsAsKeys = array_flip($fields);
|
||||||
|
return array_intersect_key($this->_formRules, $fieldsAsKeys);
|
||||||
|
}
|
||||||
|
final public function setFormOptions(array $fields): void
|
||||||
{
|
{
|
||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
$options = $this->getFormOption($action, $field, $options);
|
$this->_formOptions[$field] = $this->getFormOption($field);
|
||||||
}
|
}
|
||||||
return $options;
|
|
||||||
}
|
}
|
||||||
final public function getBatchjobFields(array $fields = []): array
|
//$fields 매치된것만 반환, []->전체
|
||||||
|
final public function getFormOptions(array $fields = []): array
|
||||||
{
|
{
|
||||||
return $fields;
|
if (empty($fields)) {
|
||||||
|
return $this->_formOptions;
|
||||||
|
}
|
||||||
|
$fieldsAsKeys = array_flip($fields);
|
||||||
|
return array_intersect_key($this->_formOptions, $fieldsAsKeys);
|
||||||
|
}
|
||||||
|
final public function setFormFilters(array $fields): void
|
||||||
|
{
|
||||||
|
$this->_formFilters = $fields;
|
||||||
|
}
|
||||||
|
final public function getFormFilters(): array
|
||||||
|
{
|
||||||
|
return $this->_formFilters;
|
||||||
|
}
|
||||||
|
final public function setBatchjobFilters(array $fields): void
|
||||||
|
{
|
||||||
|
$this->_batchjobFilters = $fields;;
|
||||||
|
}
|
||||||
|
final public function getBatchjobFilters(): array
|
||||||
|
{
|
||||||
|
return $this->_batchjobFilters;
|
||||||
}
|
}
|
||||||
final public function getBatchjobButtons(array $buttions = [
|
final public function getBatchjobButtons(array $buttions = [
|
||||||
'batchjob' => '일괄 처리',
|
'batchjob' => '일괄 처리',
|
||||||
@ -56,18 +100,36 @@ abstract class CommonForm
|
|||||||
{
|
{
|
||||||
return $buttions;
|
return $buttions;
|
||||||
}
|
}
|
||||||
|
//Validation용
|
||||||
|
public function validate(array $formDatas): bool
|
||||||
|
{
|
||||||
|
$validation = service('validation');
|
||||||
|
$dynamicRules = [];
|
||||||
|
foreach ($this->getFormRules() as $field => $rule) {
|
||||||
|
//field별 추가 커스텀 룰 적용
|
||||||
|
list($field, $rule) = $this->getValidationRule($field, $rule);
|
||||||
|
$dynamicRules[$field] = $rule;
|
||||||
|
}
|
||||||
|
$validation->setRules($dynamicRules);
|
||||||
|
return $validation->run($formDatas);
|
||||||
|
}
|
||||||
//필수함수
|
//필수함수
|
||||||
//사용자정의 함수
|
//사용자정의 함수
|
||||||
public function getFormField(string $action, string $field, array $tempFormFields = []): array
|
protected function getValidationRule(string $field, string $rule): array
|
||||||
|
{
|
||||||
|
return array($field, $rule);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFormFieldLabel(string $field, ?string $label = null): string
|
||||||
{
|
{
|
||||||
switch ($field) {
|
switch ($field) {
|
||||||
default:
|
default:
|
||||||
$tempFormFields[$field] = lang("{$this->getAttribute('class_path')}.label.{$field}");
|
$label = $label ?? lang("{$this->getAttribute('class_path')}.label.{$field}");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return $tempFormFields;
|
return $label;
|
||||||
}
|
}
|
||||||
public function getFormRule(string $action, string $field, array $rules = []): array
|
public function getFormRule(string $action, string $field): string
|
||||||
{
|
{
|
||||||
switch ($field) {
|
switch ($field) {
|
||||||
case $this->getAttribute('pk_field'):
|
case $this->getAttribute('pk_field'):
|
||||||
@ -77,57 +139,55 @@ abstract class CommonForm
|
|||||||
} else {
|
} else {
|
||||||
$rule = "required|numeric";
|
$rule = "required|numeric";
|
||||||
}
|
}
|
||||||
$rules[$field] = $rule;
|
|
||||||
break;
|
break;
|
||||||
case $this->getAttribute('title_field'):
|
case $this->getAttribute('title_field'):
|
||||||
$rules[$field] = "required|trim|string";
|
$rule = "required|trim|string";
|
||||||
break;
|
break;
|
||||||
case "code":
|
case "code":
|
||||||
// a-zA-Z → 영문 대소문자,0-9 → 숫자,가-힣 → 한글 완성형,\- → 하이픈
|
// a-zA-Z → 영문 대소문자,0-9 → 숫자,가-힣 → 한글 완성형,\- → 하이픈
|
||||||
$rule = "required|regex_match[/^[a-zA-Z0-9가-힣\-]+$/]|min_length[4]|max_length[20]";
|
$rule = "required|regex_match[/^[a-zA-Z0-9가-힣\-]+$/]|min_length[4]|max_length[20]";
|
||||||
$rule .= in_array($action, ["create"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
|
$rule .= in_array($action, ["create"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
|
||||||
$rules[$field] = $rule;
|
|
||||||
break;
|
break;
|
||||||
case 'picture':
|
case 'picture':
|
||||||
$rules[$field] = "is_image[{$field}]|mime_in[{$field},image/jpg,image/jpeg,image/gif,image/png,image/webp]|max_size[{$field},300]|max_dims[{$field},2048,768]";
|
$rule = "is_image[{$field}]|mime_in[{$field},image/jpg,image/jpeg,image/gif,image/png,image/webp]|max_size[{$field},300]|max_dims[{$field},2048,768]";
|
||||||
break;
|
break;
|
||||||
case "updated_at":
|
case "updated_at":
|
||||||
case "created_at":
|
case "created_at":
|
||||||
case "deleted_at":
|
case "deleted_at":
|
||||||
$rules[$field] = "permit_empty|valid_date";
|
$rule = "permit_empty|valid_date";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$rules[$field] = "permit_empty|trim|string";
|
$rule = "permit_empty|trim|string";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return $rules;
|
return $rule;
|
||||||
}
|
}
|
||||||
public function getFormOption(string $action, string $field, array $options = []): array
|
public function getFormOption(string $field, array $options = ['options' => [], 'extras' => [], 'atttributes' => []]): array
|
||||||
{
|
{
|
||||||
|
$tempOptions = ['' => lang("{$this->getAttribute('class_path')}.label.{$field}") . " 선택"];
|
||||||
switch ($field) {
|
switch ($field) {
|
||||||
case 'user_uid':
|
case 'user_uid':
|
||||||
$tempOptions = ['' => lang("{$this->getAttribute('class_path')}.label.{$field}") . " 선택"];
|
|
||||||
foreach (service('userservice')->getEntities() as $entity) {
|
foreach (service('userservice')->getEntities() as $entity) {
|
||||||
$tempOptions[$entity->getPK()] = $entity->getTitle();
|
$tempOptions[$entity->getPK()] = $entity->getTitle();
|
||||||
|
// $options['attributes'][$entity->getPK()] = ['data-role' => implode(DEFAULTS['DELIMITER_ROLE'], $entity->getRole())];
|
||||||
}
|
}
|
||||||
$options[$field]['options'] = $tempOptions;
|
$options['options'] = $tempOptions;
|
||||||
$options[$field]['extras'] = ['class' => 'select-field'];
|
$options['extras'] = ['class' => 'form-control select-field'];
|
||||||
break;
|
break;
|
||||||
case 'clientinfo_uid':
|
case 'clientinfo_uid':
|
||||||
$tempOptions = ['' => lang("{$this->getAttribute('class_path')}.label.{$field}") . " 선택"];
|
|
||||||
foreach (service('clientervice')->getEntities() as $entity) {
|
foreach (service('clientervice')->getEntities() as $entity) {
|
||||||
$tempOptions[$entity->getPK()] = $entity->getTitle();
|
$tempOptions[$entity->getPK()] = $entity->getTitle();
|
||||||
|
// $options['attributes'][$entity->getPK()] = ['data-role' => implode(DEFAULTS['DELIMITER_ROLE'], $entity->getRole())];
|
||||||
}
|
}
|
||||||
$options[$field]['options'] = $tempOptions;
|
$options['options'] = $tempOptions;
|
||||||
$options[$field]['extras'] = ['class' => 'select-field'];
|
$options['extras'] = ['class' => 'form-control select-field'];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$tempOptions = [
|
foreach (lang($this->getAttribute('class_path') . "." . strtoupper($field)) as $key => $label) {
|
||||||
'' => lang("{$this->getAttribute('class_path')}.label.{$field}") . " 선택",
|
$tempOptions[$key] = $label;
|
||||||
...lang($this->getAttribute('class_path') . "." . strtoupper($field))
|
}
|
||||||
];
|
$options['options'] = $tempOptions;
|
||||||
$options[$field]['options'] = $tempOptions;
|
$options['extras'] = ['class' => 'form-control'];
|
||||||
$options[$field]['extras'] = [];
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return $options;
|
return $options;
|
||||||
|
|||||||
@ -11,20 +11,19 @@ class MylogForm extends CommonForm
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFormRule(string $action, string $field, array $rules = []): array
|
public function getFormRule(string $action, string $field): string
|
||||||
{
|
{
|
||||||
switch ($field) {
|
switch ($field) {
|
||||||
case "title":
|
case "title":
|
||||||
$rule = "required|trime|string";
|
$rule = "required|trime|string";
|
||||||
$rules[$field] = $rule;
|
|
||||||
break;
|
break;
|
||||||
case "content":
|
case "content":
|
||||||
$rules[$field] = "permit_empty|trim|string";
|
$rule = "permit_empty|trim|string";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$rules = parent::getFormRule($action, $field, $rules);
|
$rule = parent::getFormRule($action, $field);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return $rules;
|
return $rule;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,31 +10,27 @@ class TrafficForm extends CommonForm
|
|||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
public function getFormRule(string $action, string $field, array $rules = []): array
|
public function getFormRule(string $action, string $field): string
|
||||||
{
|
{
|
||||||
switch ($field) {
|
switch ($field) {
|
||||||
case "client":
|
case "client":
|
||||||
case "switch":
|
case "switch":
|
||||||
$rule = "required|trim|string";
|
$rule = "required|trim|string";
|
||||||
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
|
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
|
||||||
$rules[$field] = $rule;
|
|
||||||
break;
|
break;
|
||||||
case "ip":
|
case "ip":
|
||||||
$rule = "required|trim|valid_ip[both]"; //ipv4 , ipv6 , both(ipv4,ipv6)
|
$rule = "required|trim|valid_ip[both]"; //ipv4 , ipv6 , both(ipv4,ipv6)
|
||||||
$rules[$field] = $rule;
|
|
||||||
break;
|
break;
|
||||||
case "interface":
|
case "interface":
|
||||||
$rule = "required|trim|string";
|
$rule = "required|trim|string";
|
||||||
$rules[$field] = $rule;
|
|
||||||
break;
|
break;
|
||||||
case "status":
|
case "status":
|
||||||
$rule = "required|trim|string";
|
$rule = "required|trim|string";
|
||||||
$rules[$field] = $rule;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$rules = parent::getFormRule($action, $field, $rules);
|
$rule = parent::getFormRule($action, $field);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return $rules;
|
return $rule;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,42 +10,51 @@ class UserForm extends CommonForm
|
|||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
protected function getValidationRule(string $field, string $rule): array
|
||||||
public function getFormField(string $action, string $field, array $tempFormFields = []): array
|
|
||||||
{
|
{
|
||||||
switch ($field) {
|
switch ($field) {
|
||||||
default:
|
case 'role':
|
||||||
$tempFormFields = parent::getFormField($action, $field, $tempFormFields);
|
$field = "{$field}.*";
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
return parent::getValidationRule($field, $rule);
|
||||||
|
// break;
|
||||||
}
|
}
|
||||||
return $tempFormFields;
|
return array($field, $rule);
|
||||||
}
|
}
|
||||||
public function getFormRule(string $action, string $field, array $rules = []): array
|
// public function getFormFieldLabel(string $field, ?string $label = null): string
|
||||||
|
// {
|
||||||
|
// switch ($field) {
|
||||||
|
// default:
|
||||||
|
// $label = parent::getFormFieldLabel($field, $label);
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// return $label;
|
||||||
|
// }
|
||||||
|
public function getFormRule(string $action, string $field): string
|
||||||
{
|
{
|
||||||
switch ($field) {
|
switch ($field) {
|
||||||
case "id":
|
case "id":
|
||||||
$rule = "required|trim|min_length[4]|max_length[20]";
|
$rule = "required|trim|min_length[4]|max_length[20]";
|
||||||
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
|
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
|
||||||
$rules[$field] = $rule;
|
|
||||||
break;
|
break;
|
||||||
case "passwd":
|
case "passwd":
|
||||||
$rules[$field] = in_array($action, ["create", "create_form"]) ? "required" : "permit_empty" . "|trim|string";
|
$rule = in_array($action, ["create", "create_form"]) ? "required" : "permit_empty" . "|trim|string";
|
||||||
break;
|
break;
|
||||||
case "confirmpassword":
|
case "confirmpassword":
|
||||||
$rules[$field] = in_array($action, ["create", "create_form"]) ? "required" : "permit_empty" . "|trim|string|matches[passwd]";
|
$rule = in_array($action, ["create", "create_form"]) ? "required" : "permit_empty" . "|trim|string|matches[passwd]";
|
||||||
break;
|
break;
|
||||||
case "email":
|
case "email":
|
||||||
$rule = "required|trim|valid_email";
|
$rule = "required|trim|valid_email";
|
||||||
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "" . "|trim|valid_email";
|
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "" . "|trim|valid_email";
|
||||||
$rules[$field] = $rule;
|
|
||||||
break;
|
break;
|
||||||
case "role":
|
case "role":
|
||||||
$rules[$field] = "required|trim|string";
|
$rule = "required|trim|string";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$rules = parent::getFormRule($action, $field, $rules);
|
$rule = parent::getFormRule($action, $field);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return $rules;
|
return $rule;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,6 +32,54 @@ class CommonHelper
|
|||||||
}
|
}
|
||||||
return $label;
|
return $label;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* CI4의 form_dropdown()을 확장하여 <option> 태그에 data-* 속성을 추가할 수 있도록 합니다.
|
||||||
|
*
|
||||||
|
* @param string $name 폼 필드 이름
|
||||||
|
* @param array $options 드롭다운 옵션 배열.
|
||||||
|
* 값은 문자열/정수, 또는 추가 속성을 포함하는 배열일 수 있습니다.
|
||||||
|
* 예: ['value' => 'test1', 'text' => 'Test 1', 'data-price' => 1000]
|
||||||
|
* @param string|array|null $selected 현재 선택된 값
|
||||||
|
* @param string $extra <select> 태그에 추가할 속성
|
||||||
|
* @return string HTML <select> 태그
|
||||||
|
*/
|
||||||
|
public function form_dropdown_custom(string $name = '', array $options = [], $selected = null, string $extra = ''): string
|
||||||
|
{
|
||||||
|
$select = '<select name="' . esc($name) . '"' . $extra . ">\n";
|
||||||
|
// 선택된 값 처리
|
||||||
|
$selected = is_array($selected) ? $selected : [$selected];
|
||||||
|
foreach ($options as $key => $val) {
|
||||||
|
// 💡 핵심 로직: $val이 배열인지 확인합니다.
|
||||||
|
if (is_array($val)) {
|
||||||
|
// $val이 배열인 경우: 복합 옵션 (value, text, data-* 속성 포함)
|
||||||
|
$optionValue = $val['value'] ?? $key; // value가 없으면 키 사용
|
||||||
|
$optionText = $val['text'] ?? $optionValue;
|
||||||
|
$optionAttributes = '';
|
||||||
|
|
||||||
|
// data-* 속성 추출 및 조합
|
||||||
|
foreach ($val as $attrKey => $attrValue) {
|
||||||
|
// 'value'와 'text'는 <option> 속성이 아니므로 제외
|
||||||
|
if ($attrKey !== 'value' && $attrKey !== 'text') {
|
||||||
|
$optionAttributes .= " " . esc($attrKey) . '="' . esc($attrValue) . '"';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$optionSelected = in_array($optionValue, $selected) ? ' selected="selected"' : '';
|
||||||
|
$select .= '<option value="' . esc($optionValue) . '"' . $optionAttributes . $optionSelected . '>'
|
||||||
|
. esc($optionText)
|
||||||
|
. "</option>\n";
|
||||||
|
} else {
|
||||||
|
// $val이 배열이 아닌 경우: 일반 옵션 (기존 form_dropdown() 방식)
|
||||||
|
$optionSelected = in_array($key, $selected) ? ' selected="selected"' : '';
|
||||||
|
|
||||||
|
$select .= '<option value="' . esc($key) . '"' . $optionSelected . '>'
|
||||||
|
. esc($val)
|
||||||
|
. "</option>\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$select .= "</select>\n";
|
||||||
|
return $select;
|
||||||
|
}
|
||||||
|
|
||||||
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
|
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
|
||||||
{
|
{
|
||||||
switch ($field) {
|
switch ($field) {
|
||||||
|
|||||||
@ -105,9 +105,8 @@ abstract class AuthService
|
|||||||
$formDatas = (array)$dto;
|
$formDatas = (array)$dto;
|
||||||
// dd($formDatas);
|
// dd($formDatas);
|
||||||
//입력값 검증
|
//입력값 검증
|
||||||
$validation = service('validation')->setRules($this->getValidationRules(__FUNCTION__));
|
if (!$this->getFormService()->validate($formDatas)) {
|
||||||
if (!$validation->run($formDatas)) {
|
throw new ValidationException(implode("\n", service('validation')->getErrors()));
|
||||||
throw new ValidationException(implode("\n", $validation->getErrors()));
|
|
||||||
}
|
}
|
||||||
//인증처리
|
//인증처리
|
||||||
$entity = $this->login_process($formDatas);
|
$entity = $this->login_process($formDatas);
|
||||||
|
|||||||
@ -86,21 +86,6 @@ abstract class CommonService
|
|||||||
}
|
}
|
||||||
return $entities;
|
return $entities;
|
||||||
}
|
}
|
||||||
//Validation용
|
|
||||||
final protected function getValidationRules(string $action, array $rules): array
|
|
||||||
{
|
|
||||||
$dynamicRules = [];
|
|
||||||
foreach ($rules as $field => $rule) {
|
|
||||||
//field별 추가 커스텀 룰 적용
|
|
||||||
list($field, $rule) = $this->getValidationRule($field, $rule);
|
|
||||||
$dynamicRules[$field] = $rule;
|
|
||||||
}
|
|
||||||
return $dynamicRules;
|
|
||||||
}
|
|
||||||
protected function getValidationRule(string $field, string $rule): array
|
|
||||||
{
|
|
||||||
return array($field, $rule);
|
|
||||||
}
|
|
||||||
//CURD 결과처리용
|
//CURD 결과처리용
|
||||||
//DB 결과 처리 로직 통합 및 개선
|
//DB 결과 처리 로직 통합 및 개선
|
||||||
protected function handle_save_result(mixed $result, CommonEntity $entity): CommonEntity
|
protected function handle_save_result(mixed $result, CommonEntity $entity): CommonEntity
|
||||||
@ -129,9 +114,8 @@ abstract class CommonService
|
|||||||
{
|
{
|
||||||
$formDatas = (array)$dto;
|
$formDatas = (array)$dto;
|
||||||
//입력값 검증
|
//입력값 검증
|
||||||
$validation = service('validation')->setRules($this->getValidationRules(__FUNCTION__,));
|
if (!$this->getFormService()->validate($formDatas)) {
|
||||||
if (!$validation->run($formDatas)) {
|
throw new ValidationException(implode("\n", service('validation')->getErrors()));
|
||||||
throw new ValidationException(implode("\n", $validation->getErrors()));
|
|
||||||
}
|
}
|
||||||
$entity = $this->create_process($formDatas);
|
$entity = $this->create_process($formDatas);
|
||||||
$result = $this->model->insert($entity, $this->model->useAutoIncrement());
|
$result = $this->model->insert($entity, $this->model->useAutoIncrement());
|
||||||
@ -143,9 +127,8 @@ abstract class CommonService
|
|||||||
{
|
{
|
||||||
$formDatas = (array)$dto;
|
$formDatas = (array)$dto;
|
||||||
//입력값 검증
|
//입력값 검증
|
||||||
$validation = service('validation')->setRules($this->getValidationRules(__FUNCTION__));
|
if (!$this->getFormService()->validate($formDatas)) {
|
||||||
if (!$validation->run($formDatas)) {
|
throw new ValidationException(implode("\n", service('validation')->getErrors()));
|
||||||
throw new ValidationException(implode("\n", $validation->getErrors()));
|
|
||||||
}
|
}
|
||||||
$updatedEntity = $this->modify_process($uid, $formDatas);
|
$updatedEntity = $this->modify_process($uid, $formDatas);
|
||||||
$result = $this->model->save($updatedEntity);
|
$result = $this->model->save($updatedEntity);
|
||||||
|
|||||||
@ -45,18 +45,6 @@ class UserService extends CommonService
|
|||||||
return $this->helperInstance;
|
return $this->helperInstance;
|
||||||
}
|
}
|
||||||
//기본 기능부분
|
//기본 기능부분
|
||||||
protected function getValidationRule(string $field, string $rule): array
|
|
||||||
{
|
|
||||||
switch ($field) {
|
|
||||||
case 'role':
|
|
||||||
$field = "{$field}.*";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return parent::getValidationRule($field, $rule);
|
|
||||||
// break;
|
|
||||||
}
|
|
||||||
return array($field, $rule);
|
|
||||||
}
|
|
||||||
protected function create_process(array $formDatas): UserEntity
|
protected function create_process(array $formDatas): UserEntity
|
||||||
{
|
{
|
||||||
if (isset($formDatas['confirmpassword'])) {
|
if (isset($formDatas['confirmpassword'])) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user