From 2d09b4fcce97f0096688a4afd1385117b1857855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Thu, 16 May 2024 19:12:30 +0900 Subject: [PATCH] vhost init...3 --- app/Controllers/Admin/ProductController.php | 20 +++++++++ app/Controllers/BaseController.php | 41 +++++++++---------- .../Front/Billing/BillingController.php | 4 +- app/Entities/DeviceEntity.php | 14 +++++++ app/Helpers/Product_helper.php | 10 +++++ app/Language/ko/Device.php | 10 ++--- app/Models/DeviceModel.php | 19 ++++++++- app/Views/admin/product/insert.php | 16 +++++++- 8 files changed, 102 insertions(+), 32 deletions(-) diff --git a/app/Controllers/Admin/ProductController.php b/app/Controllers/Admin/ProductController.php index 6a36ca1..d817e36 100644 --- a/app/Controllers/Admin/ProductController.php +++ b/app/Controllers/Admin/ProductController.php @@ -3,6 +3,7 @@ namespace App\Controllers\Admin; use App\Controllers\Trait\UpDownloadTrait; +use App\Models\DeviceModel; use App\Models\ProductModel; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; @@ -11,6 +12,7 @@ use Psr\Log\LoggerInterface; class ProductController extends AdminController { use UpDownloadTrait; + private $_deviceModel = null; public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { parent::initController($request, $response, $logger); @@ -22,6 +24,11 @@ class ProductController extends AdminController helper($this->_viewDatas['className']); } + final protected function getDeviceModel(): DeviceModel + { + return $this->_deviceModel = $this->_deviceModel ?: new DeviceModel(); + } + public function getFields(string $action = ""): array { $fields = ["category_uid", 'type', 'name', "photo", "cost", "sale", "stock", "view_cnt", "status", "content",]; @@ -77,7 +84,20 @@ class ProductController extends AdminController return $this->_viewDatas['fieldDatas']['cost'] - $this->_viewDatas['fieldDatas']['sale']; } + protected function action_init(array $action_datas): void + { + parent::action_init($action_datas); + $this->_viewDatas['device'] = []; + $this->_viewDatas['device']['fields'] = ['server', 'cpu', 'memory', 'disk', 'nic', 'publicip', 'os']; + $this->_viewDatas['device']['options'] = $this->getDeviceModel()->getOptions(); + } + //Insert관련 + protected function insert_validate() + { + parent::insert_validate(); + } + protected function insert_process() { $this->_viewDatas['fieldDatas']['price'] = $this->calculate_price(); diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php index e10df01..f750880 100644 --- a/app/Controllers/BaseController.php +++ b/app/Controllers/BaseController.php @@ -136,9 +136,9 @@ abstract class BaseController extends Controller } //초기화 - final public function action_init(array $viewDatas) + protected function action_init(array $action_datas): void { - switch ($viewDatas['action']) { + switch ($action_datas['action']) { case 'insert_form': $action = 'insert'; break; @@ -146,15 +146,14 @@ abstract class BaseController extends Controller $action = 'update'; break; default: - $action = $viewDatas['action']; + $action = $action_datas['action']; break; } - $this->_viewDatas['fields'] = array_key_exists('fields', $viewDatas) ? $viewDatas['fields'] : $this->getFields($action); + $this->_viewDatas['fields'] = array_key_exists('fields', $action_datas) ? $action_datas['fields'] : $this->getFields($action); $this->_viewDatas['fieldRules'] = $this->getFieldRules($this->_viewDatas['fields'], $action); $this->_viewDatas['fieldFilters'] = $this->getFieldFilters(); $this->_viewDatas['batchjobFilters'] = $this->getFieldBatchFilters(); $this->_viewDatas['fieldFormOptions'] = $this->getFieldFormOptions($this->_viewDatas['fieldFilters']); - return $this->_viewDatas; } //Insert관련 @@ -162,10 +161,10 @@ abstract class BaseController extends Controller { $this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []]; } - public function insert_form() + final public function insert_form() { try { - $this->_viewDatas = $this->action_init(['action' => __FUNCTION__]); + $this->action_init(['action' => __FUNCTION__]); $this->insert_form_process(); helper(['form']); $this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']); @@ -198,7 +197,7 @@ abstract class BaseController extends Controller //Transaction 시작 $this->_model->transStart(); try { - $this->_viewDatas = $this->action_init(['action' => __FUNCTION__]); + $this->action_init(['action' => __FUNCTION__]); $this->insert_validate(); $entity = $this->insert_process(); //Transaction Commit @@ -221,10 +220,10 @@ abstract class BaseController extends Controller $this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []]; return $entity; } - public function update_form($uid) + final public function update_form($uid) { try { - $this->_viewDatas = $this->action_init(['action' => __FUNCTION__]); + $this->action_init(['action' => __FUNCTION__]); $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); $this->_viewDatas['entity'] = $this->update_form_process($entity); helper(['form']); @@ -272,7 +271,7 @@ abstract class BaseController extends Controller //Transaction 시작 $this->_model->transStart(); try { - $this->_viewDatas = $this->action_init(['action' => __FUNCTION__]); + $this->action_init(['action' => __FUNCTION__]); $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); $this->update_validate($entity); $entity = $this->update_process($entity); @@ -298,10 +297,10 @@ abstract class BaseController extends Controller $this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []]; return $entity; } - public function reply_form($uid) + final public function reply_form($uid) { try { - $this->_viewDatas = $this->action_init(['action' => __FUNCTION__]); + $this->action_init(['action' => __FUNCTION__]); $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); $this->_viewDatas['entity'] = $this->reply_form_process($entity); helper(['form']); @@ -335,7 +334,7 @@ abstract class BaseController extends Controller //Transaction 시작 $this->_model->transStart(); try { - $this->_viewDatas = $this->action_init(['action' => __FUNCTION__]); + $this->action_init(['action' => __FUNCTION__]); $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); $this->reply_validate($entity); $entity = $this->reply_process($entity); @@ -377,7 +376,7 @@ abstract class BaseController extends Controller //Transaction 시작 $this->_model->transStart(); try { - $this->_viewDatas = $this->action_init(['action' => __FUNCTION__, 'fields' => [$field]]); + $this->action_init(['action' => __FUNCTION__, 'fields' => [$field]]); $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); $this->toggle_validate($entity); $entity = $this->toggle_process($entity); @@ -430,7 +429,7 @@ abstract class BaseController extends Controller if (!is_array($fields) || count($fields) === 0) { throw new \Exception($this->_viewDatas['title'] . '에서 변경할 항목(field)이 선택되지 않았습니다.'); } - $this->_viewDatas = $this->action_init(['action' => __FUNCTION__, 'fields' => $fields]); + $this->action_init(['action' => __FUNCTION__, 'fields' => $fields]); $uids = $this->request->getVar('batchjob_uids') ?: throw new \Exception($this->_viewDatas['title'] . '에서 변경할 항목(uid)이 선택되지 않았습니다.'); $cnt = 1; foreach ($uids as $uid) { @@ -509,10 +508,10 @@ abstract class BaseController extends Controller $this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []]; return $entity; } - public function view($uid) + final public function view($uid) { try { - $this->_viewDatas = $this->action_init(['action' => __FUNCTION__]); + $this->action_init(['action' => __FUNCTION__]); $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); $this->_viewDatas['entity'] = $this->view_process($entity); helper(['form']); @@ -584,7 +583,7 @@ abstract class BaseController extends Controller public function index() { try { - $this->_viewDatas = $this->action_init(['action' => __FUNCTION__]); + $this->action_init(['action' => __FUNCTION__]); foreach ($this->_viewDatas['fieldFilters'] as $field) { $this->_viewDatas[$field] = $this->request->getVar($field) ?: DEFAULTS['EMPTY']; } @@ -646,7 +645,7 @@ abstract class BaseController extends Controller final public function excel() { try { - $this->_viewDatas = $this->action_init(['action' => __FUNCTION__]); + $this->action_init(['action' => __FUNCTION__]); $this->_viewDatas['Entitys'] = $this->index_entitys(); $html = view( $this->_viewPath . '/excel', @@ -684,7 +683,7 @@ abstract class BaseController extends Controller } return $this->response->download(PATHS['UPLOAD'] . "/" . $uploaded_filename, null)->setFileName(date("Ymd") . '_' . $filename); } - public function download(string $field, $uid) + final public function download(string $field, $uid) { try { $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); diff --git a/app/Controllers/Front/Billing/BillingController.php b/app/Controllers/Front/Billing/BillingController.php index 34b0f46..f43e4c5 100644 --- a/app/Controllers/Front/Billing/BillingController.php +++ b/app/Controllers/Front/Billing/BillingController.php @@ -149,11 +149,11 @@ class BillingController extends FrontController $this->setCategory($this->request->getVar('category') ?: self::DEFAULT_CATEGORY); parent::index_process(); } - protected function index_setCondition() + protected function index_condition() { //사용자정보(user_uid)에 맞는 Biiling정보 가져오기 $this->_model->where('user_uid', $this->_session->get(SESSION_NAMES['AUTH'])[AUTH_FIELDS['ID']]); - parent::index_setCondition(); + parent::index_condition(); } //추가기능 diff --git a/app/Entities/DeviceEntity.php b/app/Entities/DeviceEntity.php index d55a9f2..610c890 100644 --- a/app/Entities/DeviceEntity.php +++ b/app/Entities/DeviceEntity.php @@ -14,4 +14,18 @@ class DeviceEntity extends BaseEntity return $this->attributes['name']; } //추가기능 + public function getType(): string + { + return $this->attributes['type']; + } + + //판매금액표시용 + public function getSalePrice(array $options = []): string + { + $price = $this->attributes['price'] - $this->attributes['sale']; + if (array_key_exists('format', $options)) { + $price = sprintf($options['format'], number_format($price)); + } + return $price; + } } diff --git a/app/Helpers/Product_helper.php b/app/Helpers/Product_helper.php index b1addd5..9741cf5 100644 --- a/app/Helpers/Product_helper.php +++ b/app/Helpers/Product_helper.php @@ -26,6 +26,16 @@ function getFieldForm_ProductHelper($field, $value, array $viewDatas, array $att // } // return implode(" ", $checkboxs); break; + case 'server': + case 'cpu': + case 'memory': + case 'disk': + case 'nic': + case 'os': + case 'publicip': + $viewDatas['fieldFormOptions'][$field] = [DEFAULTS['EMPTY'] => lang("Device.TYPE.label.{$field}") . " 선택", ...$viewDatas['device']['options'][$field]]; + return form_dropdown($field, $viewDatas['fieldFormOptions'][$field], $value, [...$attributes, 'style' => 'width:200px']); + break; case 'title': case 'name': return form_input($field, $value, ["placeholder" => "예)", "style" => "width:60%; ::placeholder{ color:silver; opacity: 1; }"]); diff --git a/app/Language/ko/Device.php b/app/Language/ko/Device.php index ad02782..10a4b98 100644 --- a/app/Language/ko/Device.php +++ b/app/Language/ko/Device.php @@ -15,16 +15,12 @@ return [ 'created_at' => "생성일" ], "TYPE" => [ - 'beremetal' => '단독서버', - 'kvm' => '가상서버', - 'container' => '콘테이너', + 'server' => '서버', 'cpu' => 'CPU', 'memory' => 'Memory', - 'ssd' => 'SSD', - 'nvme' => 'NVME', + 'disk' => '저장장치', 'nic' => 'LANCARD', - 'windows' => 'Windows', - 'linux' => 'Linux', + 'os' => 'OS', 'publicip' => '공인IP' ], "STATUS" => [ diff --git a/app/Models/DeviceModel.php b/app/Models/DeviceModel.php index 9174149..65c04c4 100644 --- a/app/Models/DeviceModel.php +++ b/app/Models/DeviceModel.php @@ -17,7 +17,7 @@ class DeviceModel extends BaseModel parent::__construct('Device'); $this->allowedFields = [ ...$this->allowedFields, - 'type', 'name', "photo", "cost", "price", "sale", + 'type', 'name', "cost", "price", "sale", "stock", "content", "status" ]; $this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),]; @@ -57,6 +57,23 @@ class DeviceModel extends BaseModel return $rules; } + //Form 선택용 Options Data용 + public function getOptions(array $conditions = [], $options = []): array + { + //대분류 부분은 선택이 되지 않게 하기위해 따로 만듬 (form_dropdown의 optgroup 기능) + foreach ($this->getEntitys($conditions) as $entity) { + if (!array_key_exists($entity->getType(), $options)) { + $options[$entity->getType()] = []; + } + $options[$entity->getType()][$entity->getPrimaryKey()] = sprintf( + "%s %s", + $entity->getSalePrice(['format' => "%s원"]), + $entity->getTitle() + ); + } + return $options; + } + public function getEntity($conditions): DeviceEntity { return $this->where($conditions)->first() ?: throw new \Exception(__FUNCTION__ . "에서 {$this->getClassName()}의 해당 데이터가 없습니다."); diff --git a/app/Views/admin/product/insert.php b/app/Views/admin/product/insert.php index d7dcdc3..0c35f5b 100644 --- a/app/Views/admin/product/insert.php +++ b/app/Views/admin/product/insert.php @@ -5,9 +5,23 @@ + + + + - +
기본장비 + +
+ + + + +
+ +
+