cfmgrv4 init...1

This commit is contained in:
최준흠 2024-10-11 11:41:13 +09:00
parent 4f4e05b14b
commit 445dfd7cb0
16 changed files with 78 additions and 54 deletions

View File

@ -3,8 +3,9 @@
namespace App\Controllers\Admin; namespace App\Controllers\Admin;
use App\Helpers\UserSNSHelper; use App\Helpers\UserSNSHelper;
use App\Models\UserSNSModel; use App\Models\UserModel;
use App\Models\UserSNSModel;
use CodeIgniter\HTTP\DownloadResponse; use CodeIgniter\HTTP\DownloadResponse;
use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
@ -42,6 +43,13 @@ class UserSNSController extends AdminController
protected function getFormFieldOption(string $field, array $options = []): array protected function getFormFieldOption(string $field, array $options = []): array
{ {
switch ($field) { switch ($field) {
case $this->getModel()::PARENT:
$userModel = model(UserModel::class);
// $this->getUserModel()->where('status', DEFAULTS['STATUS']);
$options[$field] = $userModel->getFormFieldOption($field);
// echo $this->getUserModel()->getLastQuery();
// dd($options);
break;
default: default:
$options = parent::getFormFieldOption($field, $options); $options = parent::getFormFieldOption($field, $options);
break; break;
@ -60,9 +68,9 @@ class UserSNSController extends AdminController
private function init(string $action): void private function init(string $action): void
{ {
$this->action = $action; $this->action = $action;
$this->fields = ['site', 'id', $this->getModel()::TITLE, 'email']; $this->fields = [$this->getModel()::PARENT, 'site', 'id', $this->getModel()::TITLE, 'email'];
$this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields);
$this->filter_fields = ['status']; $this->filter_fields = [$this->getModel()::PARENT, 'status'];
$this->field_options = $this->getFormFieldOptions($this->filter_fields); $this->field_options = $this->getFormFieldOptions($this->filter_fields);
} }
//수정 //수정
@ -88,9 +96,9 @@ class UserSNSController extends AdminController
public function index(): string public function index(): string
{ {
$this->action = __FUNCTION__; $this->action = __FUNCTION__;
$this->fields = ['site', 'id', $this->getModel()::TITLE, 'email', 'status']; $this->fields = [$this->getModel()::PARENT, 'site', 'id', $this->getModel()::TITLE, 'email', 'status'];
$this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields);
$this->filter_fields = ['status']; $this->filter_fields = [$this->getModel()::PARENT, 'status'];
$this->field_options = $this->getFormFieldOptions($this->filter_fields); $this->field_options = $this->getFormFieldOptions($this->filter_fields);
$this->batchjob_fields = ['status']; $this->batchjob_fields = ['status'];
return $this->list_procedure(); return $this->list_procedure();
@ -99,9 +107,9 @@ class UserSNSController extends AdminController
public function download(string $output_type, $uid = false): DownloadResponse|string public function download(string $output_type, $uid = false): DownloadResponse|string
{ {
$this->action = __FUNCTION__; $this->action = __FUNCTION__;
$this->fields = ['site', 'id', $this->getModel()::TITLE, 'email', 'status']; $this->fields = [$this->getModel()::PARENT, 'site', 'id', $this->getModel()::TITLE, 'email', 'status'];
$this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields);
$this->filter_fields = ['status']; $this->filter_fields = [$this->getModel()::PARENT, 'status'];
$this->field_options = $this->getFormFieldOptions($this->filter_fields); $this->field_options = $this->getFormFieldOptions($this->filter_fields);
$this->batchjob_fields = ['status']; $this->batchjob_fields = ['status'];
return $this->download_procedure($output_type, $uid); return $this->download_procedure($output_type, $uid);

View File

@ -294,7 +294,7 @@ abstract class MVController extends CommonController
{ {
$this->list_condition_process(); $this->list_condition_process();
$total_count = $this->getModel()->countAllResults(); $total_count = $this->getModel()->countAllResults();
// echo $this->getModel()->getLastQuery(); // log_message("debug", $this->getModel()->getLastQuery());
return $total_count; return $total_count;
} }
//PageNation 처리 //PageNation 처리
@ -343,7 +343,7 @@ abstract class MVController extends CommonController
); );
} }
$entitys = $this->getModel()->select($this->getModel()->getTable() . '.*')->findAll(); $entitys = $this->getModel()->select($this->getModel()->getTable() . '.*')->findAll();
log_message("debug", $this->getModel()->getLastQuery()); // log_message("debug", $this->getModel()->getLastQuery());
return $entitys; return $entitys;
} }
final protected function list_procedure(): string final protected function list_procedure(): string

