diff --git a/app/Config/Routes.php b/app/Config/Routes.php index dd4ba91..36eb93c 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -71,6 +71,7 @@ $routes->group('admin/cloudflare', ['namespace' => 'App\Controllers\Admin\Cloudf $routes->get('create', 'AuthController::create_form'); $routes->post('create', 'AuthController::create'); $routes->get('modify/(:num)', 'AuthController::modify_form/$1'); + $routes->post('modify/(:num)', 'AuthController::modify/$1'); $routes->get('view/(:num)', 'AuthController::view/$1'); $routes->get('delete/(:num)', 'AuthController::delete/$1'); $routes->get('toggle/(:num)/(:any)', 'AuthController::toggle/$1/$2'); @@ -80,8 +81,9 @@ $routes->group('admin/cloudflare', ['namespace' => 'App\Controllers\Admin\Cloudf }); $routes->group('account', function ($routes) { $routes->get('/', 'AccountController::index'); + $routes->get('view/(:alphanum)', 'AccountController::view/$1'); $routes->get('reload/(:num)', 'AccountController::reload/$1'); - $routes->get('download/(:alpha)', 'AccountController::download/$1'); + $routes->get('download/(:alphanum)', 'AccountController::download/$1'); }); $routes->group('zone', function ($routes) { $routes->get('/', 'ZoneController::index'); diff --git a/app/Controllers/Admin/Cloudflare/AccountController.php b/app/Controllers/Admin/Cloudflare/AccountController.php index 079988b..c4a444a 100644 --- a/app/Controllers/Admin/Cloudflare/AccountController.php +++ b/app/Controllers/Admin/Cloudflare/AccountController.php @@ -13,7 +13,6 @@ use Psr\Log\LoggerInterface; class AccountController extends CloudflareController { - private $_model = null; private $_auth_entity = null; private $_myLibrays = []; public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) @@ -26,10 +25,10 @@ class AccountController extends CloudflareController } final protected function getModel(): AccountModel { - if ($this->_model === null) { - $this->_model = new AccountModel(); + if ($this->model === null) { + $this->model = new AccountModel(); } - return $this->_model; + return $this->model; } final protected function getMyLibrary(): Account { @@ -53,26 +52,31 @@ class AccountController extends CloudflareController } return $options; } - // 리스트 - public function index(): string + private function init(string $action, array $fields = []): void { - $this->action = __FUNCTION__; - $this->fields = [$this->getModel()::PARENT, $this->getModel()::TITLE, 'type', 'status', 'updated_at', 'created_at']; - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); + $this->action = $action; + $this->fields = count($fields) ? $fields : [$this->getModel()::PARENT, $this->getModel()::TITLE, 'type', 'status', 'updated_at', 'created_at']; + $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); $this->filter_fields = [$this->getModel()::PARENT, 'type', 'status']; $this->field_options = $this->getFormFieldOptions($this->filter_fields); $this->batchjob_fields = []; + } + //View + public function view(string $uid): RedirectResponse|string + { + $this->init(__FUNCTION__); + return $this->view_procedure($uid); + } + // 리스트 + public function index(): string + { + $this->init(__FUNCTION__); return $this->list_procedure(); } // Download public function download(string $output_type, mixed $uid = false): DownloadResponse|string { - $this->action = __FUNCTION__; - $this->fields = [$this->getModel()::PARENT, $this->getModel()::TITLE, 'type', 'status', 'updated_at', 'created_at']; - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - $this->filter_fields = [$this->getModel()::PARENT, 'type', 'status']; - $this->field_options = $this->getFormFieldOptions($this->filter_fields); - $this->batchjob_fields = ['type', 'status']; + $this->init(__FUNCTION__); return $this->download_procedure($output_type, $uid); } //reload Account By Auth diff --git a/app/Controllers/Admin/Cloudflare/AuthController.php b/app/Controllers/Admin/Cloudflare/AuthController.php index 63605c3..4397cc0 100644 --- a/app/Controllers/Admin/Cloudflare/AuthController.php +++ b/app/Controllers/Admin/Cloudflare/AuthController.php @@ -12,7 +12,6 @@ use Psr\Log\LoggerInterface; class AuthController extends CloudflareController { - private $_model = null; public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { parent::initController($request, $response, $logger); @@ -23,47 +22,46 @@ class AuthController extends CloudflareController } final protected function getModel(): AuthModel { - if ($this->_model === null) { - $this->_model = new AuthModel(); + if ($this->model === null) { + $this->model = new AuthModel(); } - return $this->_model; + return $this->model; } - private function init(string $action): void + private function init(string $action, array $fields = []): void { $this->action = $action; - $this->fields = [$this->getModel()::TITLE, 'authkey', 'status']; + $this->fields = count($fields) ? $fields : [$this->getModel()::TITLE, 'authkey', 'status', 'updated_at', 'created_at']; $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); $this->filter_fields = ['status']; $this->field_options = $this->getFormFieldOptions($this->filter_fields); + $this->batchjob_fields = ['status']; } //생성 public function create_form(): RedirectResponse|string { - $this->init('create'); + $this->init('create', [$this->getModel()::TITLE, 'authkey', 'status']); return $this->create_form_procedure(); } public function create(): RedirectResponse|string { - $this->init(__FUNCTION__); + $this->init(__FUNCTION__, [$this->getModel()::TITLE, 'authkey', 'status']); return $this->create_procedure(); } //수정 public function modify_form(int $uid): RedirectResponse|string { - $this->init('modify'); + $this->init('modify', [$this->getModel()::TITLE, 'authkey', 'status']); return $this->modify_form_procedure($uid); } public function modify(int $uid): RedirectResponse|string { - $this->init(__FUNCTION__); + $this->init(__FUNCTION__, [$this->getModel()::TITLE, 'authkey', 'status']); return $this->modify_procedure($uid); } //일괄처리작업 public function batcjob(): RedirectResponse { - $this->action = __FUNCTION__; - $this->fields = ['status']; - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); + $this->init(__FUNCTION__); return $this->batcjob_procedure(); } //View @@ -75,23 +73,13 @@ class AuthController extends CloudflareController // 리스트 public function index(): string { - $this->action = __FUNCTION__; - $this->fields = [$this->getModel()::TITLE, 'oldkey', 'status', 'updated_at', 'created_at']; - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - $this->filter_fields = ['status']; - $this->field_options = $this->getFormFieldOptions($this->filter_fields); - $this->batchjob_fields = ['status']; + $this->init(__FUNCTION__); return $this->list_procedure(); } // Download public function download(string $output_type, mixed $uid = false): DownloadResponse|string { - $this->action = __FUNCTION__; - $this->fields = [$this->getModel()::TITLE, 'oldkey', 'status', 'updated_at', 'created_at']; - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - $this->filter_fields = ['status']; - $this->field_options = $this->getFormFieldOptions($this->filter_fields); - $this->batchjob_fields = ['status']; + $this->init(__FUNCTION__); return $this->download_procedure($output_type, $uid); } } diff --git a/app/Controllers/Admin/Cloudflare/RecordController.php b/app/Controllers/Admin/Cloudflare/RecordController.php index 83cf191..19d054b 100644 --- a/app/Controllers/Admin/Cloudflare/RecordController.php +++ b/app/Controllers/Admin/Cloudflare/RecordController.php @@ -26,10 +26,10 @@ class RecordController extends CloudflareController } final protected function getModel(): RecordModel { - if ($this->_model === null) { - $this->_model = new RecordModel(); + if ($this->model === null) { + $this->model = new RecordModel(); } - return $this->_model; + return $this->model; } final protected function getMyLibrary(): Record { @@ -69,18 +69,21 @@ class RecordController extends CloudflareController } return $formDatas; } - private function init(string $action): void + private function init(string $action, array $fields = []): void { $this->action = $action; - $this->fields = [$this->getModel()::PARENT, 'hosts', 'type', 'content', 'proxied']; + $this->fields = count($fields) ? $fields : [$this->getModel()::PARENT, 'host', 'type', 'content', 'proxied', 'updated_at', 'created_at', 'created_at']; $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - $this->filter_fields = [$this->getModel()::PARENT, 'type', 'proxied']; + $this->filter_fields = [$this->getModel()::PARENT, 'type', 'proxied', 'fixed']; $this->field_options = $this->getFormFieldOptions($this->filter_fields); + $this->batchjob_fields = ['type', 'content', 'proxied']; } //생성 public function create_form(): RedirectResponse|string { - $this->init('create'); + $this->init('create', [$this->getModel()::PARENT, 'hosts', 'type', 'content', 'proxied']); + $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); + //부모데이터 정의 $parent_field = $this->getModel()::PARENT; $this->$parent_field = $this->request->getVar($parent_field) ?: DEFAULTS["EMPTY"]; return $this->create_form_procedure(); @@ -132,15 +135,13 @@ class RecordController extends CloudflareController } protected function create_process_result(): RedirectResponse|string { - $this->fields = [$this->getModel()::PARENT, $this->getModel()::TITLE, 'name_servers', 'original_name_servers', 'plan', 'development_mode', 'ipv6', 'security_level', 'status', 'updated_at', 'created_at']; - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - $this->filter_fields = [$this->getModel()::PARENT, 'development_mode', 'ipv6', 'security_level']; - $this->field_options = $this->getFormFieldOptions($this->filter_fields); + $this->init(__FUNCTION__); return $this->view_process_result(); } public function create(): RedirectResponse|string { - $this->init(__FUNCTION__); + $this->init(__FUNCTION__, [$this->getModel()::PARENT, 'hosts', 'type', 'content', 'proxied']); + $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); return $this->create_procedure(); } //수정 (modify,toggle,batchjob사용) @@ -170,16 +171,7 @@ class RecordController extends CloudflareController //일괄처리작업 public function batcjob(): RedirectResponse { - $this->action = __FUNCTION__; - //데이터가 있는경우 Field만 처리하기위해 - $fields = []; - foreach (['type', 'content', 'proxied'] as $field) { - if ($this->request->getVar($field)) { - $fields[$field] = $field; - } - } - $this->fields = $fields; - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); + $this->init(__FUNCTION__); return $this->batcjob_procedure(); } //View @@ -200,11 +192,7 @@ class RecordController extends CloudflareController } public function view(string $uid): RedirectResponse|string { - $this->action = __FUNCTION__; - $this->fields = [$this->getModel()::PARENT, $this->getModel()::TITLE, 'type', 'content', 'ttl', 'proxied', 'locked', 'updated_at', 'created_at']; - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - $this->filter_fields = [$this->getModel()::PARENT, 'type', 'proxied', 'fixed']; - $this->field_options = $this->getFormFieldOptions($this->filter_fields); + $this->init(__FUNCTION__); return $this->view_procedure($uid); } //삭제 @@ -253,23 +241,13 @@ class RecordController extends CloudflareController } public function index(): string { - $this->action = __FUNCTION__; - $this->fields = [$this->getModel()::PARENT, $this->getModel()::TITLE, 'type', 'content', 'ttl', 'proxied', 'locked', 'updated_at', 'created_at']; - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - $this->filter_fields = [$this->getModel()::PARENT, 'type', 'proxied', 'fixed']; - $this->field_options = $this->getFormFieldOptions($this->filter_fields); - $this->batchjob_fields = ['type', 'content', 'proxied']; + $this->init(__FUNCTION__); return $this->list_procedure(); } // Download public function download(string $output_type, mixed $uid = false): DownloadResponse|string { - $this->action = __FUNCTION__; - $this->fields = [$this->getModel()::PARENT, $this->getModel()::TITLE, 'type', 'content', 'ttl', 'proxied', 'locked', 'updated_at', 'created_at']; - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - $this->filter_fields = [$this->getModel()::PARENT, 'type', 'proxied']; - $this->field_options = $this->getFormFieldOptions($this->filter_fields); - $this->batchjob_fields = ['proxied']; + $this->init(__FUNCTION__); return $this->download_procedure($output_type, $uid); } //Sync작업 diff --git a/app/Controllers/Admin/Cloudflare/ZoneController.php b/app/Controllers/Admin/Cloudflare/ZoneController.php index a24c1ec..5eec029 100644 --- a/app/Controllers/Admin/Cloudflare/ZoneController.php +++ b/app/Controllers/Admin/Cloudflare/ZoneController.php @@ -17,7 +17,6 @@ class ZoneController extends CloudflareController { private $_account_entity = null; private $_myLibrays = []; - private $_model = null; public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { parent::initController($request, $response, $logger); @@ -28,10 +27,10 @@ class ZoneController extends CloudflareController } final protected function getModel(): ZoneModel { - if ($this->_model === null) { - $this->_model = new ZoneModel(); + if ($this->model === null) { + $this->model = new ZoneModel(); } - return $this->_model; + return $this->model; } final protected function getMyLibrary(): Zone { @@ -80,18 +79,23 @@ class ZoneController extends CloudflareController } return $formDatas; } - private function init(string $action): void + private function init(string $action, array $fields = []): void { $this->action = $action; - $this->fields = [$this->getModel()::PARENT, 'domains', 'hosts', 'type', 'content', 'proxied']; + $this->fields = count($fields) ? $fields : [$this->getModel()::PARENT, $this->getModel()::TITLE, 'name_servers', 'original_name_servers', 'plan', 'development_mode', 'ipv6', 'security_level', 'status', 'updated_at', 'created_at']; $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - $this->filter_fields = [$this->getModel()::PARENT, 'type', 'proxied']; + $this->filter_fields = [$this->getModel()::PARENT, 'plan', 'development_mode', 'ipv6', 'security_level']; $this->field_options = $this->getFormFieldOptions($this->filter_fields); + $this->batchjob_fields = ['development_mode', 'ipv6', 'security_level']; } //생성 public function create_form(): RedirectResponse|string { - $this->init('create'); + $this->init('create', [$this->getModel()::PARENT, 'domains', 'hosts', 'type', 'content', 'proxied']); + $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); + $this->filter_fields = [$this->getModel()::PARENT, 'type', 'proxied']; + $this->field_options = $this->getFormFieldOptions($this->filter_fields); + //부모데이터 정의 $parent_field = $this->getModel()::PARENT; $this->$parent_field = $this->request->getVar($parent_field) ?: DEFAULTS["EMPTY"]; return $this->create_form_procedure(); @@ -171,15 +175,15 @@ class ZoneController extends CloudflareController } protected function create_process_result(): RedirectResponse|string { - $this->fields = [$this->getModel()::PARENT, $this->getModel()::TITLE, 'name_servers', 'original_name_servers', 'development_mode', 'ipv6', 'security_level', 'status', 'updated_at', 'created_at']; - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - $this->filter_fields = [$this->getModel()::PARENT, 'development_mode', 'ipv6', 'security_level']; - $this->field_options = $this->getFormFieldOptions($this->filter_fields); + $this->init(__FUNCTION__); return $this->view_process_result(); } public function create(): RedirectResponse|string { - $this->init(__FUNCTION__); + $this->init(__FUNCTION__, [$this->getModel()::PARENT, 'domains', 'hosts', 'type', 'content', 'proxied']); + $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); + $this->filter_fields = [$this->getModel()::PARENT, 'type', 'proxied']; + $this->field_options = $this->getFormFieldOptions($this->filter_fields); return $this->create_procedure(); } //수정 (modify,toggle,batchjob사용) @@ -201,16 +205,7 @@ class ZoneController extends CloudflareController //일괄처리작업 public function batcjob(): RedirectResponse { - $this->action = __FUNCTION__; - //데이터가 있는경우 Field만 처리하기위해 - $fields = []; - foreach (['development_mode', 'ipv6', 'security_level'] as $field) { - if ($this->request->getVar($field)) { - $fields[$field] = $field; - } - } - $this->fields = $fields; - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); + $this->init(__FUNCTION__); return $this->batcjob_procedure(); } //View @@ -236,11 +231,7 @@ class ZoneController extends CloudflareController } public function view(string $uid): RedirectResponse|string { - $this->action = __FUNCTION__; - $this->fields = [$this->getModel()::PARENT, $this->getModel()::TITLE, 'name_servers', 'original_name_servers', 'plan', 'development_mode', 'ipv6', 'security_level', 'status', 'updated_at', 'created_at']; - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - $this->filter_fields = [$this->getModel()::PARENT, 'development_mode', 'ipv6', 'security_level']; - $this->field_options = $this->getFormFieldOptions($this->filter_fields); + $this->init(__FUNCTION__); return $this->view_procedure($uid); } //삭제 @@ -295,23 +286,13 @@ class ZoneController extends CloudflareController } public function index(): string { - $this->action = __FUNCTION__; - $this->fields = [$this->getModel()::PARENT, $this->getModel()::TITLE, 'name_servers', 'original_name_servers', 'plan', 'development_mode', 'ipv6', 'security_level', 'status', 'updated_at', 'created_at']; - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - $this->filter_fields = [$this->getModel()::PARENT, 'plan', 'development_mode', 'ipv6', 'security_level']; - $this->field_options = $this->getFormFieldOptions($this->filter_fields); - $this->batchjob_fields = ['development_mode', 'ipv6', 'security_level']; + $this->init(__FUNCTION__); return $this->list_procedure(); } // Download public function download(string $output_type, mixed $uid = false): DownloadResponse|string { - $this->action = __FUNCTION__; - $this->fields = [$this->getModel()::PARENT, $this->getModel()::TITLE, 'name_servers', 'original_name_servers', 'plan', 'development_mode', 'ipv6', 'security_level', 'status', 'updated_at', 'created_at']; - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - $this->filter_fields = [$this->getModel()::PARENT, 'plan', 'development_mode', 'ipv6', 'security_level']; - $this->field_options = $this->getFormFieldOptions($this->filter_fields); - $this->batchjob_fields = ['development_mode', 'ipv6', 'security_level']; + $this->init(__FUNCTION__); return $this->download_procedure($output_type, $uid); } //Sync작업 diff --git a/app/Controllers/Admin/MapurlController.php b/app/Controllers/Admin/MapurlController.php index f142260..a72995a 100644 --- a/app/Controllers/Admin/MapurlController.php +++ b/app/Controllers/Admin/MapurlController.php @@ -13,7 +13,6 @@ use Psr\Log\LoggerInterface; class MapurlController extends AdminController { - private $_model = null; public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { parent::initController($request, $response, $logger); @@ -24,36 +23,19 @@ class MapurlController extends AdminController } protected function getModel(): MapurlModel { - if ($this->_model === null) { - $this->_model = new MapurlModel(); + if ($this->model === null) { + $this->model = new MapurlModel(); } - return $this->_model; + return $this->model; } - protected function getFormFieldOption(string $field, array $options = []): array - { - switch ($field) { - default: - $options = parent::getFormFieldOption($field, $options); - break; - } - return $options; - } - protected function getFormData(string $field, array $formDatas): array - { - switch ($field) { - default: - $formDatas = parent::getFormData($field, $formDatas); - break; - } - return $formDatas; - } - private function init(string $action): void + private function init(string $action, array $fields = []): void { $this->action = $action; - $this->fields = [$this->getModel()::TITLE, 'newurl', 'status']; + $this->fields = count($fields) ? $fields : [$this->getModel()::TITLE, 'newurl', 'status', 'updated_at', 'created_at']; $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); $this->filter_fields = ['status']; $this->field_options = $this->getFormFieldOptions($this->filter_fields); + $this->batchjob_fields = ['status']; } private function remaping_process(): void { @@ -75,7 +57,7 @@ class MapurlController extends AdminController //생성 public function create_form(): RedirectResponse|string { - $this->init('create'); + $this->init('create', [$this->getModel()::TITLE, 'newurl', 'status']); return $this->create_form_procedure(); } protected function create_process(): void @@ -85,13 +67,13 @@ class MapurlController extends AdminController } public function create(): RedirectResponse|string { - $this->init(__FUNCTION__); + $this->init(__FUNCTION__, [$this->getModel()::TITLE, 'newurl', 'status']); return $this->create_procedure(); } //수정 public function modify_form(int $uid): RedirectResponse|string { - $this->init('modify'); + $this->init('modify', [$this->getModel()::TITLE, 'newurl', 'status']); return $this->modify_form_procedure($uid); } //(modify,toggle,batchjob사용) @@ -102,15 +84,13 @@ class MapurlController extends AdminController } public function modify(int $uid): RedirectResponse|string { - $this->init(__FUNCTION__); + $this->init(__FUNCTION__, [$this->getModel()::TITLE, 'newurl', 'status']); return $this->modify_procedure($uid); } //일괄처리작업 public function batcjob(): RedirectResponse { - $this->action = __FUNCTION__; - $this->fields = ['status']; - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); + $this->init(__FUNCTION__); return $this->batcjob_procedure(); } //View @@ -128,24 +108,14 @@ class MapurlController extends AdminController // 리스트 public function index(): string { - $this->action = __FUNCTION__; - $this->fields = [$this->getModel()::TITLE, 'newurl', 'status']; - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - $this->filter_fields = ['status']; - $this->field_options = $this->getFormFieldOptions($this->filter_fields); - $this->batchjob_fields = ['status']; + $this->init(__FUNCTION__); return $this->list_procedure(); } // Download public function download(string $output_type, mixed $uid = false): DownloadResponse|string { - $this->action = __FUNCTION__; - $this->fields = [$this->getModel()::TITLE, 'newurl', 'status']; - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - $this->filter_fields = ['status']; - $this->field_options = $this->getFormFieldOptions($this->filter_fields); - $this->batchjob_fields = ['status']; + $this->init(__FUNCTION__); return $this->download_procedure($output_type, $uid); } } diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php index 5b4769f..aff6068 100644 --- a/app/Controllers/Admin/UserController.php +++ b/app/Controllers/Admin/UserController.php @@ -14,7 +14,6 @@ use Psr\Log\LoggerInterface; class UserController extends AdminController { - private $_model = null; public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { parent::initController($request, $response, $logger); @@ -25,12 +24,12 @@ class UserController extends AdminController } protected function getModel(): UserModel { - if ($this->_model === null) { - $this->_model = new UserModel(); + if ($this->model === null) { + $this->model = new UserModel(); } - return $this->_model; + return $this->model; } - protected function setFormFieldRule($field, Validation $validation, string $action): Validation + protected function setValidationRule($field, Validation $validation, string $action): Validation { switch ($field) { case 'role': @@ -38,20 +37,11 @@ class UserController extends AdminController $validation->setRule($field . ".*", $field, $this->getModel()->getFieldRule($action, $field)); break; default: - $validation = parent::setFormFieldRule($field, $validation, $action); + $validation = parent::setValidationRule($field, $validation, $action); break; } return $validation; } - protected function getFormFieldOption(string $field, array $options = []): array - { - switch ($field) { - default: - $options = parent::getFormFieldOption($field, $options); - break; - } - return $options; - } protected function getFormData(string $field, array $formDatas): array { switch ($field) { @@ -80,42 +70,40 @@ class UserController extends AdminController } return $formDatas; } - private function init(string $action): void + private function init(string $action, array $fields = []): void { $this->action = $action; - $this->fields = ['id', 'passwd', 'confirmpassword', $this->getModel()::TITLE, 'email', 'mobile', 'role']; - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); + $this->fields = count($fields) ? $fields : ['id', $this->getModel()::TITLE, 'email', 'mobile', 'role', 'updated_at', 'created_at']; $this->filter_fields = ['role', 'status']; $this->field_options = $this->getFormFieldOptions($this->filter_fields); + $this->batchjob_fields = ['status']; } //생성 public function create_form(): RedirectResponse|string { - $this->init('create'); + $this->init('create', ['id', 'passwd', 'confirmpassword', $this->getModel()::TITLE, 'email', 'mobile', 'role']); return $this->create_form_procedure(); } public function create(): RedirectResponse|string { - $this->init(__FUNCTION__); + $this->init(__FUNCTION__, ['id', 'passwd', 'confirmpassword', $this->getModel()::TITLE, 'email', 'mobile', 'role']); return $this->create_procedure(); } //수정 public function modify_form(int $uid): RedirectResponse|string { - $this->init('modify'); + $this->init('modify', ['passwd', 'confirmpassword', $this->getModel()::TITLE, 'email', 'mobile', 'role']); return $this->modify_form_procedure($uid); } public function modify(int $uid): RedirectResponse|string { - $this->init(__FUNCTION__); + $this->init(__FUNCTION__, ['passwd', 'confirmpassword', $this->getModel()::TITLE, 'email', 'mobile', 'role']); return $this->modify_procedure($uid); } //일괄작업 public function batcjob(): RedirectResponse { - $this->action = __FUNCTION__; - $this->fields = ['status']; - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); + $this->init(__FUNCTION__); return $this->batcjob_procedure(); } //View @@ -127,23 +115,13 @@ class UserController extends AdminController // 리스트 public function index(): string { - $this->action = __FUNCTION__; - $this->fields = ['id', $this->getModel()::TITLE, 'email', 'mobile', 'role', 'status']; - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - $this->filter_fields = ['role', 'status']; - $this->field_options = $this->getFormFieldOptions($this->filter_fields); - $this->batchjob_fields = ['status']; + $this->init(__FUNCTION__); return $this->list_procedure(); } // Download public function download(string $output_type, mixed $uid = false): DownloadResponse|string { - $this->action = __FUNCTION__; - $this->fields = ['id', $this->getModel()::TITLE, 'email', 'mobile', 'role', 'status']; - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - $this->filter_fields = ['role', 'status']; - $this->field_options = $this->getFormFieldOptions($this->filter_fields); - $this->batchjob_fields = ['status']; + $this->init(__FUNCTION__); return $this->download_procedure($output_type, $uid); } } diff --git a/app/Controllers/Admin/UserSNSController.php b/app/Controllers/Admin/UserSNSController.php index 477dd40..37321d3 100644 --- a/app/Controllers/Admin/UserSNSController.php +++ b/app/Controllers/Admin/UserSNSController.php @@ -15,7 +15,6 @@ use Psr\Log\LoggerInterface; class UserSNSController extends AdminController { - private $_model = null; public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { parent::initController($request, $response, $logger); @@ -26,19 +25,10 @@ class UserSNSController extends AdminController } protected function getModel(): UserSNSModel { - if ($this->_model === null) { - $this->_model = new UserSNSModel(); + if ($this->model === null) { + $this->model = new UserSNSModel(); } - return $this->_model; - } - protected function setFormFieldRule($field, Validation $validation, string $action): Validation - { - switch ($field) { - default: - $validation = parent::setFormFieldRule($field, $validation, $action); - break; - } - return $validation; + return $this->model; } protected function getFormFieldOption(string $field, array $options = []): array { @@ -56,62 +46,42 @@ class UserSNSController extends AdminController } return $options; } - protected function getFormData(string $field, array $formDatas): array - { - switch ($field) { - default: - $formDatas = parent::getFormData($field, $formDatas); - break; - } - return $formDatas; - } - private function init(string $action): void + private function init(string $action, array $fields = []): void { $this->action = $action; - $this->fields = [$this->getModel()::PARENT, 'site', 'id', $this->getModel()::TITLE, 'email']; + $this->fields = count($fields) ? $fields : [$this->getModel()::PARENT, 'site', 'id', $this->getModel()::TITLE, 'email', 'updated_at', 'created_at']; $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); $this->filter_fields = [$this->getModel()::PARENT, 'status']; $this->field_options = $this->getFormFieldOptions($this->filter_fields); + $this->batchjob_fields = []; } //수정 public function modify_form(int $uid): RedirectResponse|string { - $this->init('modify'); + $this->init('modify', [$this->getModel()::PARENT, 'site', 'id', $this->getModel()::TITLE, 'email']); return $this->modify_form_procedure($uid); } public function modify(int $uid): RedirectResponse|string { - $this->init(__FUNCTION__); + $this->init(__FUNCTION__, [$this->getModel()::PARENT, 'site', 'id', $this->getModel()::TITLE, 'email']); return $this->modify_procedure($uid); } //일괄작업 public function batcjob(): RedirectResponse { - $this->action = __FUNCTION__; - $this->fields = ['status']; - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); + $this->init(__FUNCTION__); return $this->batcjob_procedure(); } // 리스트 public function index(): string { - $this->action = __FUNCTION__; - $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 = [$this->getModel()::PARENT, 'status']; - $this->field_options = $this->getFormFieldOptions($this->filter_fields); - $this->batchjob_fields = []; + $this->init(__FUNCTION__); return $this->list_procedure(); } // Download public function download(string $output_type, mixed $uid = false): DownloadResponse|string { - $this->action = __FUNCTION__; - $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 = [$this->getModel()::PARENT, 'status']; - $this->field_options = $this->getFormFieldOptions($this->filter_fields); - $this->batchjob_fields = []; + $this->init(__FUNCTION__); return $this->download_procedure($output_type, $uid); } } diff --git a/app/Controllers/MVController.php b/app/Controllers/MVController.php index 8eeb4d2..f7034a5 100644 --- a/app/Controllers/MVController.php +++ b/app/Controllers/MVController.php @@ -21,7 +21,7 @@ abstract class MVController extends CommonController } abstract protected function getModel(): mixed; //Field별 Form Rule용 - protected function setFormFieldRule($field, Validation $validation, string $action): Validation + protected function setValidationRule($field, Validation $validation, string $action): Validation { switch ($field) { default: @@ -30,10 +30,10 @@ abstract class MVController extends CommonController } return $validation; } - final protected function setFormFieldRules(array $fields, Validation $validation, string $action): Validation + final protected function getValidation(array $fields, Validation $validation, string $action): Validation { foreach ($fields as $field) { - $validation = $this->setFormFieldRule($field, $validation, $action); + $validation = $this->setValidationRule($field, $validation, $action); } return $validation; } @@ -96,11 +96,11 @@ abstract class MVController extends CommonController protected function create_validate(string $action, array $fields): void { //변경할 값 확인 : Upload된 파일 검증시 $this->request->getPOST()보다 먼처 체크필요 - $this->validation = $this->setFormFieldRules($fields, service('validation'), $action); - if (!$this->validation->withRequest($this->request)->run()) { + $validation = $this->getValidation($fields, service('validation'), $action); + if (!$validation->withRequest($this->request)->run()) { throw new \Exception("{$this->class_name} 작업 데이터 검증 오류발생\n" . implode( "\n", - $this->validation->getErrors() + $validation->getErrors() )); } } @@ -112,7 +112,7 @@ abstract class MVController extends CommonController } protected function create_process_result(): RedirectResponse|string { - $url = strtolower(base_url() . $this->uri_path . "/" . $this->class_path . "/view/" . $this->entity->getPK()); + $url = strtolower(base_url() . $this->uri_path . $this->class_name) . "/view/" . $this->entity->getPK(); return redirect()->to($url)->with('error', $this->message); } final protected function create_procedure(): RedirectResponse|string @@ -156,14 +156,14 @@ abstract class MVController extends CommonController return redirect()->back()->with('error', $e->getMessage()); } } - protected function modify_validate(string $action, array $fields): void + final protected function modify_validate(string $action, array $fields): void { //변경할 값 확인 : Upload된 파일 검증시 $this->request->getVar()보다 먼처 체크필요 - $this->validation = $this->setFormFieldRules($fields, service('validation'), $action); - if (!$this->validation->withRequest($this->request)->run()) { + $validation = $this->getValidation($fields, service('validation'), $action); + if (!$validation->withRequest($this->request)->run()) { throw new \Exception("{$this->class_name} 작업 데이터 검증 오류발생\n" . implode( "\n", - $this->validation->getErrors() + $validation->getErrors() )); } } @@ -180,7 +180,7 @@ abstract class MVController extends CommonController } protected function modify_process_result(): RedirectResponse|string { - $url = strtolower(base_url() . $this->uri_path . "/" . $this->class_path . "/view/" . $this->entity->getPK()); + $url = strtolower(base_url() . $this->uri_path . $this->class_name) . "/view/" . $this->entity->getPK(); return redirect()->to($url)->with('error', $this->message); } final protected function modify_procedure(mixed $uid): RedirectResponse|string @@ -207,6 +207,14 @@ abstract class MVController extends CommonController //Transaction Start $this->getModel()->transStart(); try { + //데이터가 있는경우 Field만 처리하기위해 + $fields = []; + foreach ($this->batchjob_fields as $field) { + if ($this->request->getVar($field)) { + $fields[$field] = $field; + } + } + $this->fields = $fields; //변경할 UIDS $uids = $this->request->getVar('batchjob_uids'); if (!$uids) { diff --git a/app/Controllers/UserController.php b/app/Controllers/UserController.php index 26c0ad3..b088443 100644 --- a/app/Controllers/UserController.php +++ b/app/Controllers/UserController.php @@ -11,12 +11,10 @@ use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; -use CodeIgniter\Validation\Validation; use Psr\Log\LoggerInterface; class UserController extends FrontController { - private $_model = null; public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { parent::initController($request, $response, $logger); @@ -27,61 +25,21 @@ class UserController extends FrontController } protected function getModel(): UserModel { - if ($this->_model === null) { - $this->_model = new UserModel(); + if ($this->model === null) { + $this->model = new UserModel(); } - return $this->_model; + return $this->model; } - protected function setFormFieldRule($field, Validation $validation, string $action): Validation - { - switch ($field) { - case 'role': - //아래 Rule Array는 필드명.* checkbox를 사용 - $validation->setRule($field . ".*", $field, $this->getModel()->getFieldRule($action, $field)); - break; - default: - $validation = parent::setFormFieldRule($field, $validation, $action); - break; - } - return $validation; - } - protected function getFormFieldOption(string $field, array $options = []): array - { - switch ($field) { - default: - $options = parent::getFormFieldOption($field, $options); - break; - } - return $options; - } - protected function getFormData(string $field, array $formDatas): array - { - switch ($field) { - case 'role': - $roles = $this->request->getVar($field) ?? []; - if (!count($roles)) { - throw new \Exception("권한이 지정되지 않았습니다."); - } - $formDatas[$field] = implode(DEFAULTS["DELIMITER_ROLE"], $roles); - break; - default: - $formDatas = parent::getFormData($field, $formDatas); - break; - } - return $formDatas; - } - - private function init(string $action): void + private function init(string $action, array $fields = []): void { $this->action = $action; - $this->fields = ['id', 'passwd']; - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); + $this->fields = count($fields) ? $fields : ['id', 'passwd']; } //로그인화면 public function login_form(): RedirectResponse|string { - $this->init('login'); try { + $this->init('login'); helper(['form']); //구글 로그인 BUTTON용 $google_socket = new GoogleSocket(); @@ -99,8 +57,8 @@ class UserController extends FrontController //로그인처리 public function login(): RedirectResponse|string { - $this->init('login'); try { + $this->init('login'); $this->create_validate($this->action, $this->fields); $this->formDatas = $this->getFormDatas(); $auth = new LocalAuth(); @@ -116,7 +74,6 @@ class UserController extends FrontController } public function google_login(): RedirectResponse|string { - $this->init('login'); try { $access_code = $this->request->getVar('code'); if (!$access_code) { diff --git a/app/Helpers/Cloudflare/AccountHelper.php b/app/Helpers/Cloudflare/AccountHelper.php index 6902fc2..9a529dd 100644 --- a/app/Helpers/Cloudflare/AccountHelper.php +++ b/app/Helpers/Cloudflare/AccountHelper.php @@ -2,10 +2,10 @@ namespace App\Helpers\Cloudflare; -use App\Helpers\CommonHelper; +use App\Helpers\MVCHelper; use App\Models\Cloudflare\AccountModel; -class AccountHelper extends CommonHelper +class AccountHelper extends MVCHelper { public $old_parent = ""; public function __construct() @@ -14,6 +14,9 @@ class AccountHelper extends CommonHelper } public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string { + if (in_array($viewDatas['action'], ['create', 'modify'])) { + $extras = (strpos($viewDatas['model']->getFieldRule($viewDatas['action'], $field), 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras]; + } $value = $value ?: DEFAULTS['EMPTY']; switch ($field) { case AccountModel::PARENT: @@ -77,7 +80,7 @@ class AccountHelper extends CommonHelper "class" => "btn btn-sm btn-primary btn-circle", "target" => "_self", ] - ) . " {$value}"; + ) . " " . parent::getFieldView($field, $viewDatas, $extras); break; case 'type': case 'status': diff --git a/app/Helpers/Cloudflare/AuthHelper.php b/app/Helpers/Cloudflare/AuthHelper.php index d3a92c7..1e667b7 100644 --- a/app/Helpers/Cloudflare/AuthHelper.php +++ b/app/Helpers/Cloudflare/AuthHelper.php @@ -2,10 +2,10 @@ namespace App\Helpers\Cloudflare; -use App\Helpers\CommonHelper; +use App\Helpers\MVCHelper; use App\Models\Cloudflare\AuthModel; -class AuthHelper extends CommonHelper +class AuthHelper extends MVCHelper { public function __construct() { @@ -13,6 +13,9 @@ class AuthHelper extends CommonHelper } public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string { + if (in_array($viewDatas['action'], ['create', 'modify'])) { + $extras = (strpos($viewDatas['model']->getFieldRule($viewDatas['action'], $field), 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras]; + } $value = $value ?: DEFAULTS['EMPTY']; switch ($field) { case AuthModel::TITLE: @@ -44,7 +47,7 @@ class AuthHelper extends CommonHelper "class" => "btn btn-sm btn-primary btn-circle", "target" => "_self" ] - ) . " {$value}"; + ) . " " . parent::getFieldView($field, $viewDatas, $extras); break; default: $value = parent::getFieldView($field, $viewDatas, $extras); diff --git a/app/Helpers/Cloudflare/RecordHelper.php b/app/Helpers/Cloudflare/RecordHelper.php index 412e8e2..03dfd9e 100644 --- a/app/Helpers/Cloudflare/RecordHelper.php +++ b/app/Helpers/Cloudflare/RecordHelper.php @@ -2,10 +2,10 @@ namespace App\Helpers\Cloudflare; -use App\Helpers\CommonHelper; +use App\Helpers\MVCHelper; use App\Models\Cloudflare\RecordModel; -class RecordHelper extends CommonHelper +class RecordHelper extends MVCHelper { public $old_parent = ""; public function __construct() @@ -27,6 +27,9 @@ class RecordHelper extends CommonHelper } public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string { + if (in_array($viewDatas['action'], ['create', 'modify'])) { + $extras = (strpos($viewDatas['model']->getFieldRule($viewDatas['action'], $field), 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras]; + } $value = $value ?: DEFAULTS['EMPTY']; switch ($field) { case RecordModel::PARENT: @@ -80,15 +83,22 @@ class RecordHelper extends CommonHelper "class" => "btn btn-sm btn-primary btn-circle", "target" => "_self", ] - ) . " " . "{$viewDatas['field_options'][$field][$value]}"; + ) . " " . form_label( + $viewDatas['field_options'][$field][$value], + 'label_zones', + $extras + ); } $this->old_parent = $viewDatas['entity']->getParent(); break; case RecordModel::TITLE: - $url = sprintf("%s/toggle/%s/fixed?fixed=%s", current_url(), $viewDatas['entity']->getPK(), $viewDatas['entity']->fixed == 'on' ? "off" : "on"); - $fixed = $viewDatas['entity']->fixed == 'on' ? "" . ICONS['LOCK'] . "" : ""; - $value = sprintf("%s%s", $fixed, $value); - $value = anchor($url, $value, ["target" => "_self"]); + $value = parent::getFieldView($field, $viewDatas, ['class' => "label_hosts", ...$extras]); + $fixed = anchor( + sprintf("%s/toggle/%s/fixed?fixed=%s", current_url(), $viewDatas['entity']->getPK(), $viewDatas['entity']->fixed == 'on' ? "off" : "on"), + $viewDatas['entity']->fixed == 'on' ? "" . ICONS['LOCK'] . "" : ICONS['UNLOCK'], + ["class" => "ext-danger", "style" => "float:right;", ...$extras] + ); + $value = $fixed . " " . $value; break; case 'content': // 값이 40자 이상인 경우 자르고 '...' 추가 diff --git a/app/Helpers/Cloudflare/ZoneHelper.php b/app/Helpers/Cloudflare/ZoneHelper.php index dcf6479..3c14750 100644 --- a/app/Helpers/Cloudflare/ZoneHelper.php +++ b/app/Helpers/Cloudflare/ZoneHelper.php @@ -2,10 +2,10 @@ namespace App\Helpers\Cloudflare; -use App\Helpers\CommonHelper; +use App\Helpers\MVCHelper; use App\Models\Cloudflare\ZoneModel; -class ZoneHelper extends CommonHelper +class ZoneHelper extends MVCHelper { public $old_parent = ""; public function __construct() @@ -14,6 +14,9 @@ class ZoneHelper extends CommonHelper } function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string { + if (in_array($viewDatas['action'], ['create', 'modify'])) { + $extras = (strpos($viewDatas['model']->getFieldRule($viewDatas['action'], $field), 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras]; + } $value = $value ?: DEFAULTS['EMPTY']; switch ($field) { case ZoneModel::PARENT: @@ -98,7 +101,7 @@ class ZoneHelper extends CommonHelper "class" => "btn btn-sm btn-primary btn-circle", "target" => "_self" ] - ) . " {$value}"; + ) . " " . parent::getFieldView($field, $viewDatas, ['class' => "label_zones", ...$extras]); break; case 'name_servers': case 'original_name_servers': diff --git a/app/Helpers/CommonHelper.php b/app/Helpers/CommonHelper.php index 6454964..6d39477 100644 --- a/app/Helpers/CommonHelper.php +++ b/app/Helpers/CommonHelper.php @@ -128,154 +128,4 @@ class CommonHelper } return ""; } // - - public function getFieldLabel(string $field, array $viewDatas, array $extras = []): string - { - switch ($field) { - default: - if (strpos($viewDatas['field_rules'][$field], 'required') !== false) { - $extras = ["class" => "text-danger ", ...$extras]; - } - $label = form_label(lang("{$viewDatas['class_path']}.label.{$field}"), $field, $extras); - break; - } - return $label; - } - //header.php에서 getFieldForm_Helper사용 - public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string - { - $value = $value ?: DEFAULTS['EMPTY']; - switch ($field) { - case 'status': - $form = form_dropdown($field, [ - "" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택', - ] + $viewDatas['field_options'][$field], $value, $extras); - break; - case 'updated_at': - case 'created_at': - $extra_class = isset($extras['class']) ? $extras['class'] . ' calender' : 'calender'; - $form = form_input($field, $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]); - break; - default: - $form = form_input($field, $value, ["autocomplete" => $field, ...$extras]); - break; - } - return $form; - } // - public function getFieldView(string $field, array $viewDatas, array $extras = []): string - { - $value = $viewDatas['entity']->$field ?: DEFAULTS['EMPTY']; - switch ($field) { - case 'category_uid': - foreach (array_values($viewDatas['field_options'][$field]) as $category_2depths) { - foreach ($category_2depths as $key => $depth) { - if ($key == $depth) { - $value = $depth; - } - } - } - break; - case 'updated_at': - case 'created_at': - $value = $value ? date("Y-m-d", strtotime($value)) : ""; - break; - default: - if (in_array($field, $viewDatas['filter_fields'])) { - $extras["onChange"] = sprintf( - 'location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', - current_url(), - $viewDatas['entity']->getPK(), - $field, - $field - ); - $value = $this->getFieldForm($field, $viewDatas['entity']->$field, $viewDatas, $extras); - } - break; - } - return $value; - } // - public function getListRowColor($entity): string - { - return $entity->status != DEFAULTS['STATUS'] ? 'class="table-danger"' : ""; - } - public function getListLabel(string $field, array $viewDatas, array $extras = []): string - { - switch ($field) { - default: - $label = $this->getFieldLabel($field, $viewDatas, $extras); - if (isset($viewDatas['order_field']) && $viewDatas['order_field'] == $field) { - $label .= $viewDatas['order_value'] == 'ASC' ? ICONS["UP"] : ICONS["DOWN"]; - } - $query = $viewDatas['uri']->getQuery(['except' => ['order_field', 'order_value']]); - $query .= empty($query) ? "" : "&"; - $query .= "order_field={$field}&order_value="; - $query .= isset($viewDatas['order_value']) && $viewDatas['order_value'] == 'DESC' ? "ASC" : "DESC"; - $label = anchor(current_url() . "?" . $query, $label); - break; - } - return $label; - } - public function getListButton(string $action, array $viewDatas, array $extras = []): string - { - switch ($action) { - case 'create': - $extras = ["class" => "btn btn-outline btn-primary btn-circle", "target" => "_self", ...$extras]; - $action = form_label( - '입력', - $action, - [ - "data-src" => current_url() . '/' . $action, - "data-bs-toggle" => "modal", - "data-bs-target" => "#index_action_form", - ...$extras - ] - ); - break; - case 'modify': - $pk = $viewDatas['entity']->getPK(); - $oldBatchJobUids = old("batchjob_uids", null); - $oldBatchJobUids = is_array($oldBatchJobUids) ? $oldBatchJobUids : [$oldBatchJobUids]; - $checkbox = form_checkbox([ - "id" => "checkbox_uid_{$pk}", - "name" => "batchjob_uids[]", - "value" => $pk, - "class" => "batchjobuids_checkboxs", - "checked" => in_array($pk, $oldBatchJobUids) - ]); - $action = $checkbox . form_label( - $viewDatas['cnt'], - $action, - [ - "data-src" => current_url() . '/' . $action . '/' . $viewDatas['entity']->getPK(), - "data-bs-toggle" => "modal", - "data-bs-target" => "#index_action_form", - ...$extras - ] - ); - break; - case 'delete': - $extras = ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self", ...$extras]; - $action = anchor( - current_url() . '/' . $action . '/' . $viewDatas['entity']->getPK(), - ICONS['DELETE'], - $extras - ); - break; - case 'batchjob': - $action = form_submit("batchjob_submit", '일괄처리', [ - "formaction" => current_url() . '/batchjob', - "class" => "btn btn-outline btn-warning", - "onclick" => "return submitBatchJob()" - ]); - break; - case 'batchjob_delete': - $action = form_submit("batchjob_submit", '일괄삭제', [ - "formaction" => current_url() . '/batchjob_delete', - "class" => "btn btn-outline btn-danger", - "onclick" => "return submitBatchJobDelete()" - ]); - break; - } - return $action; - } } diff --git a/app/Helpers/MVCHelper.php b/app/Helpers/MVCHelper.php new file mode 100644 index 0000000..f34ca71 --- /dev/null +++ b/app/Helpers/MVCHelper.php @@ -0,0 +1,176 @@ +getFieldRule($viewDatas['action'], $field), 'required') !== false) { + $extras = ["class" => "text-danger ", ...$extras]; + } + $label = form_label(lang("{$viewDatas['class_path']}.label.{$field}"), $field, $extras); + break; + } + return $label; + } + //header.php에서 getFieldForm_Helper사용 + public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string + { + if (in_array($viewDatas['action'], ['create', 'modify'])) { + $extras = (strpos($viewDatas['model']->getFieldRule($viewDatas['action'], $field), 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras]; + } + $value = $value ?: DEFAULTS['EMPTY']; + switch ($field) { + case 'status': + $form = form_dropdown($field, [ + "" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택', + ] + $viewDatas['field_options'][$field], $value, $extras); + break; + case 'updated_at': + case 'created_at': + $extra_class = isset($extras['class']) ? $extras['class'] . ' calender' : 'calender'; + $form = form_input($field, $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]); + break; + default: + $form = form_input($field, $value, ["autocomplete" => $field, ...$extras]); + break; + } + return $form; + } // + public function getFieldView(string $field, array $viewDatas, array $extras = []): string + { + $value = $viewDatas['entity']->$field ?: DEFAULTS['EMPTY']; + switch ($field) { + case $viewDatas['model']::TITLE: + $value = form_label( + $value, + 'view', + [ + "data-src" => current_url() . '/view/' . $viewDatas['entity']->getPK(), + "data-bs-toggle" => "modal", + "data-bs-target" => "#index_action_form", + "style" => "color: blue; cursor: pointer; font-weight:bold;", + ...$extras, + ] + ); + break; + case 'category_uid': + foreach (array_values($viewDatas['field_options'][$field]) as $category_2depths) { + foreach ($category_2depths as $key => $depth) { + if ($key == $depth) { + $value = $depth; + } + } + } + break; + case 'updated_at': + case 'created_at': + $value = $value ? date("Y-m-d", strtotime($value)) : ""; + break; + default: + if (in_array($field, $viewDatas['filter_fields'])) { + $extras["onChange"] = sprintf( + 'location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', + current_url(), + $viewDatas['entity']->getPK(), + $field, + $field + ); + $value = $this->getFieldForm($field, $viewDatas['entity']->$field, $viewDatas, $extras); + } + break; + } + return $value; + } // + public function getListRowColor($entity): string + { + return $entity->status != DEFAULTS['STATUS'] ? 'class="table-danger"' : ""; + } + public function getListLabel(string $field, array $viewDatas, array $extras = []): string + { + switch ($field) { + default: + $label = $this->getFieldLabel($field, $viewDatas, $extras); + if (isset($viewDatas['order_field']) && $viewDatas['order_field'] == $field) { + $label .= $viewDatas['order_value'] == 'ASC' ? ICONS["UP"] : ICONS["DOWN"]; + } + $query = $viewDatas['uri']->getQuery(['except' => ['order_field', 'order_value']]); + $query .= empty($query) ? "" : "&"; + $query .= "order_field={$field}&order_value="; + $query .= isset($viewDatas['order_value']) && $viewDatas['order_value'] == 'DESC' ? "ASC" : "DESC"; + $label = anchor(current_url() . "?" . $query, $label); + break; + } + return $label; + } + public function getListButton(string $action, array $viewDatas, array $extras = []): string + { + switch ($action) { + case 'create': + $extras = ["class" => "btn btn-outline btn-primary btn-circle", "target" => "_self", ...$extras]; + $action = form_label( + '입력', + $action, + [ + "data-src" => current_url() . '/' . $action, + "data-bs-toggle" => "modal", + "data-bs-target" => "#index_action_form", + ...$extras + ] + ); + break; + case 'modify': + $pk = $viewDatas['entity']->getPK(); + $oldBatchJobUids = old("batchjob_uids", null); + $oldBatchJobUids = is_array($oldBatchJobUids) ? $oldBatchJobUids : [$oldBatchJobUids]; + $checkbox = form_checkbox([ + "id" => "checkbox_uid_{$pk}", + "name" => "batchjob_uids[]", + "value" => $pk, + "class" => "batchjobuids_checkboxs", + "checked" => in_array($pk, $oldBatchJobUids) + ]); + $action = $checkbox . form_label( + $viewDatas['cnt'], + $action, + [ + "data-src" => current_url() . '/' . $action . '/' . $viewDatas['entity']->getPK(), + "data-bs-toggle" => "modal", + "data-bs-target" => "#index_action_form", + ...$extras + ] + ); + break; + case 'delete': + $extras = ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self", ...$extras]; + $action = anchor( + current_url() . '/' . $action . '/' . $viewDatas['entity']->getPK(), + ICONS['DELETE'], + $extras + ); + break; + case 'batchjob': + $action = form_submit("batchjob_submit", '일괄처리', [ + "formaction" => current_url() . '/batchjob', + "class" => "btn btn-outline btn-warning", + "onclick" => "return submitBatchJob()" + ]); + break; + case 'batchjob_delete': + $action = form_submit("batchjob_submit", '일괄삭제', [ + "formaction" => current_url() . '/batchjob_delete', + "class" => "btn btn-outline btn-danger", + "onclick" => "return submitBatchJobDelete()" + ]); + break; + } + return $action; + } +} diff --git a/app/Helpers/MapurlHelper.php b/app/Helpers/MapurlHelper.php index 2a8785e..a4f317d 100644 --- a/app/Helpers/MapurlHelper.php +++ b/app/Helpers/MapurlHelper.php @@ -4,7 +4,7 @@ namespace App\Helpers; use App\Models\MapurlModel; -class MapurlHelper extends CommonHelper +class MapurlHelper extends MVCHelper { public function __construct() { @@ -12,6 +12,9 @@ class MapurlHelper extends CommonHelper } public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string { + if (in_array($viewDatas['action'], ['create', 'modify'])) { + $extras = (strpos($viewDatas['model']->getFieldRule($viewDatas['action'], $field), 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras]; + } $value = $value ?: DEFAULTS['EMPTY']; switch ($field) { case MapurlModel::TITLE: diff --git a/app/Helpers/UserHelper.php b/app/Helpers/UserHelper.php index 3f70ba5..6803cdf 100644 --- a/app/Helpers/UserHelper.php +++ b/app/Helpers/UserHelper.php @@ -4,7 +4,7 @@ namespace App\Helpers; use App\Models\UserModel; -class UserHelper extends CommonHelper +class UserHelper extends MVCHelper { public function __construct() { @@ -12,6 +12,9 @@ class UserHelper extends CommonHelper } public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string { + if (in_array($viewDatas['action'], ['create', 'modify'])) { + $extras = (strpos($viewDatas['model']->getFieldRule($viewDatas['action'], $field), 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras]; + } $value = $value ?: DEFAULTS['EMPTY']; switch ($field) { case 'id': diff --git a/app/Helpers/UserSNSHelper.php b/app/Helpers/UserSNSHelper.php index 96d1377..1a1bd5b 100644 --- a/app/Helpers/UserSNSHelper.php +++ b/app/Helpers/UserSNSHelper.php @@ -4,7 +4,7 @@ namespace App\Helpers; use App\Models\UserSNSModel; -class UserSNSHelper extends CommonHelper +class UserSNSHelper extends MVCHelper { public function __construct() { @@ -12,6 +12,9 @@ class UserSNSHelper extends CommonHelper } public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string { + if (in_array($viewDatas['action'], ['create', 'modify'])) { + $extras = (strpos($viewDatas['model']->getFieldRule($viewDatas['action'], $field), 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras]; + } $value = $value ?: DEFAULTS['EMPTY']; switch ($field) { case UserSNSModel::PARENT: diff --git a/app/Views/admin/create.php b/app/Views/admin/create.php index 81c825d..f567529 100644 --- a/app/Views/admin/create.php +++ b/app/Views/admin/create.php @@ -10,8 +10,7 @@
| 번호 | -= $viewDatas['helper']->getListLabel($field, $viewDatas) ?> - | += $viewDatas['helper']->getListLabel($field, $viewDatas) ?> | 작업 | |
|---|---|---|---|---|
| - = $viewDatas['helper']->getListButton('modify', $viewDatas) ?> - | += $viewDatas['helper']->getListButton('modify', $viewDatas) ?> | = $viewDatas['helper']->getFieldView($field, $viewDatas) ?> | -- = $viewDatas['helper']->getListButton('delete', $viewDatas) ?> - | += $viewDatas['helper']->getListButton('delete', $viewDatas) ?> |