dbms_init...1

This commit is contained in:
최준흠 2025-05-09 18:46:54 +09:00
parent f62fece95e
commit e870bcf90f
27 changed files with 1434 additions and 2511 deletions

View File

@ -95,19 +95,6 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au
}); });
}); });
$routes->group('device', ['namespace' => 'App\Controllers\Admin\Device'], function ($routes) { $routes->group('device', ['namespace' => 'App\Controllers\Admin\Device'], function ($routes) {
$routes->group('rack', ['namespace' => 'App\Controllers\Admin\Device'], function ($routes) {
$routes->get('/', 'RackController::index', []);
$routes->get('create', 'RackController::create_form');
$routes->post('create', 'RackController::create');
$routes->get('modify/(:num)', 'RackController::modify_form/$1');
$routes->post('modify/(:num)', 'RackController::modify/$1');
$routes->get('view/(:num)', 'RackController::view/$1');
$routes->get('delete/(:num)', 'RackController::delete/$1');
$routes->get('toggle/(:num)/(:any)', 'RackController::toggle/$1/$2');
$routes->post('batchjob', 'RackController::batchjob');
$routes->post('batchjob_delete', 'RackController::batchjob_delete');
$routes->get('download/(:alpha)', 'RackController::download/$1');
});
$routes->group('line', ['namespace' => 'App\Controllers\Admin\Device'], function ($routes) { $routes->group('line', ['namespace' => 'App\Controllers\Admin\Device'], function ($routes) {
$routes->get('/', 'LineController::index', []); $routes->get('/', 'LineController::index', []);
$routes->get('create', 'LineController::create_form'); $routes->get('create', 'LineController::create_form');

View File

@ -58,10 +58,7 @@ class ClientController extends CustomerController
protected function create_process(): ClientEntity protected function create_process(): ClientEntity
{ {
//데이터 검증 $entity = parent::create_process();
$this->formDatas = $this->doValidate($this->action, $this->fields);
$entity = $this->getService()->create($this->formDatas);
//Account정보 //Account정보
$temps = []; $temps = [];
$temps['clientinfo_uid'] = $entity->getPK(); $temps['clientinfo_uid'] = $entity->getPK();

View File

@ -14,7 +14,10 @@ use App\Services\Customer\PointService;
abstract class CustomerController extends AdminController abstract class CustomerController extends AdminController
{ {
private $_clientService = null; private ?ClientService $_clientService = null;
private ?AccountService $_accountService = null;
private ?CouponService $_couponService = null;
private ?PointService $_pointService = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);

View File

@ -6,11 +6,14 @@ use App\Controllers\Admin\AdminController;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use App\Services\Device\LineService;
use App\Services\Device\ServerService; use App\Services\Device\ServerService;
abstract class DeviceController extends AdminController abstract class DeviceController extends AdminController
{ {
private $_serverService = null; private ?ServerService $_serverService = null;
private ?LineService $_lineService = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
@ -24,6 +27,13 @@ abstract class DeviceController extends AdminController
} }
return $this->_serverService; return $this->_serverService;
} }
final public function getLineService(): LineService
{
if (!$this->_lineService) {
$this->_lineService = new LineService($this->request);
}
return $this->_lineService;
}
//Index,FieldForm관련 //Index,FieldForm관련
protected function getFormFieldOption(string $field, array $options = []): array protected function getFormFieldOption(string $field, array $options = []): array
{ {
@ -33,6 +43,11 @@ abstract class DeviceController extends AdminController
// echo $this->getUserModel()->getLastQuery(); // echo $this->getUserModel()->getLastQuery();
// dd($options); // dd($options);
break; break;
case 'lineinfo_uid':
$options[$field] = $this->getLineService()->getFormFieldOption($field);
// echo $this->getUserModel()->getLastQuery();
// dd($options);
break;
default: default:
$options = parent::getFormFieldOption($field, $options); $options = parent::getFormFieldOption($field, $options);
break; break;

View File

@ -35,18 +35,4 @@ class IpController extends DeviceController
return $this->_helper; return $this->_helper;
} }
//Index,FieldForm관련 //Index,FieldForm관련
protected function setValidation(Validation $validation, string $action, string $field, ?string $rule = null): Validation
{
switch ($field) {
case 'role':
//아래 Rule Array는 필드명.* checkbox를 사용
$validation->setRule("{$field}.*", $field, $rule);
break;
default:
$validation = parent::setValidation($validation, $action, $field, $rule);
break;
}
return $validation;
}
//Index,FieldForm관련.
} }

View File

@ -4,14 +4,17 @@ namespace App\Controllers\Admin\Device;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Validation\Validation;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use App\Entities\Device\LineEntity;
use App\Helpers\Device\LineHelper; use App\Helpers\Device\LineHelper;
use App\Services\Device\LineService; use App\Services\Device\LineService;
use App\Services\Device\IpService;
use App\Entities\Device\IpEntity;
class LineController extends DeviceController class LineController extends DeviceController
{ {
private ?IpService $_ipService = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
@ -34,19 +37,32 @@ class LineController extends DeviceController
} }
return $this->_helper; return $this->_helper;
} }
//Index,FieldForm관련 final public function getIpService(): IpService
protected function setValidation(Validation $validation, string $action, string $field, ?string $rule = null): Validation
{ {
switch ($field) { if (!$this->_ipService) {
case 'role': $this->_ipService = new IpService($this->request);
//아래 Rule Array는 필드명.* checkbox를 사용
$validation->setRule("{$field}.*", $field, $rule);
break;
default:
$validation = parent::setValidation($validation, $action, $field, $rule);
break;
} }
return $validation; return $this->_ipService;
}
//Index,FieldForm관련
//생성
protected function create_process(): LineEntity
{
//Line 등록
if (!$this->getHelper()->isValidCIDR($this->formDatas['bandwith'])) {
throw new \Exception("{$this->formDatas['bandwith']}는 CIDR 형식에 부합되지 않습니다.");
}
$entity = parent::create_process();
// //IP 등록
foreach ($this->getHelper()->cidrToIpRange($this->formDatas['bandwith']) as $ip) {
$temps = [];
$temps['lineinfo_uid'] = $entity->getPK();
$temps['ip'] = $ip;
$temps['price'] = $this->formDatas['price'] ?? 0;
$temps['status'] = lang("{$this->getIpService()->getClassPath()}.DEFAULTS.status");
$this->getIpService()->create($temps, new IpEntity());
}
return $entity;
} }
//Index,FieldForm관련.
} }

View File

@ -1,52 +0,0 @@
<?php
namespace App\Controllers\Admin\Device;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Validation\Validation;
use Psr\Log\LoggerInterface;
use App\Helpers\Device\RackHelper;
use App\Services\Device\RackService;
class RackController extends DeviceController
{
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->uri_path .= strtolower($this->getService()->getClassName()) . '/';
$this->class_path = $this->getService()->getClassPath();
$this->title = lang("{$this->getService()->getClassPath()}.title");
$this->helper = $this->getHelper();
}
public function getService(): RackService
{
if (!$this->_service) {
$this->_service = new RackService($this->request);
}
return $this->_service;
}
public function getHelper(): mixed
{
if (!$this->_helper) {
$this->_helper = new RackHelper($this->request);
}
return $this->_helper;
}
//Index,FieldForm관련
protected function setValidation(Validation $validation, string $action, string $field, ?string $rule = null): Validation
{
switch ($field) {
case 'role':
//아래 Rule Array는 필드명.* checkbox를 사용
$validation->setRule("{$field}.*", $field, $rule);
break;
default:
$validation = parent::setValidation($validation, $action, $field, $rule);
break;
}
return $validation;
}
//Index,FieldForm관련.
}

View File

@ -6,6 +6,7 @@ use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use App\Services\UserService as Service; use App\Services\UserService as Service;
use App\Helpers\UserHelper as Helper;
class Home extends AdminController class Home extends AdminController
{ {
@ -14,6 +15,7 @@ class Home extends AdminController
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->title = "관리자페이지 메인"; $this->title = "관리자페이지 메인";
$this->helper = $this->getHelper();
} }
final public function getService(): Service final public function getService(): Service
@ -23,6 +25,13 @@ class Home extends AdminController
} }
return $this->_service; return $this->_service;
} }
public function getHelper(): mixed
{
if (!$this->_helper) {
$this->_helper = new Helper($this->request);
}
return $this->_helper;
}
//Index,FieldForm관련 //Index,FieldForm관련
public function getFields(): array public function getFields(): array