View File

@ -24,7 +24,7 @@ class AccountEntity extends CommonEntity
$this->attributes[AccountModel::TITLE] = $title; $this->attributes[AccountModel::TITLE] = $title;
} }
//Common Function //Common Function
public function getParent(): string public function getParent(): int
{ {
return $this->attributes[AccountModel::PARENT]; return $this->attributes[AccountModel::PARENT];
} }

View File

@ -11,6 +11,10 @@ class UserSNSEntity extends CommonEntity
{ {
return "{$this->getPK()}|{$this->getID()}|{$this->getTitle()}"; return "{$this->getPK()}|{$this->getID()}|{$this->getTitle()}";
} }
public function getPK(): int
{
return $this->attributes[UserSNSModel::PK];
}
public function getTitle(): string public function getTitle(): string
{ {
return $this->attributes[UserSNSModel::TITLE]; return $this->attributes[UserSNSModel::TITLE];
@ -20,19 +24,18 @@ class UserSNSEntity extends CommonEntity
$this->attributes[UserSNSModel::TITLE] = $title; $this->attributes[UserSNSModel::TITLE] = $title;
} }
//Common Function //Common Function
public function getParent(): int|null
public function getPK(): int
{ {
return $this->attributes[UserSNSModel::PK]; return $this->attributes[UserSNSModel::PARENT];
}
public function getSite(): string
{
return $this->attributes['site'];
} }
public function getID(): string public function getID(): string
{ {
return $this->attributes['id']; return $this->attributes['id'];
} }
public function getSite(): string
{
return $this->attributes['site'];
}
public function getEmail(): string public function getEmail(): string
{ {
return $this->attributes['email']; return $this->attributes['email'];

View File

@ -20,8 +20,7 @@ class AccountHelper extends CommonHelper
$extra_class = isset($extras['class']) ? $extras['class'] . ' select-field' : 'select-field'; $extra_class = isset($extras['class']) ? $extras['class'] . ' select-field' : 'select-field';
$form = form_dropdown($field, [ $form = form_dropdown($field, [
"" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택', "" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
...$viewDatas['field_options'][$field] ] + $viewDatas['field_options'][$field], $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]);
], isset($viewDatas[$field]) ? $viewDatas[$field] : $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]);
break; break;
case AccountModel::TITLE: case AccountModel::TITLE:
$form = form_input($field, $value, ["placeholder" => "예)test@exmaple.com", ...$extras]); $form = form_input($field, $value, ["placeholder" => "예)test@exmaple.com", ...$extras]);
@ -29,8 +28,7 @@ class AccountHelper extends CommonHelper
case 'type': case 'type':
$form = form_dropdown($field, [ $form = form_dropdown($field, [
"" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택', "" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
...$viewDatas['field_options'][$field], ] + $viewDatas['field_options'][$field], $value, $extras);
], $value, $extras);
break; break;
default: default:
$form = parent::getFieldForm($field, $value, $viewDatas, $extras); $form = parent::getFieldForm($field, $value, $viewDatas, $extras);

View File

@ -20,8 +20,7 @@ class RecordHelper extends CommonHelper
$extra_class = isset($extras['class']) ? $extras['class'] . ' select-field' : 'select-field'; $extra_class = isset($extras['class']) ? $extras['class'] . ' select-field' : 'select-field';
$form = form_dropdown($field, [ $form = form_dropdown($field, [
"" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택', "" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
...$viewDatas['field_options'][$field] ] + $viewDatas['field_options'][$field], $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]);
], isset($viewDatas[$field]) ? $viewDatas[$field] : $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]);
break; break;
case RecordModel::TITLE: //host case RecordModel::TITLE: //host
$form = form_input($field, $value, $extras); $form = form_input($field, $value, $extras);
@ -42,8 +41,7 @@ class RecordHelper extends CommonHelper
case "proxiable": case "proxiable":
$form = form_dropdown($field, [ $form = form_dropdown($field, [
"" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택', "" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
...$viewDatas['field_options'][$field], ] + $viewDatas['field_options'][$field], $value, $extras);
], $value, $extras);
break; break;
default: default:
$form = parent::getFieldForm($field, $value, $viewDatas, $extras); $form = parent::getFieldForm($field, $value, $viewDatas, $extras);

View File

