diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 4d8c6f4..4e9626e 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -21,6 +21,7 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin'], function ($rou $routes->group('cloudflare', ['namespace' => 'App\Controllers\Admin\Cloudflare'], function ($routes) { $routes->group('account', function ($routes) { $routes->get('/', 'AccountController::index'); + $routes->get('create', 'AccountController::create_form'); $routes->post('create', 'AccountController::create'); }); $routes->group('zone', function ($routes) { diff --git a/app/Controllers/Admin/Cloudflare/AccountController.php b/app/Controllers/Admin/Cloudflare/AccountController.php index ce64453..8edd235 100644 --- a/app/Controllers/Admin/Cloudflare/AccountController.php +++ b/app/Controllers/Admin/Cloudflare/AccountController.php @@ -2,16 +2,17 @@ namespace App\Controllers\Admin\Cloudflare; -use Psr\Log\LoggerInterface; -use CodeIgniter\HTTP\ResponseInterface; -use CodeIgniter\HTTP\RequestInterface; -use CodeIgniter\HTTP\RedirectResponse; - use App\Libraries\MyCloudflare\Account; +use App\Models\Cloudflare\AccountModel; +use CodeIgniter\HTTP\RedirectResponse; +use CodeIgniter\HTTP\RequestInterface; +use CodeIgniter\HTTP\ResponseInterface; +use Psr\Log\LoggerInterface; class AccountController extends CloudflareController { private $_myLibrary = null; + private $_model = null; public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { parent::initController($request, $response, $logger); @@ -20,6 +21,13 @@ class AccountController extends CloudflareController $this->title = lang("{$this->class_path}.title"); helper($this->class_path); } + final protected function getModel(): AccountModel + { + if ($this->_model === null) { + $this->_model = new AccountModel(); + } + return $this->_model; + } final protected function getMyLibrary(): Account { if ($this->_myLibrary === null) { @@ -27,44 +35,30 @@ class AccountController extends CloudflareController } return $this->_myLibrary; } + //생성 protected function create_init(): void { $this->action = 'create'; - $this->fields = [$this->getMyLibrary()->getMyStorage()::TITLE, 'authkey', 'type', 'status']; - $this->filter_fields = ['type', 'status']; + $this->fields = ['id', 'authkey']; + $this->filter_fields = []; $this->field_rules = $this->getFormFieldRules(); $this->field_options = $this->getFormFieldOptions(); - $this->getMyLibrary()->getMyStorage()->setAction($this->action); + $this->getModel()->setAction($this->action); } - // public function create_form(): RedirectResponse|string - // { - // $this->create_init(); - // return $this->create_form_process(); - // } - protected function create_process_submit(): void + protected function create_process(): void { - $entity = $this->getMyLibrary()->create($this->formDatas); + parent::create_process(); + $this->getMyLibrary()->create($this->formDatas); } - public function create(): RedirectResponse - { - $this->create_init(); - $this->formDatas = []; - $this->getFormDatas(); - $this->convertFormDatas(); - $this->validateFormDatas(); - return parent::create_process(); - } - public function index(): string + // 리스트 + public function list_init(): void { $this->action = 'index'; - $this->fields = [$this->getMyLibrary()->getMyStorage()::TITLE, 'oldkey', 'type', 'status', 'updated_at', 'created_at']; + $this->fields = [$this->getModel()::TITLE, 'oldkey', 'type', 'status', 'updated_at', 'created_at']; $this->filter_fields = ['type', 'status']; $this->batchjob_fields = ['status']; $this->field_rules = $this->getFormFieldRules(); $this->field_options = $this->getFormFieldOptions(); - $this->getMyLibrary()->getMyStorage()->setAction($this->action); - helper(['form']); - $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; - return parent::list_process(); + $this->getModel()->setAction($this->action); } } diff --git a/app/Controllers/Admin/Cloudflare/RecordController.php b/app/Controllers/Admin/Cloudflare/RecordController.php index d02347b..aa9c98d 100644 --- a/app/Controllers/Admin/Cloudflare/RecordController.php +++ b/app/Controllers/Admin/Cloudflare/RecordController.php @@ -2,12 +2,12 @@ namespace App\Controllers\Admin\Cloudflare; -use Psr\Log\LoggerInterface; -use CodeIgniter\HTTP\ResponseInterface; -use CodeIgniter\HTTP\RequestInterface; -use CodeIgniter\HTTP\RedirectResponse; - use App\Libraries\MyCloudflare\Record; +use App\Models\Cloudflare\RecordModel; +use CodeIgniter\HTTP\RedirectResponse; +use CodeIgniter\HTTP\RequestInterface; +use CodeIgniter\HTTP\ResponseInterface; +use Psr\Log\LoggerInterface; class RecordController extends CloudflareController { @@ -22,6 +22,13 @@ class RecordController extends CloudflareController $this->title = lang("{$this->class_path}.title"); helper($this->class_name); } + final protected function getModel(): RecordModel + { + if ($this->_model === null) { + $this->_model = new RecordModel(); + } + return $this->_model; + } final protected function getMyLibrary(): Record { if ($this->_myLibrary === null) { @@ -32,7 +39,7 @@ class RecordController extends CloudflareController protected function getFormFieldOption(string $field, array $options = []): array { switch ($field) { - case $this->getMyLibrary()->getMyStorage()::PARENT: + case $this->getModel()::PARENT: $this->getZoneModel()->where('status', DEFAULTS['STATUS']); $options[$field] = [ DEFAULTS['EMPTY'] => lang($this->_className . '.label.' . $field) . ' 선택', @@ -46,59 +53,56 @@ class RecordController extends CloudflareController return $options; } //전송된 데이터 - protected function getFormData(string $field): void + protected function getFormData(string $field, array $formDatas): array { switch ($field) { case 'hosts': - $this->formDatas[$field] = explode("\n", $this->request->getVar($field)); + $formDatas[$field] = explode("\n", $this->request->getVar($field)); if (!is_array($this->formDatas[$field]) || !count($this->formDatas[$field])) { throw new \Exception("호스트명이 정의되지 않았습니다."); } break; default: - $this->formDatas[$field] = $this->request->getVar($field); - break; - } - } - //전송된 데이터 검증 - protected function validateFormData(string $field): void - { - switch ($field) { - case 'hosts': - break; - default: - parent::validateFormData($field); + $formDatas = parent::getFormData($field, $formDatas); break; } + return $formDatas; } protected function create_init(): void { $this->action = 'create'; - $this->fields = [$this->getMyLibrary()->getMyStorage()::PARENT, 'type', 'content', 'proxied', 'hosts']; - $this->filter_fields = [$this->getMyLibrary()->getMyStorage()::PARENT, 'type', 'proxied']; + $this->fields = [$this->getModel()::PARENT, 'type', 'content', 'proxied', 'hosts']; + $this->filter_fields = [$this->getModel()::PARENT, 'type', 'proxied']; $this->field_rules = $this->getFormFieldRules(); $this->field_options = $this->getFormFieldOptions(); - $this->getMyLibrary()->getMyStorage()->setAction($this->action); + $this->getModel()->setAction($this->action); + } + protected function create_validate(): void + { + //hosts를 제외한 fields Valid처리 + $this->validateFormDatas(array_diff($this->fields, ['hosts'])); } - // public function create_form(): RedirectResponse|string - // { - // return $this->create_form_process(); - // } protected function create_process_submit(): void { + $this->_zone_entity = $this->getZoneModel()->getEntityByPK($this->formDatas[$this->getModel()::PARENT]); + $this->_account_entity = $this->getAccountModel()->getEntityByPK($this->_zone_entity->getParent()); + if ($this->_account_entity === null) { + throw new \Exception("해당 계정정보를 찾을수 없습니다."); + } //Record생성 foreach ($this->formDatas['hosts'] as $host) { $this->getMyLibrary()->create($host, $this->formDatas); } } - public function create(string $zone_uid): RedirectResponse + // 리스트 + public function list_init(): void { - $this->_zone_entity = $this->getZoneModel()->getEntityByPK($zone_uid); - $this->_account_entity = $this->getAccountModel()->getEntityByPK($this->_zone_entity->getParent()); - $this->formDatas = []; - $this->getFormDatas(); - $this->convertFormDatas(); - $this->validateFormDatas(); - return parent::create_process(); + $this->action = 'index'; + $this->fields = [$this->getModel()::PARENT, $this->getModel()::TITLE, 'type', 'content', 'ttl', 'proxied', 'locked', 'updated_at', 'created_at']; + $this->filter_fields = [$this->getModel()::PARENT, 'type', 'proxied', 'status']; + $this->batchjob_fields = ['proxied']; + $this->field_rules = $this->getFormFieldRules(); + $this->field_options = $this->getFormFieldOptions(); + $this->getModel()->setAction($this->action); } } diff --git a/app/Controllers/Admin/Cloudflare/ZoneController.php b/app/Controllers/Admin/Cloudflare/ZoneController.php index 2525cf9..a5d1ede 100644 --- a/app/Controllers/Admin/Cloudflare/ZoneController.php +++ b/app/Controllers/Admin/Cloudflare/ZoneController.php @@ -2,18 +2,19 @@ namespace App\Controllers\Admin\Cloudflare; +use App\Libraries\MyCloudflare\Record; +use App\Libraries\MyCloudflare\Zone; +use App\Models\Cloudflare\ZoneModel; use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; -use App\Libraries\MyCloudflare\Zone; -use App\Libraries\MyCloudflare\Record; - class ZoneController extends CloudflareController { private $_myLibrary = null; private $_account_entity = null; + private $_model = null; public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { parent::initController($request, $response, $logger); @@ -22,6 +23,13 @@ class ZoneController extends CloudflareController $this->title = lang("{$this->class_path}.title"); helper($this->class_name); } + final protected function getModel(): ZoneModel + { + if ($this->_model === null) { + $this->_model = new ZoneModel(); + } + return $this->_model; + } final protected function getMyLibrary(): Zone { if ($this->_myLibrary === null) { @@ -32,7 +40,7 @@ class ZoneController extends CloudflareController protected function getFormFieldOption(string $field, array $options = []): array { switch ($field) { - case $this->getMyLibrary()->getMyStorage()::PARENT: + case $this->getModel()::PARENT: $this->getAccountModel()->where('status', DEFAULTS['STATUS']); $options[$field] = [ DEFAULTS['EMPTY'] => lang($this->_className . '.label.' . $field) . ' 선택', @@ -45,53 +53,47 @@ class ZoneController extends CloudflareController } return $options; } - protected function getFormData(string $field): void + protected function getFormData(string $field, array $formDatas): array { switch ($field) { case 'domains': - $this->formDatas[$field] = explode("\n", $this->request->getVar($field)); - if (!is_array($this->formDatas[$field]) || !count($this->formDatas[$field])) { + $formDatas[$field] = explode("\n", $this->request->getVar($field)); + if (!is_array($formDatas[$field]) || !count($formDatas[$field])) { throw new \Exception("도메인명이 정의되지 않았습니다."); } break; case 'hosts': - $this->formDatas[$field] = $this->request->getVar($field); - if (!is_array($this->formDatas[$field]) || !count($this->formDatas[$field])) { + $formDatas[$field] = $this->request->getVar($field); + if (!is_array($formDatas[$field]) || !count($formDatas[$field])) { throw new \Exception("호스트명이 정의되지 않았습니다"); } break; default: - $this->formDatas[$field] = $this->request->getVar($field); - break; - } - } - //전송된 데이터 검증 - protected function validateFormData(string $field): void - { - switch ($field) { - case 'domains': - case 'hosts': - break; - default: - parent::validateFormData($field); + $formDatas = parent::getFormData($field, $formDatas); break; } + return $formDatas; } protected function create_init(): void { $this->action = 'create'; - $this->fields = [$this->getMyLibrary()->getMyStorage()::PARENT, 'domains', 'hosts', 'type', 'content', 'proxied']; - $this->filter_fields = [$this->getMyLibrary()->getMyStorage()::PARENT, 'type', 'proxied']; + $this->fields = [$this->$this->getModel()::PARENT, 'domains', 'hosts', 'type', 'content', 'proxied']; + $this->filter_fields = [$this->$this->getModel()::PARENT, 'type', 'proxied']; $this->field_rules = $this->getFormFieldRules(); $this->field_options = $this->getFormFieldOptions(); - $this->getMyLibrary()->getMyStorage()->setAction($this->action); + $this->getModel()->setAction($this->action); } - // public function create_form(): RedirectResponse|string - // { - // return $this->create_form_process(); - // } - protected function create_process_submit(): void + protected function create_validate(): void { + //domains,hosts를 제외한 fields Valid처리 + $this->validateFormDatas(array_diff($this->fields, ['domains', 'hosts'])); + } + protected function create_process(): void + { + $this->_account_entity = $this->getAccountModel()->getEntityByPK($this->formDatas[$this->getModel()::PARENT]); + if ($this->_account_entity === null) { + throw new \Exception("해당 계정정보를 찾을수 없습니다."); + } foreach ($this->formDatas['domains'] as $domain) { //Zone생성 $zone_entity = $this->getMyLibrary()->create($domain); @@ -106,13 +108,15 @@ class ZoneController extends CloudflareController } } } - public function create(string $account_uid): RedirectResponse + // 리스트 + public function list_init(): void { - $this->_account_entity = $this->getAccountModel()->getEntityByPK($account_uid); - $this->formDatas = []; - $this->getFormDatas(); - $this->convertFormDatas(); - $this->validateFormDatas(); - return parent::create_process(); + $this->action = 'index'; + $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->filter_fields = [$this->getModel()::PARENT, 'development_mode', 'ipv6', 'security_level', 'status']; + $this->batchjob_fields = ['development_mode', 'ipv6', 'security_level']; + $this->field_rules = $this->getFormFieldRules(); + $this->field_options = $this->getFormFieldOptions(); + $this->getModel()->setAction($this->action); } } diff --git a/app/Controllers/MVController.php b/app/Controllers/MVController.php index 54d37ac..c4aa34f 100644 --- a/app/Controllers/MVController.php +++ b/app/Controllers/MVController.php @@ -14,9 +14,8 @@ abstract class MVController extends CommonController parent::initController($request, $response, $logger); helper('common'); } + abstract protected function getModel(): mixed; abstract protected function getMyLibrary(): mixed; - abstract protected function create_process_submit(): void; - abstract protected function modify_process_submit(): void; //Field별 Form Option용 protected function getFormFieldOption(string $field, array $options): array { @@ -47,70 +46,67 @@ abstract class MVController extends CommonController if (is_array($field)) { throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true)); } - $rules = $this->getMyLibrary()->getMyStorage()->getFieldRule($field, $rules); + $rules = $this->getModel()->getFieldRule($field, $rules); } // var_dump($rules); // exit; return $rules; } //전송된 데이터 - protected function getFormData(string $field): void + protected function getFormData(string $field, array $formDatas): array { switch ($field) { default: - $this->formDatas[$field] = $this->request->getVar($field); + $formDatas[$field] = $this->request->getVar($field); break; } + return $formDatas; } - final protected function getFormDatas(): void + final protected function getFormDatas(array $formDatas = []): array { foreach ($this->fields as $field) { - $this->getFormData($field); + $formDatas = $this->getFormData($field, $formDatas); } + return $formDatas; } //전송된 데이터 재정의 - protected function convertFormData(string $field): void + protected function convertFormData(string $field, array $formDatas): array { switch ($field) { default: break; } + return $formDatas; } - final protected function convertFormDatas(): void + final protected function convertFormDatas(array $formDatas = []): array { foreach ($this->fields as $field) { - $this->convertFormData($field); + $formDatas = $this->convertFormData($field, $formDatas); } + return $formDatas; } - //전송된 데이터 검증 - protected function validateFormData(string $field): void - { - switch ($field) { - default: - if ( - !$this->validation->check( - $this->formDatas[$field], - $this->getMyLibrary()->getMyStorage()->getFieldRule($field) - ) - ) { - throw new \Exception("데이터 검증 오류발생\n" . implode("\n", $this->validation->getError())); - } - break; - } - } - final protected function validateFormDatas(): void + final protected function validateFormDatas(array $fields): void { //변경할 값 확인 : Upload된 파일 검증시 $this->request->getVar()보다 먼처 체크필요 $this->validation = service('validation'); - foreach ($this->fields as $field) { - $this->validateFormData($field); + $this->validation->setRules($this->getModel()->getFieldRules($fields)); + if (!$this->validation->withRequest($this->request)->run()) { + throw new \Exception("{$this->class_name}의 {$this->action} 작업 데이터 검증 오류발생\n" . implode( + "\n", + $this->validation->getErrors() + )); } } // 생성 - final protected function create_form_process(): RedirectResponse|string + protected function create_form_process(): void + { + } + public function create_form(): RedirectResponse|string { helper(['form']); try { + $this->create_init(); + $this->create_form_process(); $this->session->keepFlashdata(SESSION_NAMES['RETURN_URL']); $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; return view( @@ -122,54 +118,92 @@ abstract class MVController extends CommonController return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/")->with(SESSION_NAMES['RETURN_MSG'], $e->getMessage()); } } - final protected function create_process(): mixed + protected function create_validate(): void + { + $this->validateFormDatas($this->fields); + } + protected function create_process(): void + { + } + public function create(): RedirectResponse { - $this->getMyLibrary()->getMyStorage()->transStart(); try { - $this->create_process_submit(); + $this->create_init(); + $this->create_validate(); + $this->formDatas = $this->getFormDatas(); + $this->formDatas = $this->convertFormDatas($this->formDatas); + //Transaction Start + $this->getModel()->transStart(); + $this->create_process(); return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/"); } catch (\Exception $e) { //Transaction Rollback - $this->getMyLibrary()->getMyStorage()->transRollback(); + $this->getModel()->transRollback(); log_message("error", $e->getMessage()); $this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage()); $this->session->keepFlashdata(SESSION_NAMES['RETURN_URL']); return redirect()->back()->withInput(); } } - // 수정 - final protected function modify_form_process(): RedirectResponse|string + protected function modify_validate(): void + { + $this->validateFormDatas($this->fields); + } + protected function modify_form_process(): void + { + } + public function modify_form(): RedirectResponse|string { helper(['form']); try { + $this->modify_init(); + $this->formDatas = $this->getFormDatas(); + //기존 데이터 가져오기 + $this->entity = $this->getModel()->getEntityByPK($this->formDatas[$this->getModel()->getPKField()]); + if ($this->entity === null) { + throw new \Exception("해당 정보를 찾을수 없습니다."); + } + $this->modify_form_process(); $this->session->keepFlashdata(SESSION_NAMES['RETURN_URL']); $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; return view( strtolower($this->class_path) . "/modify", - ['viewDatas' => $this->getViewDatas()] + data: ['viewDatas' => $this->getViewDatas()] ); } catch (\Exception $e) { log_message("error", $e->getMessage()); return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/")->with(SESSION_NAMES['RETURN_MSG'], $e->getMessage()); } } - final protected function modify_process(): mixed + protected function modify_process(): void + { + } + public function modify(): mixed { - $this->getMyLibrary()->getMyStorage()->transStart(); try { - $this->modify_process_submit(); + $this->modify_init(); + $this->modify_validate(); + $this->formDatas = $this->getFormDatas(); + $this->formDatas = $this->convertFormDatas($this->formDatas); + //기존 데이터 가져오기 + $this->entity = $this->getModel()->getEntityByPK($this->formDatas[$this->getModel()->getPKField()]); + if ($this->entity === null) { + throw new \Exception("해당 정보를 찾을수 없습니다."); + } + //Transaction Start + $this->getModel()->transStart(); + $this->modify_process(); return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/"); } catch (\Exception $e) { //Transaction Rollback - $this->getMyLibrary()->getMyStorage()->transRollback(); + $this->getModel()->transRollback(); log_message("error", $e->getMessage()); $this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage()); $this->session->keepFlashdata(SESSION_NAMES['RETURN_URL']); return redirect()->back()->withInput(); } } - // 리스트 protected function list_condition($isTotalCount = false): void { @@ -177,26 +211,24 @@ abstract class MVController extends CommonController foreach ($this->filter_fields as $field) { $this->$field = $this->request->getVar($field) ?: DEFAULTS['EMPTY']; if ($this->$field !== DEFAULTS['EMPTY']) { - $this->getMyLibrary()->getMyStorage()->setList_FieldFilter($field, $this->$field); + $this->getModel()->setList_FieldFilter($field, $this->$field); } } //검색어 처리 $this->word = $this->request->getVar('word') ?: DEFAULTS['EMPTY']; if ($this->word !== DEFAULTS['EMPTY']) { - $this->getMyLibrary()->getMyStorage()->setList_WordFilter($this->word); + $this->getModel()->setList_WordFilter($this->word); } //검색일 처리 $this->start = $this->request->getVar('start') ?: DEFAULTS['EMPTY']; $this->end = $this->request->getVar('end') ?: DEFAULTS['EMPTY']; - if ($this->start !== DEFAULTS['EMPTY'] && $this->end !== DEFAULTS['EMPTY']) { - $this->getMyLibrary()->getMyStorage()->setList_DateFilter($this->start, $this->end); - } + $this->getModel()->setList_DateFilter($this->start, $this->end); if (!$isTotalCount) { //Sorting 처리 $this->order_field = $this->request->getVar('order_field') ?: DEFAULTS['EMPTY']; $this->order_value = $this->request->getVar('order_value') ?: DEFAULTS['EMPTY']; if ($this->order_field !== DEFAULTS['EMPTY'] && $this->order_value !== DEFAULTS['EMPTY']) { - $this->getMyLibrary()->getMyStorage()->setList_OrderBy("{$this->order_field} {$this->order_value}"); + $this->getModel()->setList_OrderBy("{$this->order_field} {$this->order_value}"); } } } @@ -204,8 +236,8 @@ abstract class MVController extends CommonController protected function list_total(): int { $this->list_condition(true); - $total_count = $this->getMyLibrary()->getMyStorage()->countAllResults(); - // dd($this->getMyLibrary()->getMyStorage()->getLastQuery()); + $total_count = $this->getModel()->countAllResults(); + // echo $this->getModel()->getLastQuery(); return $total_count; } //PageNation 처리 @@ -224,7 +256,7 @@ abstract class MVController extends CommonController // 2.app/Config/Pager.php/$templates에 'bootstrap_full => 'Pagers\bootstrap_full', // 'bootstrap_simple' => 'Pagers\bootstrap_simple', 추가 $pager = service("pager"); - // $this->getMyLibrary()->getMyStorage()->paginate($this->per_page, $pager_group, $this->page, $segment); + // $this->getModel()->paginate($this->per_page, $pager_group, $this->page, $segment); $pager->makeLinks( $this->page, $this->per_page, @@ -241,18 +273,21 @@ abstract class MVController extends CommonController { $this->list_condition(); if ($this->page) { - $this->getMyLibrary()->getMyStorage()->limit( + $this->getModel()->limit( $this->per_page, $this->page * $this->per_page - $this->per_page ); } - $entitys = $this->getMyLibrary()->getMyStorage()->findAll(); - // dd($this->getMyLibrary()->getMyStorage()->getLastQuery()); + $entitys = $this->getModel()->findAll(); + // echo $this->getModel()->getLastQuery(); return $entitys; } - public function list_process(): string + public function list(): string { try { + helper(['form']); + $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; + $this->list_init(); //URL처리 $this->uri = $this->request->getUri(); //total 처리 diff --git a/app/Helpers/Admin/Cloudflare/Account_helper.php b/app/Helpers/Admin/Cloudflare/Account_helper.php index 55d9285..429d73e 100644 --- a/app/Helpers/Admin/Cloudflare/Account_helper.php +++ b/app/Helpers/Admin/Cloudflare/Account_helper.php @@ -39,6 +39,7 @@ function getFieldForm_AccountHelper(string $field, mixed $value, array $viewData break; case 'id': $form = form_input($field, $value, ["placeholder" => "예)sample@test.com", "style" => "width:60%; ::placeholder{color:silver; opacity: 1;}"]); + break; case 'name': $form = form_input($field, $value, ["placeholder" => "예)", "style" => "width:60%; ::placeholder{color:silver; opacity: 1;}"]); break; @@ -47,7 +48,7 @@ function getFieldForm_AccountHelper(string $field, mixed $value, array $viewData $form = form_input($field, $value, ['class' => 'calender']); break; default: - $form = form_input($field, $value); + $form = form_input($field, $value, ["style" => "width:60%;"]); break; } return $form; diff --git a/app/Libraries/MyCloudflare/Account.php b/app/Libraries/MyCloudflare/Account.php index da3e9c5..e13c999 100644 --- a/app/Libraries/MyCloudflare/Account.php +++ b/app/Libraries/MyCloudflare/Account.php @@ -68,19 +68,18 @@ class Account extends MyCloudflare // log_message("notice", "Account::" . __FUNCTION__ . "=> 작업을 완료하였습니다."); // return $entity; // } - public function create($formDatas): AccountEntity + public function create($formDatas): array { $this->_authkey = $formDatas['authkey']; - $cf = $this->getRequest()->get('accounts', ['page' => 1, 'per_page' => 20]); - $cf = json_decode($cf->getBody()); - if (!$cf->success) { - throw new \Exception("Account:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true)); - } //Account의 경우 인증키를 가지고있고 생성할수 없으므로 get으로 읽은후 첫번째것을 사용하기로 함 - $formDatas = $this->getArrayByResult(array_shift($cf->result)); - $entity = $this->$this->getMyStorage()->create($formDatas); - log_message("notice", "Account:" . __FUNCTION__ . "=> 작업을 완료하였습니다."); - return $entity; + $entitys = []; + foreach ($this->reload_cfs($this->getRequest(), 'accounts') as $cf) { + $formDatas = $this->getArrayByResult($cf->result); + $entity = $this->$this->getMyStorage()->create($formDatas); + log_message("notice", "Account:" . __FUNCTION__ . "=> {$entity->getTitle()} 작업을 완료하였습니다."); + $entitys[] = $entity; + } + return $entitys; } protected function reload_entity($cf): AccountEntity diff --git a/app/Models/CommonModel.php b/app/Models/CommonModel.php index f6f8ca1..4a3f1b9 100644 --- a/app/Models/CommonModel.php +++ b/app/Models/CommonModel.php @@ -63,21 +63,9 @@ abstract class CommonModel extends Model { return $this->_action = $action; } - final public function getFields(string $key = "", array $fields = []): array + final public function getFields(array $except_fields = []): array { - $allowedFields = array_filter( - $this->allowedFields, - function ($value) use (&$key, &$fields) { - if ($key == 'except') { - return !in_array($value, $fields); - } elseif ($key == 'only') { - return in_array($value, $fields); - } else { - return $value; - } - } - ); - return $allowedFields; + return array_diff($this->allowedFields, $except_fields); //제외한 fields } public function getFieldRule(string $field, array $rules): array { @@ -243,13 +231,16 @@ abstract class CommonModel extends Model } public function setList_WordFilter(string $word, string $field = null): void { - $this->like($field ?? $this->getTitleField(), $word, 'before'); //befor , after , both + $this->like($field ?? $this->getTitleField(), $word, 'both'); //befor , after , both } - public function setList_DateFilter(string $start, string $end, $field = "created_at"): void + final public function setList_DateFilter(string $start, string $end, $field = "created_at"): void { - - $this->where("{$field} >= {$start}"); - $this->where("{$field} <= {$end}"); + if ($start !== DEFAULTS['EMPTY']) { + $this->where("{$field} >= '{$start} 00:00:00'"); + } + if ($end !== DEFAULTS['EMPTY']) { + $this->where("{$field} <= '{$end} 23:59:59'"); + } } public function setList_OrderBy(string $order) { diff --git a/app/Views/admin/cloudflare/account/create.php b/app/Views/admin/cloudflare/account/create.php index 113abe0..693e97b 100644 --- a/app/Views/admin/cloudflare/account/create.php +++ b/app/Views/admin/cloudflare/account/create.php @@ -1,6 +1,4 @@ -= $this->extend('layouts/admin') ?> -= $this->section('content') ?> - + = form_open_multipart(current_url(), $viewDatas['forms']['attributes'], $viewDatas['forms']['hiddens']) ?>