vhost init...4

This commit is contained in:
최준흠 2024-05-20 17:25:35 +09:00
parent 38ddb62697
commit ecf4565fd5
40 changed files with 396 additions and 369 deletions

View File

@ -13,18 +13,10 @@ class ProductCell extends BaseCell
return $this->_deviceModel = $this->_deviceModel ?: new DeviceModel();
}
public function virtual(array $cellDatas = [])
{
return view(
'Views/cells/product/' . __FUNCTION__,
['cellDatas' => $cellDatas]
);
}
public function beremetal(array $cellDatas = [])
public function device(array $cellDatas = [])
{
$cellDatas['device'] = [];
$cellDatas['device']['categorys'] = ['server', 'memory', 'disk'];
$cellDatas['device']['categorys'] = ['server', 'cpu', 'memory', 'disk', 'nic', 'publicip', 'os'];
$cellDatas['device']['options'] = $this->getDeviceModel()->getOptions();
return view(
'Views/cells/product/' . __FUNCTION__,
@ -32,7 +24,7 @@ class ProductCell extends BaseCell
);
}
public function beremetal_calulator(array $cellDatas = []): string
public function device_calulator(array $cellDatas = []): string
{
$cellDatas['device'] = [];
$cellDatas['device']['categorys'] = ['server', 'cpu', 'memory', 'disk', 'nic', 'publicip', 'os'];

View File

@ -17,14 +17,13 @@ class BillingController extends AdminController
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->_model = new BillingModel();
$this->initModel(new BillingModel());
$this->_viewDatas['className'] = 'Billing';
$this->_viewPath .= strtolower($this->_viewDatas['className']);
$this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title');
$this->_viewDatas['class_icon'] = CLASS_ICONS[strtoupper($this->_viewDatas['className'])];
helper($this->_viewDatas['className']);
}
final protected function getOrderModel(): OrderModel
{
return $this->_orderModel = $this->_orderModel ?: new OrderModel();
@ -78,7 +77,7 @@ class BillingController extends AdminController
}
//View 관련
protected function view_process($entity)
protected function view_process($entity): BillingEntity
{
$entity = parent::view_process($entity);
//청구서 연결 주문정보 가져오기

View File

@ -3,6 +3,7 @@
namespace App\Controllers\Admin;
use App\Controllers\Trait\UpDownloadTrait;
use App\Entities\BoardEntity;
use App\Models\BoardModel;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
@ -15,7 +16,7 @@ class BoardController extends AdminController
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->_model = new BoardModel();
$this->initModel(new BoardModel());
$this->_viewDatas['className'] = 'Board';
$this->_viewPath .= strtolower($this->_viewDatas['className']);;
$this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title');
@ -66,7 +67,7 @@ class BoardController extends AdminController
private function build_notice()
{
$entitys = $this->_model->getEntitys(['category' => $this->_category_notice, 'status' => DEFAULTS['STATUS']]);
$entitys = $this->getModel()->getEntitys(['category' => $this->_category_notice, 'status' => DEFAULTS['STATUS']]);
$temps = array("<ul>");
foreach ($entitys as $entity) {
array_push($temps, sprintf(
@ -83,7 +84,7 @@ class BoardController extends AdminController
}
//Insert관련
protected function insert_process()
protected function insert_process(): BoardEntity
{
$entity = parent::insert_process();
if ($entity->category == $this->_category_notice) {
@ -92,7 +93,7 @@ class BoardController extends AdminController
return $entity;
}
//Update관련
protected function update_process($entity)
protected function update_process($entity): BoardEntity
{
$entity = parent::update_process($entity);
if ($entity->category == $this->_category_notice) {
@ -101,7 +102,7 @@ class BoardController extends AdminController
return $entity;
}
//Toggle관련
protected function toggle_process($entity)
protected function toggle_process($entity): BoardEntity
{
$entity = parent::toggle_process($entity);
if ($entity->category == $this->_category_notice) {
@ -110,7 +111,7 @@ class BoardController extends AdminController
return $entity;
}
//Delete 관련
protected function delete_process($entity)
protected function delete_process($entity): BoardEntity
{
$entity = parent::delete_process($entity);
if ($entity->category->$this->_category_notice) {

View File

@ -12,7 +12,7 @@ class CategoryController extends AdminController
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->_model = new CategoryModel();
$this->initModel(new CategoryModel());
$this->_viewDatas["className"] = "Category";
$this->_viewPath .= strtolower($this->_viewDatas["className"]);
$this->_viewDatas["title"] = lang($this->_viewDatas["className"] . ".title");

View File

@ -12,7 +12,7 @@ class DeviceController extends AdminController
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->_model = new DeviceModel();
$this->initModel(new DeviceModel());
$this->_viewDatas["className"] = "Device";
$this->_viewPath .= strtolower($this->_viewDatas["className"]);
$this->_viewDatas["title"] = lang($this->_viewDatas["className"] . ".title");
@ -51,7 +51,7 @@ class DeviceController extends AdminController
$viewDatas = [];
$viewDatas['device'] = [];
$viewDatas['device']['categorys'] = ['server', 'cpu', 'memory', 'disk', 'nic', 'publicip', 'os'];
$viewDatas['device']['options'] = $this->_model->getOptions(['category' => $category]);
$viewDatas['device']['options'] = $this->getModel()->getOptions(['category' => $category]);
return view($this->_viewPath . '/' . $category, ['cellDatas' => $viewDatas]);
}
}

View File

@ -2,6 +2,7 @@
namespace App\Controllers\Admin;
use App\Entities\OrderEntity;
use App\Models\OrderModel;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
@ -12,7 +13,7 @@ class OrderController extends AdminController
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->_model = new OrderModel();
$this->initModel(new OrderModel());
$this->_viewDatas['className'] = 'Order';
$this->_viewPath .= strtolower($this->_viewDatas['className']);
$this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title');
@ -48,7 +49,7 @@ class OrderController extends AdminController
}
//가격이나,할인가,수량 변경했을경우 다시 계산해서 Price에 넣기위해
protected function update_process($entity)
protected function update_process($entity): OrderEntity
{
//가격이나,할인가,수량 변경했을경우 다시 계산해서 결제금액(price)에 넣기위해
$this->_viewDatas['fieldDatas']['price'] =

View File

@ -3,7 +3,9 @@
namespace App\Controllers\Admin;
use App\Controllers\Trait\UpDownloadTrait;
use App\Entities\ProductEntity;
use App\Models\DeviceModel;
use App\Models\ProductDeviceModel;
use App\Models\ProductModel;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
@ -13,10 +15,11 @@ class ProductController extends AdminController
{
use UpDownloadTrait;
private $_deviceModel = null;
private $_productDeviceModel = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->_model = new ProductModel();
$this->initModel(new ProductModel());
$this->_viewDatas['className'] = 'Product';
$this->_viewPath .= strtolower($this->_viewDatas['className']);
$this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title');
@ -28,6 +31,10 @@ class ProductController extends AdminController
{
return $this->_deviceModel = $this->_deviceModel ?: new DeviceModel();
}
final protected function getProductDeviceModel(): ProductDeviceModel
{
return $this->_productDeviceModel = $this->_productDeviceModel ?: new ProductDeviceModel();
}
public function getFields(string $action = ""): array
{
@ -85,7 +92,7 @@ class ProductController extends AdminController
}
//가상서버
protected function virtual_process()
protected function virtual_process(ProductEntity $entity): array
{
//가상서버정보
$protudctDatas = array(
@ -121,40 +128,36 @@ class ProductController extends AdminController
}
$protudctDatas['name'] = implode(" ", $titles);
$protudctDatas['content'] = implode("\n", $titles);
$product = $this->_model->create($protudctDatas);
$product = $this->getModel()->create($protudctDatas);
return array();
//return $this->add_procedure($product, 1, $this->_viewDatas['fieldDatas']['paymentday']);
}
//실서버
protected function beremetal_process()
protected function beremetal_process(ProductEntity $entity, array $devices = []): array
{
//상품정보가져오기
$product = $this->_model->getEntity([$this->_model->getPrimaryKey() => $this->_viewDatas['fieldDatas']['product_uid']]);
//재고수 비교
if ($product->stock < $this->_viewDatas['fieldDatas']['quantity']) {
throw new \Exception("구매수량이 너무 많습니다.\n구매수량:{$this->_viewDatas['fieldDatas']['quantity']}개, 남은 재고수량:{$product->stock}");
$fields = ['server', 'cpu', 'memory', 'disk', 'nic', 'publicip', 'os'];
//fieldData 적용
foreach ($fields as $field) {
$formDatas = ['product_uid' => $entity->getPrimaryKey()];
$formDatas['device_uid'] = $this->request->getPost($field);
$formDatas['device_cnt'] = $this->request->getPost($field . "_cnt") ?: 1;
if (!is_null($formDatas['device_uid'])) {
$devices[$field] = $this->getProductDeviceModel()->create($formDatas);
}
//구매 금액 비교
$price = $product->price * $this->_viewDatas['fieldDatas']['quantity'];
if ($price != $this->_viewDatas['fieldDatas']['price']) {
throw new \Exception("실 상품금액{$price} 와 구매금액{$this->_viewDatas['fieldDatas']['price']}이 서로 다릅니다.");
}
//결제방식이 월이용권이면 결제일 확인
$paymentDay = null;
if ($product->type == 'rental') {
$paymentDay = $this->request->getVar('paymentday') ?: throw new \Exception("월이용권 상품의 경우는 매월 결제일을 지정해주셔야합니다.");
}
//return $this->add_procedure($product, $this->_viewDatas['fieldDatas']['quantity'], $paymentDay);
dd($devices);
return $devices;
}
//주문처리
protected function device_process()
protected function device_process(ProductEntity $entity): array
{
switch ($this->_viewDatas['fieldDatas']['category']) {
case 'virtual':
return $this->virtual_process();
return $this->virtual_process($entity);
break;
case 'beremetal':
return $this->beremetal_process();
return $this->beremetal_process($entity);
break;
default:
throw new \Exception($this->_viewDatas['fieldDatas']['category'] . "는 알수없는 상품 구분입니다. 다시 확인 부탁드립니다.");
@ -163,20 +166,22 @@ class ProductController extends AdminController
}
//Insert관련
protected function insert_validate()
protected function insert_process(): ProductEntity
{
parent::insert_validate();
}
protected function insert_process()
{
$this->device_process();
$this->_viewDatas['fieldDatas']['price'] = $this->calculate_price();
return parent::insert_process();
$entity = parent::insert_process();
$entity->setDevices($this->device_process($entity));
return $entity;
}
//Update관련
protected function update_process($entity)
protected function update_process($entity): ProductEntity
{
$this->_viewDatas['fieldDatas']['price'] = $this->calculate_price();
return parent::update_process($entity);
$entity = parent::update_process($entity);
foreach ($this->getProductDeviceModel()->getEntitys(['product_uid' => $entity->getPrimaryKey()]) as $productDeviceEntity) {
$this->getProductDeviceModel()->delete($productDeviceEntity);
}
$entity->setDevices($this->device_process($entity));
return $entity;
}
}

View File

@ -12,7 +12,7 @@ class SitepageController extends AdminController
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->_model = new SitepageModel();
$this->initModel(new SitepageModel());
$this->_viewDatas['className'] = 'Sitepage';
$this->_viewPath .= strtolower($this->_viewDatas['className']);
$this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title');

View File

@ -12,7 +12,7 @@ class UserController extends AdminController
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->_model = new UserModel();
$this->initModel(new UserModel());
$this->_viewDatas['className'] = 'User';
$this->_viewPath .= strtolower($this->_viewDatas['className']);
$this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title');

View File

@ -12,7 +12,7 @@ class UserSNSController extends AdminController
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->_model = new UserSNSModel();
$this->initModel(new UserSNSModel());
$this->_viewDatas['className'] = 'UserSNS';
$this->_viewPath .= strtolower($this->_viewDatas['className']);
$this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title');

View File

@ -2,15 +2,16 @@
namespace App\Controllers;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
abstract class CommonController extends BaseController
{
private $_model = null;
protected $helpers = ['Common'];
protected $_validation = null;
protected $_model = null;
protected $_session = null;
protected $_viewPath = '';
protected $_viewDatas = array();
@ -34,15 +35,25 @@ abstract class CommonController extends BaseController
$this->_viewDatas['currentRoles'] = is_array($currentRoles) ? $currentRoles : [DEFAULTS["ROLE"]];
}
}
abstract public function getFields(string $action): array;
abstract public function getFieldFilters(): array;
final protected function initModel($model)
{
$this->_model = $model;
}
final protected function getModel()
{
if ($this->_model === null) {
throw new \Exception("Model이 지정되지 않았습니다.");
}
return $this->_model;
}
//Field별 Rule용
protected function getFieldRule(string $field, array $rules, string $action = ""): array
{
switch ($field) {
default:
$rules = $this->_model->getFieldRule($field, $rules, $action);
$rules = $this->getModel()->getFieldRule($field, $rules, $action);
break;
}
return $rules;
@ -59,19 +70,6 @@ abstract class CommonController extends BaseController
{
return $this->getFieldFilters();
}
//Field별 Form Option용
public function getFieldFormOption(string $field): array
{
switch ($field) {
default:
$options = $this->_model->getFieldFOrmOption($field);
break;
}
if (!is_array($options)) {
throw new \Exception(__FUNCTION__ . "에서 {$this->_viewDatas['className']}의 Field:{$field}의 FormOptionData가 array가 아닙니다.\n" . var_export($options, true));
}
return $options;
}
final public function getFieldFormOptions(array $fields): array
{
$fieldFormOptions = array();
@ -79,7 +77,7 @@ abstract class CommonController extends BaseController
if (!is_string($field)) {
throw new \Exception(__FUNCTION__ . "에서 {$this->_viewDatas['className']}의 Field:{$field}가 string 아닙니다.\n" . var_export($fields, true));
}
$fieldFormOptions[$field] = $this->getFieldFormOption($field);
$fieldFormOptions[$field] = $this->getModel()->getFieldFormOption($field);
}
return $fieldFormOptions;
}
@ -152,23 +150,23 @@ abstract class CommonController extends BaseController
}
protected function insert_process()
{
return $this->_model->create($this->_viewDatas['fieldDatas']);
return $this->getModel()->create($this->_viewDatas['fieldDatas']);
}
final public function insert()
{
//Transaction 시작
$this->_model->transStart();
$this->getModel()->transStart();
try {
$this->action_init(['action' => __FUNCTION__]);
$this->insert_validate();
$entity = $this->insert_process();
//Transaction Commit
$this->_model->transComplete();
$this->getModel()->transComplete();
$this->_session->setFlashdata("return_message", "{$this->_viewDatas['title']}에서 {$entity->getTitle()}" . __FUNCTION__ . " 완료하였습니다.");
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
} catch (\Exception $e) {
//Transaction Rollback
$this->_model->transRollback();
$this->getModel()->transRollback();
log_message("error", $e->getMessage());
$this->_session->setFlashdata("return_message", "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage());
$this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']);
@ -186,7 +184,7 @@ abstract class CommonController extends BaseController
{
try {
$this->action_init(['action' => __FUNCTION__]);
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$entity = $this->getModel()->getEntity([$this->getModel()->getPrimaryKey() => $uid]);
$this->_viewDatas['entity'] = $this->update_form_process($entity);
helper(['form']);
$this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']);
@ -226,24 +224,24 @@ abstract class CommonController extends BaseController
}
protected function update_process($entity)
{
return $this->_model->modify($entity, $this->_viewDatas['fieldDatas']);
return $this->getModel()->modify($entity, $this->_viewDatas['fieldDatas']);
}
final public function update($uid)
{
//Transaction 시작
$this->_model->transStart();
$this->getModel()->transStart();
try {
$this->action_init(['action' => __FUNCTION__]);
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$entity = $this->getModel()->getEntity([$this->getModel()->getPrimaryKey() => $uid]);
$this->update_validate($entity);
$entity = $this->update_process($entity);
//Transaction Commit
$this->_model->transComplete();
$this->getModel()->transComplete();
$this->_session->setFlashdata("return_message", "{$this->_viewDatas['title']}에서 {$entity->getTitle()}" . __FUNCTION__ . " 완료하였습니다.");
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
} catch (\Exception $e) {
//Transaction Rollback
$this->_model->transRollback();
$this->getModel()->transRollback();
log_message("error", $e->getMessage());
$this->_session->setFlashdata("return_message", "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage());
$this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']);
@ -254,7 +252,7 @@ abstract class CommonController extends BaseController
//Reply관련
protected function reply_form_process($entity)
{
$titleField = $this->_model->getTitleField();
$titleField = $this->getModel()->getTitleField();
$entity->$titleField = "RE: " . $entity->$titleField;
$this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []];
return $entity;
@ -263,7 +261,7 @@ abstract class CommonController extends BaseController
{
try {
$this->action_init(['action' => __FUNCTION__]);
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$entity = $this->getModel()->getEntity([$this->getModel()->getPrimaryKey() => $uid]);
$this->_viewDatas['entity'] = $this->reply_form_process($entity);
helper(['form']);
$this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']);
@ -289,24 +287,24 @@ abstract class CommonController extends BaseController
}
protected function reply_process($entity)
{
return $this->_model->reply($entity, $this->_viewDatas['fieldDatas']);
return $this->getModel()->reply($entity, $this->_viewDatas['fieldDatas']);
}
final public function reply($uid)
{
//Transaction 시작
$this->_model->transStart();
$this->getModel()->transStart();
try {
$this->action_init(['action' => __FUNCTION__]);
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$entity = $this->getModel()->getEntity([$this->getModel()->getPrimaryKey() => $uid]);
$this->reply_validate($entity);
$entity = $this->reply_process($entity);
//Transaction Commit
$this->_model->transComplete();
$this->getModel()->transComplete();
$this->_session->setFlashdata("return_message", "{$this->_viewDatas['title']}에서 {$entity->getTitle()}" . __FUNCTION__ . " 완료하였습니다.");
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
} catch (\Exception $e) {
//Transaction Rollback
$this->_model->transRollback();
$this->getModel()->transRollback();
log_message("error", $e->getMessage());
$this->_session->setFlashdata("return_message", "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage());
$this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']);
@ -331,24 +329,24 @@ abstract class CommonController extends BaseController
}
protected function toggle_process($entity)
{
return $this->_model->modify($entity, $this->_viewDatas['fieldDatas']);
return $this->getModel()->modify($entity, $this->_viewDatas['fieldDatas']);
}
final public function toggle($uid, string $field)
{
//Transaction 시작
$this->_model->transStart();
$this->getModel()->transStart();
try {
$this->action_init(['action' => __FUNCTION__, 'fields' => [$field]]);
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$entity = $this->getModel()->getEntity([$this->getModel()->getPrimaryKey() => $uid]);
$this->toggle_validate($entity);
$entity = $this->toggle_process($entity);
//Transaction Commit
$this->_model->transComplete();
$this->getModel()->transComplete();
$this->_session->setFlashdata("return_message", "{$this->_viewDatas['title']}에서 {$entity->getTitle()}" . __FUNCTION__ . " 완료하였습니다.");
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
} catch (\Exception $e) {
//Transaction Rollback
$this->_model->transRollback();
$this->getModel()->transRollback();
log_message("error", $e->getMessage());
$this->_session->setFlashdata("return_message", "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage());
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
@ -371,7 +369,7 @@ abstract class CommonController extends BaseController
}
protected function batchjob_process($entity)
{
return $this->_model->modify($entity, $this->_viewDatas['fieldDatas']);
return $this->getModel()->modify($entity, $this->_viewDatas['fieldDatas']);
}
final public function batchjob()
{
@ -379,7 +377,7 @@ abstract class CommonController extends BaseController
$entitys = array();
$batchjobs = array();
//Transaction 시작
$this->_model->transStart();
$this->getModel()->transStart();
try {
//fields 해당하는 field중 선택된 값이 있는경우만 fields로 정의
$fields = array();
@ -396,10 +394,10 @@ abstract class CommonController extends BaseController
$cnt = 1;
foreach ($uids as $uid) {
try {
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$entity = $this->getModel()->getEntity([$this->getModel()->getPrimaryKey() => $uid]);
$this->batchjob_validate($entity);
$entity = $this->batchjob_process($entity);
array_push($entitys, $this->_model->modify($entity, $this->_viewDatas['fieldDatas']));
array_push($entitys, $this->getModel()->modify($entity, $this->_viewDatas['fieldDatas']));
array_push($batchjobs, "{$cnt}. {$uid}->{$entity->getTitle()}는 완료.");
} catch (\Exception $e) {
array_push($batchjobs, "{$cnt}. {$uid}는 실패.");
@ -407,7 +405,7 @@ abstract class CommonController extends BaseController
$cnt++;
}
//Transaction Commit
$this->_model->transComplete();
$this->getModel()->transComplete();
$this->_session->setFlashdata(
"return_message",
sprintf("%s에서 총:%s개의 %s 완료하였습니다.", $this->_viewDatas['title'], count($entitys), __FUNCTION__,),
@ -415,7 +413,7 @@ abstract class CommonController extends BaseController
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
} catch (\Exception $e) {
//Transaction Rollback
$this->_model->transRollback();
$this->getModel()->transRollback();
log_message("error", $e->getMessage());
$this->_session->setFlashdata(
"return_message",
@ -437,27 +435,27 @@ abstract class CommonController extends BaseController
//Delete 관련
protected function delete_process($entity)
{
if (!$this->_model->delete($entity->getPrimaryKey())) {
log_message("error", __FUNCTION__ . "에서 호출:" . $this->_model->getLastQuery());
log_message("error", implode("\n", $this->_model->errors()));
throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->_model->errors(), true));
if (!$this->getModel()->delete($entity->getPrimaryKey())) {
log_message("error", __FUNCTION__ . "에서 호출:" . $this->getModel()->getLastQuery());
log_message("error", implode("\n", $this->getModel()->errors()));
throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->getModel()->errors(), true));
}
return $entity;
}
final public function delete($uid)
{
//Transaction 시작
$this->_model->transStart();
$this->getModel()->transStart();
try {
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$entity = $this->getModel()->getEntity([$this->getModel()->getPrimaryKey() => $uid]);
$this->delete_process($entity);
//Transaction Commit
$this->_model->transComplete();
$this->getModel()->transComplete();
$this->_session->setFlashdata("return_message", "{$this->_viewDatas['title']}에서 {$entity->getTitle()}" . __FUNCTION__ . " 완료하였습니다.");
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
} catch (\Exception $e) {
//Transaction Rollback
$this->_model->transRollback();
$this->getModel()->transRollback();
log_message("error", $e->getMessage());
$this->_session->setFlashdata("return_message", "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage());
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
@ -474,7 +472,7 @@ abstract class CommonController extends BaseController
{
try {
$this->action_init(['action' => __FUNCTION__]);
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$entity = $this->getModel()->getEntity([$this->getModel()->getPrimaryKey() => $uid]);
$this->_viewDatas['entity'] = $this->view_process($entity);
helper(['form']);
$this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']);
@ -494,24 +492,22 @@ abstract class CommonController extends BaseController
//조건절 처리
foreach ($this->_viewDatas['fieldFilters'] as $field) {
$value = $this->request->getVar($field);
$this->_model->setIndexFieldFilter($field, $this->request->getVar($field) ?: DEFAULTS['EMPTY']);
$this->getModel()->setIndexFieldFilter($field, $this->request->getVar($field) ?: DEFAULTS['EMPTY']);
}
//검색어 처리
$this->_viewDatas['word'] = $this->request->getVar('word') ?: DEFAULTS['EMPTY'];
$this->_model->setIndexWordFilter($this->_viewDatas['word']);
$this->getModel()->setIndexWordFilter($this->_viewDatas['word']);
//검색일 처리
$this->_viewDatas['start'] = $this->request->getVar('start') ?: DEFAULTS['EMPTY'];
$this->_viewDatas['end'] = $this->request->getVar('end') ?: DEFAULTS['EMPTY'];
$this->_model->setIndexDateFilter($this->_viewDatas['start'], $this->_viewDatas['end']);
$this->getModel()->setIndexDateFilter($this->_viewDatas['start'], $this->_viewDatas['end']);
}
//Totalcount 처리
protected function index_total(): int
{
$this->index_process();
$this->index_condition();
$total = $this->_model->countAllResults();
// echo dd($this->_model->getLastQuery());
return $total;
return $this->getModel()->countAllResults();
}
//PageNation 처리
protected function index_pagination($pager_group = 'default', int $segment = 0, $template = 'bootstrap_full'): string
@ -528,7 +524,7 @@ abstract class CommonController extends BaseController
// 2.app/Config/Pager.php/$templates에 'bootstrap_full => 'Pagers\bootstrap_full',
// 'bootstrap_simple' => 'Pagers\bootstrap_simple', 추가
$pager = \Config\Services::pager();
// $this->_model->paginate($this->_viewDatas['per_page'], $pager_group, $this->_viewDatas['page'], $segment);
// $this->getModel()->paginate($this->_viewDatas['per_page'], $pager_group, $this->_viewDatas['page'], $segment);
$pager->makeLinks(
$this->_viewDatas['page'],
$this->_viewDatas['per_page'],
@ -545,7 +541,7 @@ abstract class CommonController extends BaseController
{
$this->index_condition();
if (array_key_exists('page', $this->_viewDatas)) {
$this->_model->limit(
$this->getModel()->limit(
$this->_viewDatas['per_page'],
$this->_viewDatas['page'] * $this->_viewDatas['per_page'] - $this->_viewDatas['per_page']
);
@ -557,7 +553,7 @@ abstract class CommonController extends BaseController
if ($this->_viewDatas['order_field'] && $this->_viewDatas['order_value']) {
$orderBy = ["{$this->_viewDatas['order_field']} {$this->_viewDatas['order_value']}"];
}
return $this->_model->getEntitys([], $orderBy);
return $this->getModel()->findAll();
}
public function index()
{
@ -575,7 +571,7 @@ abstract class CommonController extends BaseController
$this->_viewDatas['pagination'] = $this->index_pagination();
//모델 처리
$this->_viewDatas['entitys'] = $this->index_entitys();
// dd($this->_model->getLastQuery());
// dd($this->getModel()->getLastQuery());
//setting return_url to session flashdata
$this->_session->setFlashdata(SESSION_NAMES['RETURN_URL'], current_url() . '?' . $this->request->getUri()->getQuery() ?: "");
return view($this->_viewPath . '/index' . $this->request->getVar('v') ?: '', ['viewDatas' => $this->_viewDatas]);
@ -651,7 +647,7 @@ abstract class CommonController extends BaseController
final public function download(string $field, $uid)
{
try {
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$entity = $this->getModel()->getEntity([$this->getModel()->getPrimaryKey() => $uid]);
return $this->download_process($field, $entity);
} catch (\Exception $e) {
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/")->with('return_message', $e->getMessage());

View File

@ -21,7 +21,7 @@ class BillingController extends FrontController
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->_model = new BillingModel();
$this->initModel(new BillingModel());
$this->_viewDatas['className'] = 'Billing';
$this->_viewPath .= strtolower($this->_viewDatas['className']);
$this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title');
@ -152,7 +152,7 @@ class BillingController extends FrontController
protected function index_condition()
{
//사용자정보(user_uid)에 맞는 Biiling정보 가져오기
$this->_model->where('user_uid', $this->_session->get(SESSION_NAMES['AUTH'])[AUTH_FIELDS['ID']]);
$this->getModel()->where('user_uid', $this->_session->get(SESSION_NAMES['AUTH'])[AUTH_FIELDS['ID']]);
parent::index_condition();
}

View File

@ -65,22 +65,6 @@ class CardController extends BillingController
{
return parent::getFieldBatchFilters();
}
//Field별 Form Option용
public function getFieldFormOption(string $field): array
{
switch ($field) {
case 'card_quota':
$options = lang($this->_viewDatas['className'] . '.CARD_QUOTA');
break;
default:
$options = parent::getFieldFormOption($field);
break;
}
if (!is_array($options)) {
throw new \Exception(__FUNCTION__ . "에서 {$this->_viewDatas['className']}의 Field:{$field}의 FormOptionData가 array가 아닙니다.\n" . var_export($options, true));
}
return $options;
}
//Field별 Form Datas 처리용
protected function getFieldFormData(string $field, $entity = null): array
{

View File

@ -12,7 +12,7 @@ class BoardController extends FrontController
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->_model = new BoardModel();
$this->initModel(new BoardModel());
$this->_viewDatas['className'] = 'Board';
$this->_viewPath .= strtolower($this->_viewDatas['className']);
$this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title');
@ -104,7 +104,7 @@ class BoardController extends FrontController
//권한체크
$this->isRole('view');
//조회수 올리기
$entity = $this->_model->addViewCount($entity);
$entity = $this->getModel()->addViewCount($entity);
return parent::view_process($entity);
}
//Index관련
@ -119,8 +119,8 @@ class BoardController extends FrontController
//Category 및 Status 조건추가
protected function index_condition()
{
$this->_model->where("category", $this->_viewDatas['currentCategory']->getPrimaryKey());
$this->_model->where("status", DEFAULTS['STATUS']);
$this->getModel()->where("category", $this->_viewDatas['currentCategory']->getPrimaryKey());
$this->getModel()->where("status", DEFAULTS['STATUS']);
parent::index_condition();
}
//Download관련

View File

@ -23,10 +23,14 @@ abstract class FrontController extends CommonController
$this->_viewDatas['category'] = false;
}
final protected function getCategoryModel(): CategoryModel
final public function getCategoryModel()
{
return $this->_categoryModel = $this->_categoryModel ?: new CategoryModel();
if ($this->_categoryModel === null) {
$this->_categoryModel = new CategoryModel();
}
return $this->_categoryModel;
}
//권한체크
protected function isRole($action)
{

View File

@ -3,6 +3,7 @@
namespace App\Controllers\Front;
use App\Controllers\Trait\CartTrait;
use App\Entities\OrderEntity;
use App\Models\OrderModel;
use App\Models\ProductModel;
use CodeIgniter\HTTP\RequestInterface;
@ -17,7 +18,7 @@ class OrderController extends FrontController
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->_model = new OrderModel();
$this->initModel(new OrderModel());
$this->_viewDatas['className'] = 'Order';
$this->_viewPath .= strtolower($this->_viewDatas['className']);
$this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title');
@ -148,7 +149,7 @@ class OrderController extends FrontController
}
//주문처리
protected function insert_process()
protected function insert_process(): OrderEntity
{
switch ($this->_viewDatas['fieldDatas']['category']) {
case 'virtual':
@ -184,12 +185,12 @@ class OrderController extends FrontController
$uids = $this->_session->get(SESSION_NAMES['CART']) ?: array('NONE');
//또는 Login했으면 사용자정보(user_uid)에 맞는 Order정보 가져오기
if ($this->_session->get(SESSION_NAMES['ISLOGIN'])) {
$this->_model->where('user_uid', $this->_session->get(SESSION_NAMES['AUTH'])[AUTH_FIELDS['ID']]);
$this->getModel()->where('user_uid', $this->_session->get(SESSION_NAMES['AUTH'])[AUTH_FIELDS['ID']]);
if (count($uids)) {
$this->_model->orWhereIn('uid', $uids);
$this->getModel()->orWhereIn('uid', $uids);
}
} elseif (count($uids)) {
$this->_model->whereIn('uid', $uids);
$this->getModel()->whereIn('uid', $uids);
}
parent::index_condition();
}

View File

@ -12,7 +12,7 @@ class ProductController extends FrontController
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->_model = new ProductModel();
$this->initModel(new ProductModel());
$this->_viewDatas['className'] = 'Product';
$this->_viewPath .= strtolower($this->_viewDatas['className']);
$this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title');
@ -53,7 +53,7 @@ class ProductController extends FrontController
//권한체크
$this->isRole('view');
//조회수 올리기
$entity = $this->_model->addViewCount($entity);
$entity = $this->getModel()->addViewCount($entity);
return parent::view_process($entity);
}
//Index관련
@ -68,8 +68,8 @@ class ProductController extends FrontController
//Category 및 Status 조건추가
protected function index_condition()
{
$this->_model->where("category", $this->_viewDatas['currentCategory']->getPrimaryKey());
$this->_model->where("status", DEFAULTS['STATUS']);
$this->getModel()->where("category", $this->_viewDatas['currentCategory']->getPrimaryKey());
$this->getModel()->where("status", DEFAULTS['STATUS']);
parent::index_condition();
}
}

View File

@ -12,7 +12,7 @@ class SitepageController extends FrontController
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->_model = new SitepageModel();
$this->initModel(new SitepageModel());
$this->_viewDatas['className'] = 'Sitepage';
$this->_viewPath .= strtolower($this->_viewDatas['className']);
$this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title');
@ -56,8 +56,8 @@ class SitepageController extends FrontController
//Category 및 Status 조건추가
protected function index_condition()
{
$this->_model->where("category", $this->_viewDatas['currentCategory']->getPrimaryKey());
$this->_model->where("status", DEFAULTS['STATUS']);
$this->getModel()->where("category", $this->_viewDatas['currentCategory']->getPrimaryKey());
$this->getModel()->where("status", DEFAULTS['STATUS']);
parent::index_condition();
}
}

View File

@ -15,7 +15,7 @@ class UserController extends FrontController
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->_model = new UserModel();
$this->initModel(new UserModel());
$this->_viewDatas['className'] = 'User';
$this->_viewPath .= strtolower($this->_viewDatas['className']);
$this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title');
@ -117,7 +117,7 @@ class UserController extends FrontController
//사용자 UID 조건추가
protected function index_condition()
{
$this->_model->where("uid", $this->_viewDatas['auth'][AUTH_FIELDS['ID']]);
$this->getModel()->where("uid", $this->_viewDatas['auth'][AUTH_FIELDS['ID']]);
parent::index_condition();
}

View File

@ -0,0 +1,19 @@
<?php
namespace App\Entities;
class ProductDeviceEntity extends BaseEntity
{
protected $datamap = [];
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
protected $casts = [];
//기본기능
final public function getTitle(): string
{
return $this->attributes['product_uid'];
}
//추가기능
}

View File

@ -7,6 +7,7 @@ class ProductEntity extends BaseEntity
protected $datamap = [];
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
protected $casts = [];
private $_devices = [];
//기본기능
public function getTitle(): string
@ -41,4 +42,12 @@ class ProductEntity extends BaseEntity
}
return $price;
}
public function getDevices(): array
{
return $this->_devices;
}
public function setDevices(array $devices)
{
$this->_devices = $devices;
}
}

View File

@ -27,7 +27,7 @@ function getFieldForm_ProductHelper($field, $value, array $viewDatas, array $att
// return implode("&nbsp;", $checkboxs);
break;
case 'device':
return sprintf("<div id='device'>%s</div>", view_cell('ProductCell::beremetal'));
return sprintf("<div id='device'>%s</div>", view_cell('ProductCell::device', $viewDatas));
break;
case 'title':
case 'name':

View File

@ -16,10 +16,11 @@ abstract class BaseHierarchyModel extends BaseModel
abstract public function getContentField();
abstract public function reply($parent_entity, array $formDatas): BaseEntity;
public function getEntitys(array $conditions = array(), array $orderBys = array()): array
public function getEntitys(array $conditions = [], array $entitys = []): array
{
$orderBys = ["grpno DESC", "grporder ASC", ...$orderBys];
return parent::getEntitys($conditions, $orderBys);
$this->orderBy("grpno DESC");
$this->orderBY("grporder ASC");
return parent::getEntitys($conditions, $entitys);
}
public function getSiblingEntitys($entity)
{

View File

@ -3,6 +3,7 @@
namespace App\Models;
use App\Entities\BaseEntity;
use CodeIgniter\Entity\Entity;
use CodeIgniter\Model;
abstract class BaseModel extends Model
@ -61,7 +62,6 @@ abstract class BaseModel extends Model
$this->_validation = \Config\Services::validation();
}
abstract public function getTitleField(): string;
abstract public function getEntity($conditions): BaseEntity;
final protected function getClassName(): string
{
@ -85,14 +85,6 @@ abstract class BaseModel extends Model
{
return $this->primaryKey;
}
public function getEntitys(array $conditions = array(), array $orderBys = array()): array
{
//dd($orderBys);
foreach ($orderBys as $orderBy) {
$this->orderBy($orderBy);
}
return $this->where($conditions)->findAll();
}
final public function getUUID()
{
$randomBytes = bin2hex(random_bytes(32));
@ -163,11 +155,34 @@ abstract class BaseModel extends Model
}
return $this->_validation;
}
//Entity배열
public function getEntity(array $conditions = [])
{
foreach ($conditions as $field => $value) {
$this->where($field, $value);
}
return $this->first() ?: throw new \Exception(__FUNCTION__ . "에서 {$this->getClassName()}의 해당 데이터가 없습니다.");
}
public function getEntitys(array $conditions = [], array $entitys = []): array
{
foreach ($conditions as $field => $value) {
$this->where($field, $value);
}
foreach ($this->findAll() as $entity) {
$entitys[$entity->getPrimaryKey()] = $entity;
}
return $entitys;
}
//Field별 Form Option용
public function getOptionLabel($entity)
{
return $entity->getTitle();
}
public function getOptions(array $conditions = array(), $options = array()): array
{
foreach ($this->getEntitys($conditions) as $entity) {
$options[$entity->getPrimaryKey()] = $entity->getTitle();
foreach ($this->getEntitys($conditions, $options) as $entity) {
$options[$entity->getPrimaryKey()] = $this->getOptionLabel($entity);
}
return $options;
}
@ -200,13 +215,6 @@ abstract class BaseModel extends Model
protected function changeFormData(string $action, string $field, array $formDatas, $entity): BaseEntity
{
switch ($field) {
case $this->primaryKey:
//primaryKey가 수동입력이고 추가(Reply도 결국엔 create_process를 상용)시에만
if ($action == 'create' && !$this->useAutoIncrement) {
$pk = $this->primaryKey;
$entity->$pk = $this->getUUID();
}
break;
case "user_uid": //입력데이터로 있을시 관리툴에서 (사용자,등)추가, 없을시는 입력의 경우에만 자동(장바구니,등)으로 추가
if (array_key_exists($field, $formDatas) && !is_null($formDatas[$field])) {
//관리툴 USERSNS에서 사용자 연동 시 추가기능등에 사용
@ -236,32 +244,19 @@ abstract class BaseModel extends Model
return $entity;
}
final protected function save_process($entity)
{
// echo var_export($entity, true);
// exit;
if ($entity->hasChanged()) {
if (!$this->save($entity)) {
log_message("error", __FUNCTION__ . "에서 호출:" . $this->getLastQuery());
log_message("error", implode("\n", $this->errors()));
throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . $this->getLastQuery() . "\n" . var_export($this->errors(), true));
}
} else {
throw new \Exception(__FUNCTION__ . " 오류 발생.\n 기존정보와 동일하여 수정되지 않았습니다.");
}
return $entity;
}
protected function create_process($entity, array $formDatas)
{
foreach ($this->allowedFields as $field) {
$entity = $this->changeFormData('create', $field, $formDatas, $entity);
}
$entity = $this->save_process($entity);
//primaryKey가 자동입력이면
if ($this->useAutoIncrement) {
$pk = $this->primaryKey;
$entity->$pk = $this->insertID();
//primaryKey가 수동입력이면
if (!$this->useAutoIncrement) {
// $pk = $this->primaryKey;
// $entity->$pk = $this->getUUID();
//위 형식을 아래와같이 변경
$entity->$$this->primaryKey = $this->getUUID();
}
$this->insert($entity);
return $entity;
}
final protected function modify_process($entity, array $formDatas)
@ -270,7 +265,9 @@ abstract class BaseModel extends Model
$entity = $this->changeFormData('modify', $field, $formDatas, $entity);
}
$entity->updated_at = time();
return $this->save_process($entity);
//dd($entity);
$this->update($entity->getPrimaryKey(), $entity);
return $entity;
}
//Index관련
@ -283,7 +280,7 @@ abstract class BaseModel extends Model
public function setIndexWordFilter(string $word): void
{
if ($word !== DEFAULTS['EMPTY']) {
$this->orLike($this->getTitleField(), $word, "both");
$this->like($this->getTitleField(), $word, "both");
}
}
public function setIndexDateFilter($start, $end): void
@ -292,8 +289,4 @@ abstract class BaseModel extends Model
$this->where(["created_at >={$start}", "created_at <={$end}"]);
}
}
public function setIndexOrderBy(string $field, string $order): void
{
$this->orderBy($field, $order);
}
}

View File

@ -63,9 +63,9 @@ class BillingModel extends BaseModel
}
return $options;
}
public function getEntity($conditions): BillingEntity
public function getEntity(array $conditions = []): BillingEntity
{
return $this->where($conditions)->first() ?: throw new \Exception(__FUNCTION__ . "에서 {$this->getClassName()}의 해당 데이터가 없습니다.");
return parent::getEntity($conditions);
}
public function create(array $formDatas): BillingEntity
{

View File

@ -52,9 +52,9 @@ class BoardModel extends BaseHierarchyModel
}
return $rules;
}
public function getEntity($conditions): BoardEntity
public function getEntity(array $conditions = []): BoardEntity
{
return $this->where($conditions)->first() ?: throw new \Exception(__FUNCTION__ . "에서 {$this->getClassName()}의 해당 데이터가 없습니다.");
return parent::getEntity($conditions);
}
public function create(array $formDatas): BoardEntity
{

View File

@ -67,7 +67,7 @@ class CategoryModel extends BaseHierarchyModel
$old = $entity->getTitle();
$options[$entity->getTitle()] = [];
} else {
$options[$old][$entity->getPrimaryKey()] = $entity->getTitle();
$options[$old][$entity->getPrimaryKey()] = $this->getOptionLabel($entity);
}
}
return $options;
@ -115,9 +115,9 @@ class CategoryModel extends BaseHierarchyModel
return $entity;
}
public function getEntity($conditions): CategoryEntity
public function getEntity(array $conditions = []): CategoryEntity
{
return $this->where($conditions)->first() ?: throw new \Exception(__FUNCTION__ . "에서 {$this->getClassName()}의 해당 데이터가 없습니다.");
return parent::getEntity($conditions);
}
public function create(array $formDatas): CategoryEntity
{

View File

@ -64,19 +64,16 @@ class DeviceModel extends BaseModel
if (!array_key_exists($entity->getCategory(), $options)) {
$options[$entity->getCategory()] = [];
}
$options[$entity->getCategory()][$entity->getPrimaryKey()] = $entity->getTitle();
$options[$entity->getCategory()][$entity->getPrimaryKey()] = $this->getOptionLabel($entity);
}
return $options;
}
public function getEntity($conditions): DeviceEntity
public function getEntitys(array $conditions = array(), $entitys = array()): array
{
return $this->where($conditions)->first() ?: throw new \Exception(__FUNCTION__ . "에서 {$this->getClassName()}의 해당 데이터가 없습니다.");
}
public function getEntitys(array $conditions = array(), array $orderBys = array()): array
{
$orderBys = ["category ASC", "price DESC", ...$orderBys];
return parent::getEntitys($conditions, $orderBys);
$this->orderBy("category ASC");
$this->orderBY("price DESC");
return parent::getEntitys($conditions, $entitys);
}
public function create(array $formDatas): DeviceEntity
{
@ -86,13 +83,4 @@ class DeviceModel extends BaseModel
{
return $this->modify_process($entity, $formDatas);
}
//Index관련
public function setIndexWordFilter(string $word): void
{
if ($word !== DEFAULTS['EMPTY']) {
parent::setIndexWordFilter($word);
$this->orLike("content", $word, "both");
}
}
}

View File

@ -35,9 +35,9 @@ class OrderBillingModel extends BaseModel
}
return $rules;
}
public function getEntity($conditions): OrderBillingEntity
public function getEntity(array $conditions = []): OrderBillingEntity
{
return $this->where($conditions)->first() ?: throw new \Exception(__FUNCTION__ . "에서 {$this->getClassName()}의 해당 데이터가 없습니다.");
return parent::getEntity($conditions);
}
public function create(array $formDatas): OrderBillingEntity
{

View File

@ -72,9 +72,9 @@ class OrderModel extends BaseModel
}
return $options;
}
public function getEntity($conditions): OrderEntity
public function getEntity(array $conditions = []): OrderEntity
{
return $this->where($conditions)->first() ?: throw new \Exception(__FUNCTION__ . "에서 {$this->getClassName()}의 해당 데이터가 없습니다.");
return parent::getEntity($conditions);
}
public function create(array $formDatas): OrderEntity
{

View File

@ -2,31 +2,33 @@
namespace App\Models;
use App\Entities\OrderBillingEntity;
use App\Entities\ProductDeviceEntity;
use App\Entities\ProductEntity;
class OrderBillingModel extends BaseModel
class ProductDeviceModel extends BaseModel
{
protected $table = "tw_orderbilling";
protected $returnType = OrderBillingEntity::class;
protected $table = "tw_product_device";
protected $returnType = ProductDeviceEntity::class;
public function __construct()
{
parent::__construct('Billing');
parent::__construct('ProductDevic');
$this->allowedFields = [
...$this->allowedFields, "order_uid", "billing_uid"
...$this->allowedFields, "product_uid", "device_uid", "device_cnt"
];
$this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),];
}
final public function getTitleField(): string
{
return 'billing_uid';
return 'product_uid';
}
public function getFieldRule(string $field, array $rules, string $action = ""): array
{
switch ($field) {
case "order_uid":
case "product_uid":
case "device_uid":
$rules[$field] = $this->getUUIDFieldRule('required');
break;
case 'billing_uid':
case 'device_cnt':
$rules[$field] = "required|numeric";
break;
default:
@ -35,15 +37,17 @@ class OrderBillingModel extends BaseModel
}
return $rules;
}
public function getEntity($conditions): OrderBillingEntity
public function getEntity(array $conditions = []): ProductDeviceEntity
{
return $this->where($conditions)->first() ?: throw new \Exception(__FUNCTION__ . "에서 {$this->getClassName()}의 해당 데이터가 없습니다.");
return parent::getEntity($conditions);
}
public function create(array $formDatas): OrderBillingEntity
public function create(array $formDatas): ProductDeviceEntity
{
return $this->create_process(new OrderBillingEntity(), $formDatas);
$entity = $this->create_process(new ProductDeviceEntity(), $formDatas);
dd($entity);
return $entity;
}
public function modify(OrderBillingEntity $entity, array $formDatas): OrderBillingEntity
public function modify(ProductDeviceEntity $entity, array $formDatas): ProductDeviceEntity
{
return $this->modify_process($entity, $formDatas);
}

View File

@ -64,9 +64,9 @@ class ProductModel extends BaseModel
return $rules;
}
public function getEntity($conditions): ProductEntity
public function getEntity(array $conditions = []): ProductEntity
{
return $this->where($conditions)->first() ?: throw new \Exception(__FUNCTION__ . "에서 {$this->getClassName()}의 해당 데이터가 없습니다.");
return parent::getEntity($conditions);
}
public function create(array $formDatas): ProductEntity
{

View File

@ -47,9 +47,9 @@ class SitepageModel extends BaseModel
return $rules;
}
public function getEntity($conditions): SitepageEntity
public function getEntity(array $conditions = []): SitePageEntity
{
return $this->where($conditions)->first() ?: throw new \Exception(__FUNCTION__ . "에서 {$this->getClassName()}의 해당 데이터가 없습니다.");
return parent::getEntity($conditions);
}
public function create(array $formDatas): SitepageEntity
{

View File

@ -55,9 +55,9 @@ class UserModel extends BaseModel
}
return $rules;
}
public function getEntity($conditions): UserEntity
public function getEntity(array $conditions = []): UserEntity
{
return $this->where($conditions)->first() ?: throw new \Exception(__FUNCTION__ . "에서 {$this->getClassName()}의 해당 데이터가 없습니다.");
return parent::getEntity($conditions);
}
protected function changeFormData(string $action, string $field, array $formDatas, $entity): UserEntity
{

View File

@ -47,9 +47,9 @@ class UserSNSModel extends BaseModel
}
return $rules;
}
public function getEntity($conditions): UserSNSEntity
public function getEntity(array $conditions = []): UserSNSEntity
{
return $this->where($conditions)->first() ?: throw new \Exception(__FUNCTION__ . "에서 {$this->getClassName()}의 해당 데이터가 없습니다.");
return parent::getEntity($conditions);
}
public function create(array $formDatas): UserSNSEntity
{

View File

@ -3,6 +3,7 @@
<link href="/css/admin/content.css" media="screen" rel="stylesheet" type="text/css" />
<div id="content">
<div class="top container-fluid">
<?= form_open(current_url(), array("method" => "get")) ?>
<nav class="nav">
조건검색:<?php foreach ($viewDatas['fieldFilters'] as $field) : ?><?= getFieldFilter_BoardHelper($field, $viewDatas[$field], $viewDatas) ?><?php endforeach ?>
</nav>

View File

@ -1,24 +0,0 @@
<table class="table table-bordered" style="width: auto;">
<tr>
<?php foreach ($cellDatas['device']['categorys'] as $category) : ?>
<th style="background-color:silver; text-align:center;"><?= lang('Device.CATEGORY.' . $category) . " 선택" ?></th>
<?php endforeach ?>
</tr>
<tr>
<?php foreach ($cellDatas['device']['categorys'] as $category) : ?>
<td>
<?= form_dropdown(
$category,
$cellDatas['device']['options'][$category],
old($category, 0),
[
'id' => $category,
'size' => "6",
'class' => 'vhost_cellDatas',
'onChange' => "calculator()"
]
) ?>
</td>
<?php endforeach ?>
</tr>
</table>

View File

@ -0,0 +1,23 @@
<table class="table table-bordered" style="width: auto;">
<tr>
<?php foreach ($cellDatas['device']['categorys'] as $category) : ?>
<th style="background-color:silver; text-align:center;"><?= lang('Device.CATEGORY.' . $category) . " 선택" ?></th>
<?php endforeach ?>
</tr>
<tr>
<?php foreach ($cellDatas['device']['categorys'] as $category) : ?>
<td>
<?= form_dropdown(
$category,
$cellDatas['device']['options'][$category],
old($category, array_key_exists('entity', $cellDatas) ? $cellDatas['entity']->$category : DEFAULTS['EMPTY']),
[
'id' => $category,
'size' => "6",
'class' => 'vhost_cellDatas'
]
) ?>
</td>
<?php endforeach ?>
</tr>
</table>

View File

@ -1,87 +1,30 @@
<link href="/css/front/virtual_calculator.css" media="screen" rel="stylesheet" type="text/css" />
<script>
function calculator(order_price) {
var parts = Array.from(document.getElementsByClassName("vhost_parts"));
parts.forEach(function(part) { //loop
//console.log(part);
order_price += parseInt((part.getAttribute('cost') - part.getAttribute('sale')) * part.options[part.selectedIndex].value);
document.getElementById('price').value = order_price;
document.getElementById('order_price').textContent = new Intl.NumberFormat().format(order_price);
});
var current = document.getElementById('paymentday');
if (!current.selectedIndex) {
alert("결제일을 선택해주세요");
current.focus();
return false
}
}
</script>
<div id="virtual_calculator">
<?= form_open(URLS['addCart'], [
'method' => 'post',
"onsubmit" => 'return calculator(' . $cellDatas['parts']['virtual']['default']['baserate'] . ')'
]) ?>
<input type="hidden" id="category" name="category" value="virtual">
<input type="hidden" id="price" name="price">
<table>
<thead>
<div class="modal fade device-virtual" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<table class="table table-bordered" style="width: auto;">
<tr>
<th scope="col" colspan="3">가상서버 견적 계산기</th>
<?php foreach ($cellDatas['device']['categorys'] as $category) : ?>
<th style="background-color:silver; text-align:center;"><?= lang('Device.CATEGORY.' . $category) . " 선택" ?></th>
<?php endforeach ?>
</tr>
</thead>
<tbody>
<tr>
<th>기본요금</th>
<?php foreach ($cellDatas['device']['categorys'] as $category) : ?>
<td>
<strong><?= number_format($cellDatas['parts']['virtual']['default']['baserate']) ?>원</strong>
</td>
</tr>
<?php foreach ($cellDatas['parts']['virtual']['category'] as $category => $attrs) : ?>
<tr>
<th><?= $attrs['label'] ?></th>
<td>
<strong class="line-through"><?= number_format($attrs['cost']) ?>원</strong>
<strong class="f-back">할인가 <?= number_format($attrs['cost'] - $attrs['sale']) ?></strong> *
<?= form_dropdown(
$category,
$attrs['options'],
$cellDatas['device']['options'][$category],
old($category, 0),
[
'id' => $category,
'class' => 'vhost_parts',
'cost' => $attrs['cost'],
'sale' => $attrs['sale'],
'onChange' => "calculator(" . $cellDatas['parts']['virtual']['default']['baserate'] . ")"
'size' => "6",
'class' => 'vhost_cellDatas',
'onChange' => "calculator()"
]
) ?>
<?= $attrs['unit'] ?>
</td>
</tr>
<?php endforeach ?>
<tr>
<th>결제일</th>
<td class="column">
<?php $paymentDayOptions = ['' => "결제일 선택"];
for ($i = 1; $i <= 28; $i++) {
$paymentDayOptions[$i] = "매월 {$i}";
}
?>
<?= form_dropdown('paymentday', $paymentDayOptions, old('paymentday', 25), ['id' => 'paymentday']);
?>
</td>
</tr>
<tr>
<th class="none">주문금액</th>
<td class="none" colspan="3">
<span id="order_price">0</span>
<?= form_submit('', '신청', array("class" => "btn btn-outline btn-primary")); ?>
</td>
</tr>
</tbody>
</table>
<?= form_close() ?>
<script type="text/javascript">
window.onload = calculator(<?= $cellDatas['parts']['virtual']['default']['baserate'] ?>);
</script>
<?= $cellDatas['session']->getFlashdata('return_message') ? alert_CommonHelper($cellDatas['session']->getFlashdata('return_message')) : "" ?>
</div>
</div>
</div>

View File

@ -0,0 +1,87 @@
<link href="/css/front/virtual_calculator.css" media="screen" rel="stylesheet" type="text/css" />
<script>
function calculator(order_price) {
var parts = Array.from(document.getElementsByClassName("vhost_parts"));
parts.forEach(function(part) { //loop
//console.log(part);
order_price += parseInt((part.getAttribute('cost') - part.getAttribute('sale')) * part.options[part.selectedIndex].value);
document.getElementById('price').value = order_price;
document.getElementById('order_price').textContent = new Intl.NumberFormat().format(order_price);
});
var current = document.getElementById('paymentday');
if (!current.selectedIndex) {
alert("결제일을 선택해주세요");
current.focus();
return false
}
}
</script>
<div id="virtual_calculator">
<?= form_open(URLS['addCart'], [
'method' => 'post',
"onsubmit" => 'return calculator(' . $cellDatas['parts']['virtual']['default']['baserate'] . ')'
]) ?>
<input type="hidden" id="category" name="category" value="virtual">
<input type="hidden" id="price" name="price">
<table>
<thead>
<tr>
<th scope="col" colspan="3">가상서버 견적 계산기</th>
</tr>
</thead>
<tbody>
<tr>
<th>기본요금</th>
<td>
<strong><?= number_format($cellDatas['parts']['virtual']['default']['baserate']) ?>원</strong>
</td>
</tr>
<?php foreach ($cellDatas['parts']['virtual']['category'] as $category => $attrs) : ?>
<tr>
<th><?= $attrs['label'] ?></th>
<td>
<strong class="line-through"><?= number_format($attrs['cost']) ?>원</strong>
<strong class="f-back">할인가 <?= number_format($attrs['cost'] - $attrs['sale']) ?></strong> *
<?= form_dropdown(
$category,
$attrs['options'],
old($category, 0),
[
'id' => $category,
'class' => 'vhost_parts',
'cost' => $attrs['cost'],
'sale' => $attrs['sale'],
'onChange' => "calculator(" . $cellDatas['parts']['virtual']['default']['baserate'] . ")"
]
) ?>
<?= $attrs['unit'] ?>
</td>
</tr>
<?php endforeach ?>
<tr>
<th>결제일</th>
<td class="column">
<?php $paymentDayOptions = ['' => "결제일 선택"];
for ($i = 1; $i <= 28; $i++) {
$paymentDayOptions[$i] = "매월 {$i}";
}
?>
<?= form_dropdown('paymentday', $paymentDayOptions, old('paymentday', 25), ['id' => 'paymentday']);
?>
</td>
</tr>
<tr>
<th class="none">주문금액</th>
<td class="none" colspan="3">
<span id="order_price">0</span>
<?= form_submit('', '신청', array("class" => "btn btn-outline btn-primary")); ?>
</td>
</tr>
</tbody>
</table>
<?= form_close() ?>
<script type="text/javascript">
window.onload = calculator(<?= $cellDatas['parts']['virtual']['default']['baserate'] ?>);
</script>
<?= $cellDatas['session']->getFlashdata('return_message') ? alert_CommonHelper($cellDatas['session']->getFlashdata('return_message')) : "" ?>
</div>