@ -20,8 +20,7 @@ class ZoneHelper extends CommonHelper
$extra_class = isset($extras['class']) ? $extras['class'] . ' select-field' : 'select-field'; $extra_class = isset($extras['class']) ? $extras['class'] . ' select-field' : 'select-field';
$form = form_dropdown($field, [ $form = form_dropdown($field, [
"" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택', "" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
...$viewDatas['field_options'][$field] ] + $viewDatas['field_options'][$field], $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]);
], isset($viewDatas[$field]) ? $viewDatas[$field] : $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]);
break; break;
case ZoneModel::TITLE: case ZoneModel::TITLE:
$form = form_input($field, $value, ["placeholder" => "예)exampel.com", ...$extras]); $form = form_input($field, $value, ["placeholder" => "예)exampel.com", ...$extras]);
@ -44,15 +43,13 @@ class ZoneHelper extends CommonHelper
case 'status': case 'status':
$form = form_dropdown($field, [ $form = form_dropdown($field, [
"" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택', "" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
...$viewDatas['field_options'][$field] ] + $viewDatas['field_options'][$field], $value, $extras);
], $value, $extras);
break; break;
case 'type': //A,AAA... case 'type': //A,AAA...
case 'proxied': //CDN사용여부 case 'proxied': //CDN사용여부
$form = form_dropdown($field, [ $form = form_dropdown($field, [
"" => lang('Cloudflare/Record.label.' . $field) . ' 선택', "" => lang('Cloudflare/Record.label.' . $field) . ' 선택',
...$viewDatas['field_options'][$field] ] + $viewDatas['field_options'][$field], $value, $extras);
], $value, $extras);
break; break;
default: default:
$form = parent::getFieldForm($field, $value, $viewDatas, $extras); $form = parent::getFieldForm($field, $value, $viewDatas, $extras);

View File

@ -149,8 +149,7 @@ abstract class CommonHelper
case 'status': case 'status':
$form = form_dropdown($field, [ $form = form_dropdown($field, [
"" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택', "" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
...$viewDatas['field_options'][$field] ] + $viewDatas['field_options'][$field], $value, $extras);
], $value, $extras);
break; break;
case 'updated_at': case 'updated_at':
case 'created_at': case 'created_at':
@ -181,7 +180,7 @@ abstract class CommonHelper
$value = $value ? date("Y-m-d", strtotime($value)) : ""; $value = $value ? date("Y-m-d", strtotime($value)) : "";
break; break;
default: default:
if (in_array($field, $viewDatas['filter_fields']) && $value) { if (in_array($field, $viewDatas['filter_fields'])) {
$extras["onChange"] = sprintf( $extras["onChange"] = sprintf(
'location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', 'location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value',
current_url(), current_url(),

View File

@ -45,8 +45,7 @@ class UserHelper extends CommonHelper
$field, $field,
[ [
"" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택', "" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
...$viewDatas['field_options'][$field] ] + $viewDatas['field_options'][$field],
],
$value, $value,
$extras $extras
); );

View File

@ -14,6 +14,12 @@ class UserSNSHelper extends CommonHelper
{ {
$value = $value ?: DEFAULTS['EMPTY']; $value = $value ?: DEFAULTS['EMPTY'];
switch ($field) { switch ($field) {
case UserSNSModel::PARENT:
$extra_class = isset($extras['class']) ? $extras['class'] . ' select-field' : 'select-field';
$form = form_dropdown($field, [
"" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
] + $viewDatas['field_options'][$field], $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]);
break;
case 'id': case 'id':
case UserSNSModel::TITLE: case UserSNSModel::TITLE:
$form = form_input($field, $value, $extras); $form = form_input($field, $value, $extras);
@ -33,4 +39,5 @@ class UserSNSHelper extends CommonHelper
} }
return $form; return $form;
} // } //
} }

View File