View File

@ -47,7 +47,10 @@ abstract class AuthController extends CommonController
} }
return $result; return $result;
} }
final public function getFields(): array
{
return ['id', 'passwd'];
}
//로그인화면 //로그인화면
final public function login_form(): RedirectResponse|string final public function login_form(): RedirectResponse|string
{ {

View File

@ -191,8 +191,6 @@ abstract class CommonController extends BaseController
} }
protected function create_process(): mixed protected function create_process(): mixed
{ {
//데이터 검증
$this->formDatas = $this->doValidate($this->action, $this->fields);
return $this->getService()->create($this->formDatas); return $this->getService()->create($this->formDatas);
} }
final public function create(): RedirectResponse|string final public function create(): RedirectResponse|string
@ -201,6 +199,8 @@ abstract class CommonController extends BaseController
try { try {
$this->init(__FUNCTION__); $this->init(__FUNCTION__);
helper(['form']); helper(['form']);
//데이터 검증
$this->formDatas = $this->doValidate($this->action, $this->fields);
$this->entity = $this->create_process(); $this->entity = $this->create_process();
$this->getService()->getModel()->transCommit(); $this->getService()->getModel()->transCommit();
$this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->getMyAuth(), MESSAGES["SUCCESS"]); $this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->getMyAuth(), MESSAGES["SUCCESS"]);
@ -230,8 +230,6 @@ abstract class CommonController extends BaseController
} }
protected function modify_process(mixed $uid): mixed protected function modify_process(mixed $uid): mixed
{ {
//데이터 검증
$this->formDatas = $this->doValidate($this->action, $this->fields);
//자신정보정의 //자신정보정의
$entity = $this->getService()->getEntity($uid); $entity = $this->getService()->getEntity($uid);
return $this->getService()->modify($entity, $this->formDatas); return $this->getService()->modify($entity, $this->formDatas);
@ -243,6 +241,8 @@ abstract class CommonController extends BaseController
try { try {
$this->init(__FUNCTION__); $this->init(__FUNCTION__);
helper(['form']); helper(['form']);
//데이터 검증
$this->formDatas = $this->doValidate($this->action, $this->fields);
$this->entity = $this->modify_process($uid); $this->entity = $this->modify_process($uid);
$this->getService()->getModel()->transCommit(); $this->getService()->getModel()->transCommit();
$this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->getMyAuth(), MESSAGES["SUCCESS"]); $this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->getMyAuth(), MESSAGES["SUCCESS"]);
@ -256,8 +256,6 @@ abstract class CommonController extends BaseController
//단일필드작업 //단일필드작업
protected function toggle_process(mixed $uid): mixed protected function toggle_process(mixed $uid): mixed
{ {
//데이터 검증
$this->formDatas = $this->doValidate($this->action, $this->fields);
//자신정보정의 //자신정보정의
$entity = $this->getService()->getEntity($uid); $entity = $this->getService()->getEntity($uid);
return $this->getService()->modify($entity, $this->formDatas); return $this->getService()->modify($entity, $this->formDatas);
@ -269,6 +267,8 @@ abstract class CommonController extends BaseController
try { try {
$this->action = __FUNCTION__; $this->action = __FUNCTION__;
$this->fields = [$field]; $this->fields = [$field];
//데이터 검증
$this->formDatas = $this->doValidate($this->action, $this->fields);
$this->entity = $this->toggle_process($uid); $this->entity = $this->toggle_process($uid);
$this->getService()->getModel()->transCommit(); $this->getService()->getModel()->transCommit();
$this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->getMyAuth(), MESSAGES["SUCCESS"]); $this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->getMyAuth(), MESSAGES["SUCCESS"]);
@ -282,8 +282,6 @@ abstract class CommonController extends BaseController
//일괄처리작업 //일괄처리작업
protected function batchjob_process(array $entities): array protected function batchjob_process(array $entities): array
{ {
//데이터 검증
$this->formDatas = $this->doValidate($this->action, $this->fields);
$temps = []; $temps = [];
foreach ($entities as $entity) { foreach ($entities as $entity) {
$temps[] = $this->getService()->modify($entity, $this->formDatas); $temps[] = $this->getService()->modify($entity, $this->formDatas);
@ -317,6 +315,8 @@ abstract class CommonController extends BaseController
$entity = $this->getService()->getEntity($uid); $entity = $this->getService()->getEntity($uid);
$entities[] = $entity; $entities[] = $entity;
} }
//데이터 검증
$this->formDatas = $this->doValidate($this->action, $this->fields);
$this->entities = $this->batchjob_process($entities); $this->entities = $this->batchjob_process($entities);
$this->getService()->getModel()->transCommit(); $this->getService()->getModel()->transCommit();
$this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->getMyAuth(), MESSAGES["SUCCESS"]); $this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->getMyAuth(), MESSAGES["SUCCESS"]);
@ -429,23 +429,40 @@ abstract class CommonController extends BaseController
//조건절 처리 //조건절 처리
foreach ($filter_fields as $field) { foreach ($filter_fields as $field) {
$this->$field = $this->request->getVar($field); $this->$field = $this->request->getVar($field);
if (!is_null($this->$field)) { if ($this->$field !== null && $this->$field !== '') {
$this->getService()->getModel()->where($this->getService()->getModel()->getTable() . '.' . $field, $this->$field); if ($field === 'role') {
$where = "FIND_IN_SET(" . $this->getService()->getModel()->escape($this->$field) . ", {$this->getService()->getModel()->getTable()}.{$field}) > 0";
//FIND_IN_SET()은 MySQL 함수이므로 CodeIgniter가 이를 일반 컬럼명으로 착각하고 escape하게 되면 오류가 발생합니다. 따라서 ->where($sql, null, false)로 명시하여 escape를 꺼줘야 정상 작동
$this->getService()->getModel()->where($where, null, false);
} else {
$this->getService()->getModel()->where("{$this->getService()->getModel()->getTable()}.{$field}", $this->$field);
}
} }
} }
//검색어 처리 //검색어 처리
$this->word = $this->request->getVar('word'); $this->word = $this->request->getVar('word');
if (!is_null($this->word)) { if ($this->word !== null && $this->word !== '') {
$this->getService()->getModel()->setList_WordFilter($this->word); $this->getService()->getModel()->setList_WordFilter($this->word);
} }
//검색일 처리 //검색일 처리
$this->start = $this->request->getVar('start'); $this->start = $this->request->getVar('start');
$this->end = $this->request->getVar('end'); if ($this->start !== null && $this->start !== '') {
if ($this->start) { $this->getService()->getModel()->where(sprintf("%s.created_at >= '%s 00:00:00'", $this->getService()->getModel()->getTable(), $this->start));
$this->getService()->getModel()->where($this->getService()->getModel()->getTable() . ".created_at >= '{$this->start} 00:00:00'");
} }
if ($this->end) { $this->end = $this->request->getVar('end');
$this->getService()->getModel()->where($this->getService()->getModel()->getTable() . ".created_at <= '{$this->start} 23:59:59'"); if ($this->end !== null && $this->end !== '') {
$this->getService()->getModel()->where(sprintf("%s.created_at <= '%s 23:59:59'", $this->getService()->getModel()->getTable(), $this->end));
}
}
final protected function setOrcerByForList()
{
//OrderBy 처리
$this->order_field = $this->request->getVar('order_field');
$this->order_value = $this->request->getVar('order_value');
if ($this->order_field !== null && $this->order_field !== '') {
$this->getService()->getModel()->orderBy(sprintf("%s.%s %s", $this->getService()->getModel()->getTable(), $this->order_field, $this->order_value ?: "DESC"));
} else {
$this->getService()->getModel()->orderBy(sprintf("%s.%s %s", $this->getService()->getModel()->getTable(), $this->getService()->getModel()->getPKField(), "DESC"));
} }
} }
//PageNation 처리 //PageNation 처리
@ -483,14 +500,9 @@ abstract class CommonController extends BaseController
$this->total_count = intval($this->getService()->getModel()->selectCount('*', 'cnt')->get()->getRow()->cnt); $this->total_count = intval($this->getService()->getModel()->selectCount('*', 'cnt')->get()->getRow()->cnt);
//Pagination 처리 //Pagination 처리
$this->pagination = $this->getPaginationForList(); $this->pagination = $this->getPaginationForList();
//OrderBy 처리 //조건절 , OrcerBy , Limit 처리
$this->order_field = $this->request->getVar('order_field'); $this->setConditionForList($this->filter_fields);
$this->order_value = $this->request->getVar('order_value'); $this->setOrcerByForList();
if ($this->order_field && $this->order_value) {
$this->getService()->getModel()->orderBy(sprintf("%s.%s %s", $this->getService()->getModel()->getTable(), $this->order_field, $this->order_value));
} else {
$this->getService()->getModel()->orderBy(sprintf("%s.%s %s", $this->getService()->getModel()->getTable(), $this->getService()->getModel()->getPKField(), "DESC"));
}
$this->getService()->getModel()->limit($this->per_page); $this->getService()->getModel()->limit($this->per_page);
$this->getService()->getModel()->offset(($this->page - 1) * $this->per_page); $this->getService()->getModel()->offset(($this->page - 1) * $this->per_page);
return $this->getService()->getEntities(); return $this->getService()->getEntities();

File diff suppressed because it is too large Load Diff

View File

@ -9,8 +9,12 @@ class LineEntity extends DeviceEntity
const PK = LineModel::PK; const PK = LineModel::PK;
const TITLE = LineModel::TITLE; const TITLE = LineModel::TITLE;
public function getAmount() public function getBandwith()
{ {
return $this->attributes['amount']; return $this->attributes['bandwith'];
}
public function getPrice()
{
return $this->attributes['price'];
} }
} }

