From 3e2a27d4d6b79b34cecfba2f9bd8c420fd361b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Mon, 14 Oct 2024 15:56:43 +0900 Subject: [PATCH] cfmgrv4 init...2 --- .../Admin/Cloudflare/RecordController.php | 30 +++++++++++++++++++ .../Admin/Cloudflare/ZoneController.php | 30 +++++++++++++++++++ app/Controllers/MVController.php | 8 ++--- app/Models/Cloudflare/RecordModel.php | 15 +--------- app/Models/Cloudflare/ZoneModel.php | 13 -------- app/Models/CommonModel.php | 15 +++------- 6 files changed, 69 insertions(+), 42 deletions(-) diff --git a/app/Controllers/Admin/Cloudflare/RecordController.php b/app/Controllers/Admin/Cloudflare/RecordController.php index c78b2d4..24d9155 100644 --- a/app/Controllers/Admin/Cloudflare/RecordController.php +++ b/app/Controllers/Admin/Cloudflare/RecordController.php @@ -5,6 +5,7 @@ namespace App\Controllers\Admin\Cloudflare; use App\Helpers\Cloudflare\RecordHelper; use App\Libraries\Cloudflare\Record; use App\Models\Cloudflare\RecordModel; +use App\Models\Cloudflare\ZoneModel; use CodeIgniter\HTTP\DownloadResponse; use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RequestInterface; @@ -176,6 +177,35 @@ class RecordController extends CloudflareController $this->entity = $this->getMyLibrary()->delete($this->entity); } // 리스트 + protected function list_entitys_process(): array + { + $this->list_condition_process(); + //기본Soring처리 + $this->getModel()->orderBy(ZoneModel::TABLE . "." . ZoneModel::TITLE . " ASC ," . $this->getModel()::TITLE . " ASC"); + //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->getModel()->orderBy(sprintf( + "%s.%s %s", + $this->getModel()::TABLE, + $this->order_field, + $this->order_value + )); + } + $this->getModel()->limit($this->per_page, $this->page * $this->per_page - $this->per_page); + //Join을 해서 도메인부터 Sorting하기위함 + $this->getModel()->join(ZoneModel::TABLE, sprintf( + "%s.%s=%s.%s", + $this->getModel()::TABLE, + $this->getModel()::PARENT, + ZoneModel::TABLE, + ZoneModel::PK + )); + $entitys = $this->getModel()->select($this->getModel()::TABLE . '.*')->findAll(); + log_message("debug", $this->getModel()->getLastQuery()); + return $entitys; + } public function index(): string { $this->action = __FUNCTION__; diff --git a/app/Controllers/Admin/Cloudflare/ZoneController.php b/app/Controllers/Admin/Cloudflare/ZoneController.php index 0d50592..b9aee01 100644 --- a/app/Controllers/Admin/Cloudflare/ZoneController.php +++ b/app/Controllers/Admin/Cloudflare/ZoneController.php @@ -5,6 +5,7 @@ namespace App\Controllers\Admin\Cloudflare; use App\Helpers\Cloudflare\ZoneHelper; use App\Libraries\Cloudflare\Record; use App\Libraries\Cloudflare\Zone; +use App\Models\Cloudflare\AccountModel; use App\Models\Cloudflare\ZoneModel; use CodeIgniter\HTTP\DownloadResponse; use CodeIgniter\HTTP\RedirectResponse; @@ -210,6 +211,35 @@ class ZoneController extends CloudflareController $this->entity = $this->getMyLibrary()->delete($this->entity); } // 리스트 + protected function list_entitys_process(): array + { + $this->list_condition_process(); + //기본Soring처리 + $this->getModel()->orderBy(orderBy: AccountModel::TABLE . "." . AccountModel::TITLE . " ASC ," . $this->getModel()::TITLE . " ASC"); + //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->getModel()->orderBy(sprintf( + "%s.%s %s", + $this->getModel()::TABLE, + $this->order_field, + $this->order_value + )); + } + $this->getModel()->limit($this->per_page, $this->page * $this->per_page - $this->per_page); + //Join을 해서 도메인부터 Sorting하기위함 + $this->getModel()->join(AccountModel::TABLE, sprintf( + "%s.%s=%s.%s", + $this->getModel()::TABLE, + $this->getModel()::PARENT, + AccountModel::TABLE, + AccountModel::PK + )); + $entitys = $this->getModel()->select($this->getModel()::TABLE . '.*')->findAll(); + log_message("debug", $this->getModel()->getLastQuery()); + return $entitys; + } public function index(): string { $this->action = __FUNCTION__; diff --git a/app/Controllers/MVController.php b/app/Controllers/MVController.php index 7a67853..be3f9a6 100644 --- a/app/Controllers/MVController.php +++ b/app/Controllers/MVController.php @@ -270,7 +270,7 @@ abstract class MVController extends CommonController } } // 리스트 - private function list_condition_process(): void + protected function list_condition_process(): void { //조건절 처리 foreach ($this->filter_fields as $field) { @@ -326,17 +326,17 @@ abstract class MVController extends CommonController $this->total_page = $pager->getPageCount($pager_group); return $pager->links($pager_group, $template); } - private function list_entitys_process(): array + protected function list_entitys_process(): array { $this->list_condition_process(); //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->getModel()->setList_OrderBy("{$this->order_field} {$this->order_value}"); + $this->getModel()->orderBy("{$this->order_field} {$this->order_value}"); } $this->getModel()->limit($this->per_page, $this->page * $this->per_page - $this->per_page); - $entitys = $this->getModel()->select($this->getModel()->getTable() . '.*')->findAll(); + $entitys = $this->getModel()->select($this->getModel()::TABLE . '.*')->findAll(); log_message("debug", $this->getModel()->getLastQuery()); return $entitys; } diff --git a/app/Models/Cloudflare/RecordModel.php b/app/Models/Cloudflare/RecordModel.php index 9d7212f..ecab865 100644 --- a/app/Models/Cloudflare/RecordModel.php +++ b/app/Models/Cloudflare/RecordModel.php @@ -116,19 +116,6 @@ class RecordModel extends CommonModel public function setList_WordFilter(string $word, $field = null): void { parent::setList_WordFilter($word, $field); - $this->orLike('content', $word, 'both'); - } - public function setList_OrderBy(string $order = ""): void - { - //Join을 해서 도메인부터 Sorting하기위함 - $this->join(ZoneModel::TABLE, sprintf( - "%s.%s=%s.%s", - self::TABLE, - self::PARENT, - ZoneModel::TABLE, - ZoneModel::PK - )); - $this->orderBy(ZoneModel::TABLE . "." . ZoneModel::TITLE . " ASC ," . self::TITLE . " ASC"); - parent::setList_OrderBy($order); + $this->orLike(self::TABLE . '.content', $word, 'both'); } } diff --git a/app/Models/Cloudflare/ZoneModel.php b/app/Models/Cloudflare/ZoneModel.php index c510ed8..b85e05a 100644 --- a/app/Models/Cloudflare/ZoneModel.php +++ b/app/Models/Cloudflare/ZoneModel.php @@ -122,17 +122,4 @@ class ZoneModel extends CommonModel // $zone_uids = array_column($zone_uids, RecordModel::PARENT); // $this->orWhereIn(self::TABLE . '.' . self::PK, array_values($zone_uids)); } - public function setList_OrderBy(string $order = ""): void - { - //Join을 해서 도메인부터 Sorting하기위함 - $this->join(AccountModel::TABLE, sprintf( - "%s.%s=%s.%s", - self::TABLE, - self::PARENT, - AccountModel::TABLE, - AccountModel::PK - )); - $this->orderBy(AccountModel::TABLE . "." . AccountModel::TITLE . " ASC ," . self::TITLE . " ASC"); - parent::setList_OrderBy($order); - } } diff --git a/app/Models/CommonModel.php b/app/Models/CommonModel.php index ac2f277..6b36379 100644 --- a/app/Models/CommonModel.php +++ b/app/Models/CommonModel.php @@ -75,8 +75,7 @@ abstract class CommonModel extends Model $rule .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : ""; } else { $rule = "required|numeric"; - } - ; + }; break; case $this->getTitleField(): $rule = "required|string"; @@ -216,21 +215,15 @@ abstract class CommonModel extends Model } public function setList_WordFilter(string $word, string $field = null): void { - $this->like($field ?? $this->getTitleField(), $word, 'both'); //befor , after , both + $this->like($this->getTable() . '.' . ($field ?? $this->getTitleField()), $word, 'both'); //befor , after , both } final public function setList_DateFilter(string $start, string $end, $field = "created_at"): void { if ($start !== DEFAULTS['EMPTY']) { - $this->where("{$field} >= '{$start} 00:00:00'"); + $this->where($this->getTable() . ".{$field} >= '{$start} 00:00:00'"); } if ($end !== DEFAULTS['EMPTY']) { - $this->where("{$field} <= '{$end} 23:59:59'"); - } - } - public function setList_OrderBy(string $order = ""): void - { - if ($order) { - $this->orderBy($order); + $this->where($this->getTable() . ".{$field} <= '{$end} 23:59:59'"); } } }