@ -3,6 +3,7 @@ return [
'title' => "SNS 계정정보", 'title' => "SNS 계정정보",
'label' => [ 'label' => [
'uid' => "번호", 'uid' => "번호",
'user_uid' => "local계정",
'site' => "사이트", 'site' => "사이트",
'id' => "계정", 'id' => "계정",
'name' => "이름", 'name' => "이름",

View File

@ -41,10 +41,9 @@ class GoogleAuth extends MyAuth
// Google 서비스 설정 // Google 서비스 설정
$userSNS_entity = $this->getMySocket()->getUserSNSEntity(); $userSNS_entity = $this->getMySocket()->getUserSNSEntity();
//local db 사용와의 연결 확인 //local db 사용와의 연결 확인
$userModel = model(UserModel::class); $user_entity = $this->getModel()->getEntityByPK($userSNS_entity->getParent());
$user_entity = $userModel->getEntityByID($userSNS_entity->getID());
if ($user_entity === null) { if ($user_entity === null) {
throw new PageNotFoundException("{$userSNS_entity->getSite()}{$userSNS_entity->getEmail()}:{$userSNS_entity->getTitle()}님은 아직 사용자 연결이 이루어지지 않았습니다. "); throw new PageNotFoundException("회원[{$userSNS_entity->getTitle()}]님은 아직 로컬사용자 연결이 이루어지지 않았습니다.");
} }
return $user_entity; return $user_entity;
} catch (\Google_Service_Exception $e) { } catch (\Google_Service_Exception $e) {

View File

@ -48,7 +48,7 @@ class AuthModel extends CommonModel
{ {
switch ($field) { switch ($field) {
default: default:
$this->orderBy(self::PK, 'asc'); $this->orderBy(self::TITLE, 'asc');
$options = parent::getFormFieldOption($field, $options); $options = parent::getFormFieldOption($field, $options);
break; break;
} }

View File

@ -114,7 +114,6 @@ abstract class CommonModel extends Model
break; break;
} }
// dd($options); // dd($options);
// exit;
return $options; return $options;
} }
final public function getEntity(): array|object|null final public function getEntity(): array|object|null
@ -157,21 +156,27 @@ abstract class CommonModel extends Model
private function save_process($entity): mixed private function save_process($entity): mixed
{ {
//최종 변경사항이 있으면 저장 try {
if ($entity->hasChanged()) { //최종 변경사항이 없으면
if (!$entity->hasChanged()) {
throw new \Exception(__FUNCTION__ . " 변경된 내용이 없습니다.");
}
// log_message("debug", var_export($entity, true));
//최종 저장시 오류발생하면
if (!$this->save($entity)) { if (!$this->save($entity)) {
throw new \Exception(sprintf( throw new \Exception("저장오류:" . var_export($this->errors(), true));
"\n------%s SQL오류-----\n%s\n%s\n------------------------------\n",
__FUNCTION__,
$this->getLastQuery(),
var_export($this->errors(), true)
));
} }
log_message("notice", $this->getTable() . " => " . __FUNCTION__ . " DB 저장이 완료되었습니다."); log_message("notice", $this->getTable() . " => " . __FUNCTION__ . " DB 저장이 완료되었습니다.");
} else { return $entity;
log_message("notice", __FUNCTION__ . " 변경된 내용이 없습니다."); } catch (\Exception $e) {
$message = sprintf(
"\n------%s SQL오류-----\n%s\n%s\n------------------------------\n",
__FUNCTION__,
$this->getLastQuery(),
$e->getMessage()
);
throw new \Exception($message);
} }
return $entity;
} }
final protected function create_process($entity, array $formDatas): mixed final protected function create_process($entity, array $formDatas): mixed
{ {

View File

@ -73,7 +73,16 @@ class UserModel extends CommonModel
} }
return $value; return $value;
} }
public function getFormFieldOption(string $field, array $options = []): array
{
switch ($field) {
default:
$this->orderBy(self::TITLE, 'asc');
$options = parent::getFormFieldOption($field, $options);
break;
}
return $options;
}
public function getEntityByPK(string $uid): null|UserEntity public function getEntityByPK(string $uid): null|UserEntity
{ {
$this->where($this->getPKField(), intval($uid)); $this->where($this->getPKField(), intval($uid));

View File

@ -10,12 +10,14 @@ class UserSNSModel extends CommonModel
const TABLE = "user_sns"; const TABLE = "user_sns";
const PK = "uid"; const PK = "uid";
const TITLE = "name"; const TITLE = "name";
const PARENT = "user_uid";
const SITE = "site"; const SITE = "site";
protected $table = self::TABLE; protected $table = self::TABLE;
protected $primaryKey = self::PK; protected $primaryKey = self::PK;
protected $returnType = UserSNSEntity::class; protected $returnType = UserSNSEntity::class;
protected $allowedFields = [ protected $allowedFields = [
"site", "site",
"user_uid",
"id", "id",
"name", "name",
"email", "email",
@ -76,7 +78,6 @@ class UserSNSModel extends CommonModel
$this->where('id', $id); $this->where('id', $id);
return $this->getEntity(); return $this->getEntity();
} }
//create용 //create용
public function create(array $formDatas = []): UserSNSEntity public function create(array $formDatas = []): UserSNSEntity
{ {