View File

@ -36,6 +36,7 @@ class CommonHelper
return $this->_viewDatas[$key]; return $this->_viewDatas[$key];
} }
//IP관련련
final public function isDomainName(string $domain): bool final public function isDomainName(string $domain): bool
{ {
$pattern_validation = '/((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z0-9\&\.\/\?\:@\-_=#])*/'; $pattern_validation = '/((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z0-9\&\.\/\?\:@\-_=#])*/';
@ -60,6 +61,24 @@ class CommonHelper
} }
return $result; return $result;
} }
final function isValidCIDR(string $cidr, $type = "ipv4"): bool
{
// 형식: "IP/Prefix" 형태인지 검사
if (!preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}\/\d{1,2}$/', $cidr)) {
return false;
}
list($ip, $prefix) = explode('/', $cidr);
// IP 유효성 검사
if (!$this->isIPAddress($ip, $type)) {
return false;
}
// Prefix는 0~32 사이인지 검사 (IPv4 기준)
$prefix = (int) $prefix;
if ($prefix < 0 || $prefix > 32) {
return false;
}
return true;
}
final public function isHostName(string $host): bool final public function isHostName(string $host): bool
{ {
$pattern_validation = '/[a-zA-Z0-9\.\/\?\:@\*\-_=#]/'; $pattern_validation = '/[a-zA-Z0-9\.\/\?\:@\*\-_=#]/';
@ -155,16 +174,28 @@ class CommonHelper
} }
// (EX:192.168.1.0 -> 192.168.001.000) // (EX:192.168.1.0 -> 192.168.001.000)
final public function convertIPV4toCIDR($cidr) final public function cidrToIpRange(string $cidr): array
{ {
$temps = explode(".", $cidr); if (!$this->isValidCIDR($cidr)) {
return sprintf("%03d.%03d.%03d.%03d", $temps[0], $temps[1], $temps[2], $temps[3]); return []; // 유효하지 않으면 빈 배열 반환
} }
// (EX:192.168.001.0000 -> 192.168.1.0)
final public function convertCIDRtoIPV4($ipv4) list($ip, $prefix) = explode('/', $cidr);
{ $prefix = (int) $prefix;
$temps = explode(".", $ipv4);
return sprintf("%d.%d.%d.%d", $temps[0], $temps[1], $temps[2], $temps[3]); $ipLong = ip2long($ip);
$netmask = ~((1 << (32 - $prefix)) - 1);
$network = $ipLong & $netmask;
$broadcast = $network | ~$netmask;
$ips = [];
// 첫 IP부터 마지막 IP까지 반복
for ($i = $network; $i <= $broadcast; $i++) {
$ips[] = long2ip($i);
}
return $ips;
} }
public function getFieldLabel(string $field, array $viewDatas, array $extras = []): string public function getFieldLabel(string $field, array $viewDatas, array $extras = []): string
@ -186,16 +217,15 @@ class CommonHelper
} }
switch ($field) { switch ($field) {
case 'email': case 'email':
$form = form_input($field, $value, ["placeholder" => "예)test@example.com", ...$extras]); $form = form_input($field, $value ?? "", ["placeholder" => "예)test@example.com", ...$extras]);
break; break;
case 'mobile': case 'mobile':
case 'phone': case 'phone':
$form = form_input($field, $value, ["placeholder" => "예)010-0010-0010", ...$extras]); $form = form_input($field, $value ?? "", ["placeholder" => "예)010-0010-0010", ...$extras]);
break; break;
case 'role': case 'role':
if (!is_array($viewDatas['field_options'][$field])) { if (!is_array($viewDatas['field_options'][$field])) {
echo var_dump($viewDatas['field_options']); throw new \Exception(__METHOD__ . "에서 {$field}의 field_options가 array형태가 아닙니다.");
exit;
} }
if (in_array($viewDatas['action'], ['create_form', 'modify_form'])) { if (in_array($viewDatas['action'], ['create_form', 'modify_form'])) {
$forms = []; $forms = [];
@ -215,13 +245,12 @@ class CommonHelper
case 'updated_at': case 'updated_at':
case 'created_at': case 'created_at':
$extra_class = isset($extras['class']) ? $extras['class'] . ' calender' : 'calender'; $extra_class = isset($extras['class']) ? $extras['class'] . ' calender' : 'calender';
$form = form_input($field, $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]); $form = form_input($field, $value ?? "", ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]);
break; break;
default: default:
if (in_array($field, $viewDatas['filter_fields'])) { if (in_array($field, $viewDatas['filter_fields'])) {
if (!is_array($viewDatas['field_options'][$field])) { if (!is_array($viewDatas['field_options'][$field])) {
echo var_dump($viewDatas['field_options']); throw new \Exception(__METHOD__ . "에서 {$field}의 field_options가 array형태가 아닙니다.");
exit;
} }
$formOptions = ["" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택']; $formOptions = ["" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택'];
foreach ($viewDatas['field_options'][$field] as $key => $label) { foreach ($viewDatas['field_options'][$field] as $key => $label) {
@ -229,7 +258,7 @@ class CommonHelper
} }
$form = form_dropdown($field, $formOptions, $value, $extras); $form = form_dropdown($field, $formOptions, $value, $extras);
} else { } else {
$form = form_input($field, $value, ["autocomplete" => $field, ...$extras]); $form = form_input($field, $value ?? "", ["autocomplete" => $field, ...$extras]);
} }
break; break;
} }
@ -238,7 +267,7 @@ class CommonHelper
public function getFieldView(string $field, array $viewDatas, array $extras = []): string public function getFieldView(string $field, array $viewDatas, array $extras = []): string
{ {
$value = $viewDatas['entity']->$field; $value = $viewDatas['entity']->$field ?? "";
switch ($field) { switch ($field) {
case $this->getTitleField(): case $this->getTitleField():
$value = form_label( $value = form_label(
@ -272,7 +301,7 @@ class CommonHelper
case 'role': case 'role':
$roles = []; $roles = [];
foreach (explode(DEFAULTS["DELIMITER_ROLE"], $value) as $key) { foreach (explode(DEFAULTS["DELIMITER_ROLE"], $value) as $key) {
$roles[] = $viewDatas['field_options'][$field][$key]; $roles[] = $viewDatas['field_options'][$field][$key] ?? "";
} }
$value = implode(" , ", $roles); $value = implode(" , ", $roles);
break; break;
@ -335,15 +364,14 @@ class CommonHelper
); );
break; break;
case 'modify': case 'modify':
$pk = $viewDatas['entity']->getPK();
$oldBatchJobUids = old("batchjob_uids", null); $oldBatchJobUids = old("batchjob_uids", null);
$oldBatchJobUids = is_array($oldBatchJobUids) ? $oldBatchJobUids : [$oldBatchJobUids]; $oldBatchJobUids = is_array($oldBatchJobUids) ? $oldBatchJobUids : [$oldBatchJobUids];
$checkbox = form_checkbox([ $checkbox = form_checkbox([
"id" => "checkbox_uid_{$pk}", "id" => "checkbox_uid_{$viewDatas['entity']->getPK()}",
"name" => "batchjob_uids[]", "name" => "batchjob_uids[]",
"value" => $pk, "value" => $viewDatas['entity']->getPK(),
"class" => "batchjobuids_checkboxs", "class" => "batchjobuids_checkboxs",
"checked" => in_array($pk, $oldBatchJobUids) "checked" => in_array($viewDatas['entity']->getPK(), $oldBatchJobUids)
]); ]);
$action = $checkbox . form_label( $action = $checkbox . form_label(
$viewDatas['cnt'], $viewDatas['cnt'],

View File

@ -19,8 +19,7 @@ class DeviceHelper extends CommonHelper
switch ($field) { switch ($field) {
case "serverinfo_uid": case "serverinfo_uid":
if (!is_array($viewDatas['field_options'][$field])) { if (!is_array($viewDatas['field_options'][$field])) {
echo var_dump($viewDatas['field_options']); throw new \Exception(__METHOD__ . "에서 {$field}의 field_options가 array형태가 아닙니다.");
exit;
} }
$formOptions = array_merge( $formOptions = array_merge(
["" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택'], ["" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택'],
@ -34,7 +33,7 @@ class DeviceHelper extends CommonHelper
} }
return $form; return $form;
} // } //
public function getListRowColor(mixed $entity, string $field = 'status', string $value = 'in'): string public function getListRowColor(mixed $entity, string $field = 'status', string $value = 'use'): string
{ {
return $entity->isMatched($field, $value) ? "" : 'class="table-danger"'; return $entity->isMatched($field, $value) ? "" : 'class="table-danger"';
} }

View File

@ -1,16 +0,0 @@
<?php
namespace App\Helpers\Device;
use App\Models\Device\RackModel;
use CodeIgniter\HTTP\IncomingRequest;
class RackHelper extends DeviceHelper
{
protected ?IncomingRequest $request = null;
public function __construct(?IncomingRequest $request = null)
{
parent::__construct($request);
$this->setTitleField(field: RackModel::TITLE);
}
}

View File

@ -0,0 +1,21 @@
<?php
return [
'title' => "IP정보",
'label' => [
'lineinfo_uid' => '회선정보',
'ip' => "IP",
'price' => "금액",
'status' => "상태",
'updated_at' => "수정일",
'created_at' => "작성일",
],
'DEFAULTS' => [
'status' => "use"
],
"STATUS" => [
"use" => "사용가능",
"pause" => "일시중지",
"occupied" => "사용중",
"forbidden" => "사용금지됨",
],
];

View File

@ -0,0 +1,27 @@
<?php
return [
'title' => "회선정보",
'label' => [
'title' => "제목",
'type' => "종류",
'price' => "금액",
'bandwith' => "CIDR대역",
'status' => "상태",
'updated_at' => "수정일",
'created_at' => "작성일",
],
'DEFAULTS' => [
'type' => 'general',
'status' => "use"
],
"TYPE" => [
"general" => "일반",
"dedicated" => "전용",
"defence" => "빙아",
],
"STATUS" => [
"use" => "사용",
"pause" => "사용정지",
"termination" => "해지",
],
];

View File

@ -174,14 +174,13 @@ abstract class CommonModel extends Model
return $entity; return $entity;
} }
public function create(array $formDatas, mixed $entity): mixed final function create(array $formDatas, mixed $entity): mixed
{ {
// Field에 맞는 Validation Rule 재정의 // Field에 맞는 Validation Rule 재정의
$this->setValidationRules($this->getFieldRules('create', $this->allowedFields)); $this->setValidationRules($this->getFieldRules(__FUNCTION__, $this->allowedFields));
// 저장하기 전에 데이터 값 변경이 필요한 Field
foreach (array_keys($formDatas) as $field) { foreach (array_keys($formDatas) as $field) {
LogCollector::debug("{$field}:{$formDatas[$field]}"); $value = $this->convertEntityData($field, $formDatas);
$entity->$field = $this->convertEntityData($field, $formDatas); $entity->$field = $value;
} }
// primaryKey가 자동입력이 아니면 // primaryKey가 자동입력이 아니면
if (!$this->useAutoIncrement) { if (!$this->useAutoIncrement) {
@ -194,19 +193,22 @@ abstract class CommonModel extends Model
$pkField = $this->getPKField(); $pkField = $this->getPKField();
$entity->$pkField = $this->getInsertID(); $entity->$pkField = $this->getInsertID();
} }
// log_message("debug", $this->getTable() . " => " . __FUNCTION__ . " DB 작업 완료"); LogCollector::debug("[{$entity->getTitle()}] 입력내용");
LogCollector::debug(var_export($entity->toArray(), true));
return $entity; return $entity;
} }
public function modify(mixed $entity, array $formDatas): mixed final function modify(mixed $entity, array $formDatas): mixed
{ {
// Field에 맞는 Validation Rule 재정의 // Field에 맞는 Validation Rule 재정의
$this->setValidationRules($this->getFieldRules('modify', $this->allowedFields)); $this->setValidationRules($this->getFieldRules(__FUNCTION__, $this->allowedFields));
// 저장하기 전에 데이터 값 변경이 필요한 Field // 저장하기 전에 데이터 값 변경이 필요한 Field
LogCollector::debug("[{$entity->getPK()}/{$entity->getTitle()}] 변경내용"); LogCollector::debug("[{$entity->getPK()}/{$entity->getTitle()}] 변경 전 내용");
LogCollector::debug(var_export($entity->toArray(), true));
foreach (array_keys($formDatas) as $field) { foreach (array_keys($formDatas) as $field) {
LogCollector::debug("{$field}/{$entity->$field}=>{$formDatas[$field]}");
$entity->$field = $this->convertEntityData($field, $formDatas); $entity->$field = $this->convertEntityData($field, $formDatas);
} }
LogCollector::debug("[{$entity->getPK()}/{$entity->getTitle()}] 변경 후 내용");
LogCollector::debug(var_export($entity->toArray(), true));
return $this->save_process($entity); return $this->save_process($entity);
} }

View File

@ -8,15 +8,15 @@ class IpModel extends DeviceModel
{ {
const TABLE = "ipinfo"; const TABLE = "ipinfo";
const PK = "uid"; const PK = "uid";
const TITLE = "title"; const TITLE = "ip";
protected $table = self::TABLE; protected $table = self::TABLE;
protected $primaryKey = self::PK; protected $primaryKey = self::PK;
protected $returnType = IpEntity::class; protected $returnType = IpEntity::class;
protected $allowedFields = [ protected $allowedFields = [
"clientinfo_uid", "lineinfo_uid",
"ip",
"price",
"status", "status",
"title",
"amount",
]; ];
public function __construct() public function __construct()
{ {
@ -24,7 +24,7 @@ class IpModel extends DeviceModel
} }
public function getFilterFields(): array public function getFilterFields(): array
{ {
return ["clientinfo_uid", 'status']; return ["lineinfo_uid", 'status'];
} }
public function getBatchJobFields(): array public function getBatchJobFields(): array
{ {
@ -36,15 +36,15 @@ class IpModel extends DeviceModel
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true)); throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
} }
switch ($field) { switch ($field) {
case "clientinfo_uid": case "lineinfo_uid":
case "amount": case "price":
$rule = "required|numeric"; $rule = "required|numeric";
break; break;
case "title": case "ip":
$rule = "required|trim|string"; $rule = "required|trim|valid_ip[both]"; //ipv4 , ipv6 , both(ipv4,ipv6)
break; break;
case "status": case "status":
$rule = "required|in_list[in,out]"; $rule = "required|in_list[use,pause,occupied,forbidden]";
break; break;
default: default:
$rule = parent::getFieldRule($action, $field); $rule = parent::getFieldRule($action, $field);

View File

@ -13,10 +13,11 @@ class LineModel extends DeviceModel
protected $primaryKey = self::PK; protected $primaryKey = self::PK;
protected $returnType = LineEntity::class; protected $returnType = LineEntity::class;
protected $allowedFields = [ protected $allowedFields = [
"clientinfo_uid", "type",
"status",
"title", "title",
"amount", "bandwith",
"price",
"status",
]; ];
public function __construct() public function __construct()
{ {
@ -24,7 +25,7 @@ class LineModel extends DeviceModel
} }
public function getFilterFields(): array public function getFilterFields(): array
{ {
return ["clientinfo_uid", 'status']; return ["type", 'status'];
} }
public function getBatchJobFields(): array public function getBatchJobFields(): array
{ {
@ -36,15 +37,18 @@ class LineModel extends DeviceModel
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true)); throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
} }
switch ($field) { switch ($field) {
case "clientinfo_uid": case "price":
case "amount":
$rule = "required|numeric"; $rule = "required|numeric";
break; break;
case "title": case "title":
case "bandwith":
$rule = "required|trim|string"; $rule = "required|trim|string";
break; break;
case "type":
$rule = "required|in_list[general,dedicated,defence]";
break;
case "status": case "status":
$rule = "required|in_list[in,out]"; $rule = "required|in_list[use,pause,termination]";
break; break;
default: default:
$rule = parent::getFieldRule($action, $field); $rule = parent::getFieldRule($action, $field);

View File

@ -1,55 +0,0 @@
<?php
namespace App\Models\Device;
use App\Entities\Device\RackEntity;
class RackModel extends DeviceModel
{
const TABLE = "rackinfo";
const PK = "uid";
const TITLE = "title";
protected $table = self::TABLE;
protected $primaryKey = self::PK;
protected $returnType = RackEntity::class;
protected $allowedFields = [
"clientinfo_uid",
"status",
"title",
"amount",
];
public function __construct()
{
parent::__construct();
}
public function getFilterFields(): array
{
return ["clientinfo_uid", 'status'];
}
public function getBatchJobFields(): array
{
return ['status'];
}
public function getFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
}
switch ($field) {
case "clientinfo_uid":
case "amount":
$rule = "required|numeric";
break;
case "title":
$rule = "required|trim|string";
break;
case "status":
$rule = "required|in_list[in,out]";
break;
default:
$rule = parent::getFieldRule($action, $field);
break;
}
return $rule;
}
}

View File

@ -21,11 +21,6 @@ abstract class AuthService extends CommonService
return "Auth" . DIRECTORY_SEPARATOR; return "Auth" . DIRECTORY_SEPARATOR;
} }
//Index,FieldForm관련 //Index,FieldForm관련
final public function getFields(): array
{
return ['id', 'passwd'];
}
//Index,FieldForm관련
final public function getSession(): Session final public function getSession(): Session
{ {

View File

@ -74,6 +74,7 @@ abstract class CommonService
} }
if (env('app.debug.index')) { if (env('app.debug.index')) {
echo $this->getModel()->getLastQuery(); echo $this->getModel()->getLastQuery();
// exit;
} }
return $entitys; return $entitys;
} // } //
@ -105,7 +106,7 @@ abstract class CommonService
public function create(array $formDatas, mixed $entity = null): mixed public function create(array $formDatas, mixed $entity = null): mixed
{ {
$entity = $this->getModel()->create($formDatas, $entity); $entity = $this->getModel()->create($formDatas, $entity ?? $this->getEntityClass());
LogCollector::info("[{$entity->getTitle()}]" . MESSAGES["CREATED"] . ":"); LogCollector::info("[{$entity->getTitle()}]" . MESSAGES["CREATED"] . ":");
return $entity; return $entity;
} }

View File

@ -1,28 +0,0 @@
<?php
namespace App\Services\Device;
use App\Entities\Device\RackEntity;
use App\Models\Device\RackModel;
use CodeIgniter\HTTP\IncomingRequest;
class RackService extends DeviceService
{
protected ?IncomingRequest $request = null;
public function __construct(?IncomingRequest $request = null)
{
parent::__construct($request);
}
public function getClassName(): string
{
return parent::getClassName() . DIRECTORY_SEPARATOR . "Rack";
}
public function getModelClass(): RackModel
{
return new RackModel();
}
public function getEntityClass(): RackEntity
{
return new RackEntity();
}
}

View File

@ -1,9 +1,6 @@
<div class="accordion-item"> <div class="accordion-item">
<a href="/admin/user"><?= ICONS['MEMBER'] ?> 계정 관리</a> <a href="/admin/user"><?= ICONS['MEMBER'] ?> 계정 관리</a>
</div> </div>
<div class="accordion-item">
<a href="/admin/usersns"><?= ICONS['GOOGLE'] ?> SNS 계정 관리</a>
</div>
<div class="accordion-item"> <div class="accordion-item">
<a href="/admin/mylog"><?= ICONS['FLAG'] ?> Log 관리</a> <a href="/admin/mylog"><?= ICONS['FLAG'] ?> Log 관리</a>
</div> </div>

View File

@ -5,9 +5,6 @@
</button> </button>
</h2> </h2>
<div id="flush-device" class="accordion-collapse collapse" aria-labelledby="flush-device"> <div id="flush-device" class="accordion-collapse collapse" aria-labelledby="flush-device">
<div class="accordion-item">
<a href="/admin/device/rack"><?= ICONS['BOXS'] ?>상면정보</a>
</div>
<div class="accordion-item"> <div class="accordion-item">
<a href="/admin/device/line"><?= ICONS['BOX'] ?>회선정보</a> <a href="/admin/device/line"><?= ICONS['BOX'] ?>회선정보</a>
</div> </div>

View File

@ -4,12 +4,12 @@
<nav class="condition nav"> <nav class="condition nav">
조건: 조건:
<?php foreach ($viewDatas['filter_fields'] as $field): ?> <?php foreach ($viewDatas['filter_fields'] as $field): ?>
<?= $viewDatas['helper']->getFieldForm($field, $viewDatas[$field] ?: old($field), $viewDatas) ?> <?= $viewDatas['helper']->getFieldForm($field, $viewDatas[$field] ?? old($field), $viewDatas) ?>
<?php endforeach ?> <?php endforeach ?>
</nav> </nav>
<nav class="search nav justify-content-center"> <nav class="search nav justify-content-center">
검색어:<?= form_input('word', $viewDatas['word']) ?> 검색어:<?= form_input('word', $viewDatas['word'] ?? "") ?>
검색일:<?= form_input('start', $viewDatas['start'], ["class" => "calender"]) ?><?= form_input('end', $viewDatas['end'], ["class" => "calender"]) ?> 검색일:<?= form_input('start', $viewDatas['start'] ?? "", ["class" => "calender"]) ?><?= form_input('end', $viewDatas['end'] ?? "", ["class" => "calender"]) ?>
<button class="btn btn-outline-primary" type="submit">검색</button> <button class="btn btn-outline-primary" type="submit">검색</button>
<?= anchor(current_url() . '/download/excel', ICONS['EXCEL'], ["target" => "_self", "class" => "excel"]) ?> <?= anchor(current_url() . '/download/excel', ICONS['EXCEL'], ["target" => "_self", "class" => "excel"]) ?>
</nav> </nav>