cfmgrv4 init...1
This commit is contained in:
parent
4f4e05b14b
commit
445dfd7cb0
@ -3,8 +3,9 @@
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Helpers\UserSNSHelper;
|
||||
use App\Models\UserSNSModel;
|
||||
use App\Models\UserModel;
|
||||
|
||||
use App\Models\UserSNSModel;
|
||||
use CodeIgniter\HTTP\DownloadResponse;
|
||||
use CodeIgniter\HTTP\RedirectResponse;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
@ -42,6 +43,13 @@ class UserSNSController extends AdminController
|
||||
protected function getFormFieldOption(string $field, array $options = []): array
|
||||
{
|
||||
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:
|
||||
$options = parent::getFormFieldOption($field, $options);
|
||||
break;
|
||||
@ -60,9 +68,9 @@ class UserSNSController extends AdminController
|
||||
private function init(string $action): void
|
||||
{
|
||||
$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->filter_fields = ['status'];
|
||||
$this->filter_fields = [$this->getModel()::PARENT, 'status'];
|
||||
$this->field_options = $this->getFormFieldOptions($this->filter_fields);
|
||||
}
|
||||
//수정
|
||||
@ -88,9 +96,9 @@ class UserSNSController extends AdminController
|
||||
public function index(): string
|
||||
{
|
||||
$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->filter_fields = ['status'];
|
||||
$this->filter_fields = [$this->getModel()::PARENT, 'status'];
|
||||
$this->field_options = $this->getFormFieldOptions($this->filter_fields);
|
||||
$this->batchjob_fields = ['status'];
|
||||
return $this->list_procedure();
|
||||
@ -99,9 +107,9 @@ class UserSNSController extends AdminController
|
||||
public function download(string $output_type, $uid = false): DownloadResponse|string
|
||||
{
|
||||
$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->filter_fields = ['status'];
|
||||
$this->filter_fields = [$this->getModel()::PARENT, 'status'];
|
||||
$this->field_options = $this->getFormFieldOptions($this->filter_fields);
|
||||
$this->batchjob_fields = ['status'];
|
||||
return $this->download_procedure($output_type, $uid);
|
||||
|
||||
@ -294,7 +294,7 @@ abstract class MVController extends CommonController
|
||||
{
|
||||
$this->list_condition_process();
|
||||
$total_count = $this->getModel()->countAllResults();
|
||||
// echo $this->getModel()->getLastQuery();
|
||||
// log_message("debug", $this->getModel()->getLastQuery());
|
||||
return $total_count;
|
||||
}
|
||||
//PageNation 처리
|
||||
@ -343,7 +343,7 @@ abstract class MVController extends CommonController
|
||||
);
|
||||
}
|
||||
$entitys = $this->getModel()->select($this->getModel()->getTable() . '.*')->findAll();
|
||||
log_message("debug", $this->getModel()->getLastQuery());
|
||||
// log_message("debug", $this->getModel()->getLastQuery());
|
||||
return $entitys;
|
||||
}
|
||||
final protected function list_procedure(): string
|
||||
|
||||
@ -24,7 +24,7 @@ class AccountEntity extends CommonEntity
|
||||
$this->attributes[AccountModel::TITLE] = $title;
|
||||
}
|
||||
//Common Function
|
||||
public function getParent(): string
|
||||
public function getParent(): int
|
||||
{
|
||||
return $this->attributes[AccountModel::PARENT];
|
||||
}
|
||||
|
||||
@ -11,6 +11,10 @@ class UserSNSEntity extends CommonEntity
|
||||
{
|
||||
return "{$this->getPK()}|{$this->getID()}|{$this->getTitle()}";
|
||||
}
|
||||
public function getPK(): int
|
||||
{
|
||||
return $this->attributes[UserSNSModel::PK];
|
||||
}
|
||||
public function getTitle(): string
|
||||
{
|
||||
return $this->attributes[UserSNSModel::TITLE];
|
||||
@ -20,19 +24,18 @@ class UserSNSEntity extends CommonEntity
|
||||
$this->attributes[UserSNSModel::TITLE] = $title;
|
||||
}
|
||||
//Common Function
|
||||
|
||||
public function getPK(): int
|
||||
public function getParent(): int|null
|
||||
{
|
||||
return $this->attributes[UserSNSModel::PK];
|
||||
}
|
||||
public function getSite(): string
|
||||
{
|
||||
return $this->attributes['site'];
|
||||
return $this->attributes[UserSNSModel::PARENT];
|
||||
}
|
||||
public function getID(): string
|
||||
{
|
||||
return $this->attributes['id'];
|
||||
}
|
||||
public function getSite(): string
|
||||
{
|
||||
return $this->attributes['site'];
|
||||
}
|
||||
public function getEmail(): string
|
||||
{
|
||||
return $this->attributes['email'];
|
||||
|
||||
@ -20,8 +20,7 @@ class AccountHelper extends CommonHelper
|
||||
$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]
|
||||
], isset($viewDatas[$field]) ? $viewDatas[$field] : $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]);
|
||||
] + $viewDatas['field_options'][$field], $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]);
|
||||
break;
|
||||
case AccountModel::TITLE:
|
||||
$form = form_input($field, $value, ["placeholder" => "예)test@exmaple.com", ...$extras]);
|
||||
@ -29,8 +28,7 @@ class AccountHelper extends CommonHelper
|
||||
case 'type':
|
||||
$form = form_dropdown($field, [
|
||||
"" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
|
||||
...$viewDatas['field_options'][$field],
|
||||
], $value, $extras);
|
||||
] + $viewDatas['field_options'][$field], $value, $extras);
|
||||
break;
|
||||
default:
|
||||
$form = parent::getFieldForm($field, $value, $viewDatas, $extras);
|
||||
|
||||
@ -20,8 +20,7 @@ class RecordHelper extends CommonHelper
|
||||
$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]
|
||||
], isset($viewDatas[$field]) ? $viewDatas[$field] : $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]);
|
||||
] + $viewDatas['field_options'][$field], $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]);
|
||||
break;
|
||||
case RecordModel::TITLE: //host
|
||||
$form = form_input($field, $value, $extras);
|
||||
@ -42,8 +41,7 @@ class RecordHelper extends CommonHelper
|
||||
case "proxiable":
|
||||
$form = form_dropdown($field, [
|
||||
"" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
|
||||
...$viewDatas['field_options'][$field],
|
||||
], $value, $extras);
|
||||
] + $viewDatas['field_options'][$field], $value, $extras);
|
||||
break;
|
||||
default:
|
||||
$form = parent::getFieldForm($field, $value, $viewDatas, $extras);
|
||||
|
||||
@ -20,8 +20,7 @@ class ZoneHelper extends CommonHelper
|
||||
$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]
|
||||
], isset($viewDatas[$field]) ? $viewDatas[$field] : $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]);
|
||||
] + $viewDatas['field_options'][$field], $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]);
|
||||
break;
|
||||
case ZoneModel::TITLE:
|
||||
$form = form_input($field, $value, ["placeholder" => "예)exampel.com", ...$extras]);
|
||||
@ -44,15 +43,13 @@ class ZoneHelper extends CommonHelper
|
||||
case 'status':
|
||||
$form = form_dropdown($field, [
|
||||
"" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
|
||||
...$viewDatas['field_options'][$field]
|
||||
], $value, $extras);
|
||||
] + $viewDatas['field_options'][$field], $value, $extras);
|
||||
break;
|
||||
case 'type': //A,AAA...
|
||||
case 'proxied': //CDN사용여부
|
||||
$form = form_dropdown($field, [
|
||||
"" => lang('Cloudflare/Record.label.' . $field) . ' 선택',
|
||||
...$viewDatas['field_options'][$field]
|
||||
], $value, $extras);
|
||||
] + $viewDatas['field_options'][$field], $value, $extras);
|
||||
break;
|
||||
default:
|
||||
$form = parent::getFieldForm($field, $value, $viewDatas, $extras);
|
||||
|
||||
@ -149,8 +149,7 @@ abstract class CommonHelper
|
||||
case 'status':
|
||||
$form = form_dropdown($field, [
|
||||
"" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
|
||||
...$viewDatas['field_options'][$field]
|
||||
], $value, $extras);
|
||||
] + $viewDatas['field_options'][$field], $value, $extras);
|
||||
break;
|
||||
case 'updated_at':
|
||||
case 'created_at':
|
||||
@ -181,7 +180,7 @@ abstract class CommonHelper
|
||||
$value = $value ? date("Y-m-d", strtotime($value)) : "";
|
||||
break;
|
||||
default:
|
||||
if (in_array($field, $viewDatas['filter_fields']) && $value) {
|
||||
if (in_array($field, $viewDatas['filter_fields'])) {
|
||||
$extras["onChange"] = sprintf(
|
||||
'location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value',
|
||||
current_url(),
|
||||
|
||||
@ -45,8 +45,7 @@ class UserHelper extends CommonHelper
|
||||
$field,
|
||||
[
|
||||
"" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
|
||||
...$viewDatas['field_options'][$field]
|
||||
],
|
||||
] + $viewDatas['field_options'][$field],
|
||||
$value,
|
||||
$extras
|
||||
);
|
||||
|
||||
@ -14,6 +14,12 @@ class UserSNSHelper extends CommonHelper
|
||||
{
|
||||
$value = $value ?: DEFAULTS['EMPTY'];
|
||||
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 UserSNSModel::TITLE:
|
||||
$form = form_input($field, $value, $extras);
|
||||
@ -33,4 +39,5 @@ class UserSNSHelper extends CommonHelper
|
||||
}
|
||||
return $form;
|
||||
} //
|
||||
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ return [
|
||||
'title' => "SNS 계정정보",
|
||||
'label' => [
|
||||
'uid' => "번호",
|
||||
'user_uid' => "local계정",
|
||||
'site' => "사이트",
|
||||
'id' => "계정",
|
||||
'name' => "이름",
|
||||
|
||||
@ -41,10 +41,9 @@ class GoogleAuth extends MyAuth
|
||||
// Google 서비스 설정
|
||||
$userSNS_entity = $this->getMySocket()->getUserSNSEntity();
|
||||
//local db 사용와의 연결 확인
|
||||
$userModel = model(UserModel::class);
|
||||
$user_entity = $userModel->getEntityByID($userSNS_entity->getID());
|
||||
$user_entity = $this->getModel()->getEntityByPK($userSNS_entity->getParent());
|
||||
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;
|
||||
} catch (\Google_Service_Exception $e) {
|
||||
|
||||
@ -48,7 +48,7 @@ class AuthModel extends CommonModel
|
||||
{
|
||||
switch ($field) {
|
||||
default:
|
||||
$this->orderBy(self::PK, 'asc');
|
||||
$this->orderBy(self::TITLE, 'asc');
|
||||
$options = parent::getFormFieldOption($field, $options);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -114,7 +114,6 @@ abstract class CommonModel extends Model
|
||||
break;
|
||||
}
|
||||
// dd($options);
|
||||
// exit;
|
||||
return $options;
|
||||
}
|
||||
final public function getEntity(): array|object|null
|
||||
@ -157,21 +156,27 @@ abstract class CommonModel extends Model
|
||||
|
||||
private function save_process($entity): mixed
|
||||
{
|
||||
//최종 변경사항이 있으면 저장
|
||||
if ($entity->hasChanged()) {
|
||||
try {
|
||||
//최종 변경사항이 없으면
|
||||
if (!$entity->hasChanged()) {
|
||||
throw new \Exception(__FUNCTION__ . " 변경된 내용이 없습니다.");
|
||||
}
|
||||
// log_message("debug", var_export($entity, true));
|
||||
//최종 저장시 오류발생하면
|
||||
if (!$this->save($entity)) {
|
||||
throw new \Exception(sprintf(
|
||||
throw new \Exception("저장오류:" . var_export($this->errors(), true));
|
||||
}
|
||||
log_message("notice", $this->getTable() . " => " . __FUNCTION__ . " DB 저장이 완료되었습니다.");
|
||||
return $entity;
|
||||
} catch (\Exception $e) {
|
||||
$message = sprintf(
|
||||
"\n------%s SQL오류-----\n%s\n%s\n------------------------------\n",
|
||||
__FUNCTION__,
|
||||
$this->getLastQuery(),
|
||||
var_export($this->errors(), true)
|
||||
));
|
||||
$e->getMessage()
|
||||
);
|
||||
throw new \Exception($message);
|
||||
}
|
||||
log_message("notice", $this->getTable() . " => " . __FUNCTION__ . " DB 저장이 완료되었습니다.");
|
||||
} else {
|
||||
log_message("notice", __FUNCTION__ . " 변경된 내용이 없습니다.");
|
||||
}
|
||||
return $entity;
|
||||
}
|
||||
final protected function create_process($entity, array $formDatas): mixed
|
||||
{
|
||||
|
||||
@ -73,7 +73,16 @@ class UserModel extends CommonModel
|
||||
}
|
||||
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
|
||||
{
|
||||
$this->where($this->getPKField(), intval($uid));
|
||||
|
||||
@ -10,12 +10,14 @@ class UserSNSModel extends CommonModel
|
||||
const TABLE = "user_sns";
|
||||
const PK = "uid";
|
||||
const TITLE = "name";
|
||||
const PARENT = "user_uid";
|
||||
const SITE = "site";
|
||||
protected $table = self::TABLE;
|
||||
protected $primaryKey = self::PK;
|
||||
protected $returnType = UserSNSEntity::class;
|
||||
protected $allowedFields = [
|
||||
"site",
|
||||
"user_uid",
|
||||
"id",
|
||||
"name",
|
||||
"email",
|
||||
@ -76,7 +78,6 @@ class UserSNSModel extends CommonModel
|
||||
$this->where('id', $id);
|
||||
return $this->getEntity();
|
||||
}
|
||||
|
||||
//create용
|
||||
public function create(array $formDatas = []): UserSNSEntity
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user