vhost init...3
This commit is contained in:
parent
425a9df110
commit
2d09b4fcce
@ -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();
|
||||
|
||||
@ -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]);
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
//추가기능
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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; }"]);
|
||||
|
||||
@ -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" => [
|
||||
|
||||
@ -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()}의 해당 데이터가 없습니다.");
|
||||
|
||||
@ -5,9 +5,23 @@
|
||||
<?= form_open_multipart(current_url(), $viewDatas['forms']['attributes'], $viewDatas['forms']['hiddens']) ?>
|
||||
<table class="form table table-bordered table-striped">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="text-align:right;">기본장비</td>
|
||||
<td>
|
||||
<?php foreach ($viewDatas['device']['fields'] as $field) : ?>
|
||||
<div>
|
||||
<label class="col-sm-1 col-form-label"><?= lang("Device.TYPE.label.{$field}") ?></label>
|
||||
<?= getFieldForm_ProductHelper($field, DEFAULTS['EMPTY'], $viewDatas) ?>
|
||||
<?= form_input('{$field}_cnt'); ?>
|
||||
<?= validation_show_error($field); ?>
|
||||
</div>
|
||||
<?php endforeach ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php foreach ($viewDatas['fields'] as $field) : ?>
|
||||
<tr>
|
||||
<td class="label"><?= getFieldLabel_ProductHelper($field, $viewDatas) ?></td>
|
||||
<td class=" label"><?= getFieldLabel_ProductHelper($field, $viewDatas) ?>
|
||||
</td>
|
||||
<td class="column">
|
||||
<?= getFieldForm_ProductHelper($field, DEFAULTS['EMPTY'], $viewDatas) ?>
|
||||
<?= validation_show_error($field); ?>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user