dbms init...1

This commit is contained in:
최준흠 2025-05-03 16:48:52 +09:00
parent f921c04108
commit aa407973e3
12 changed files with 87 additions and 47 deletions

View File

@ -17,8 +17,9 @@ class MyLogController extends AdminController
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->uri_path .= strtolower($this->getService()->getClassName()) . DIRECTORY_SEPARATOR; $this->uri_path .= strtolower($this->getService()->getClassName()) . DIRECTORY_SEPARATOR;
$this->title = lang("MyLog.title"); $this->class_path = $this->getService()->getClassPath();
$this->helper = new Helper($this->getService()); $this->title = lang("{$this->getService()->getClassPath()}.title");
$this->helper = new Helper();
} }
final public function getService(): Service final public function getService(): Service
{ {

View File

@ -18,8 +18,9 @@ class UserController extends AdminController
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->uri_path .= strtolower($this->getService()->getClassName()) . '/'; $this->uri_path .= strtolower($this->getService()->getClassName()) . '/';
$this->class_path = $this->getService()->getClassPath();
$this->title = lang("{$this->getService()->getClassPath()}.title"); $this->title = lang("{$this->getService()->getClassPath()}.title");
$this->helper = new Helper($this->getService()); $this->helper = new Helper();
} }
final public function getService(): Service final public function getService(): Service
{ {

View File

@ -17,8 +17,9 @@ class GoogleController extends AuthController
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->uri_path .= strtolower($this->getService()->getClassName()) . '/'; $this->uri_path .= strtolower($this->getService()->getClassName()) . '/';
$this->class_path = $this->getService()->getClassPath();
$this->title = lang("{$this->getService()->getClassPath()}.title");; $this->title = lang("{$this->getService()->getClassPath()}.title");;
$this->helper = new Helper($this->getService()); $this->helper = new Helper();
} }
final public function getService(): Service final public function getService(): Service

View File

@ -18,8 +18,9 @@ class LocalController extends AuthController
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->uri_path .= strtolower($this->getService()->getClassName()) . '/'; $this->uri_path .= strtolower($this->getService()->getClassName()) . '/';
$this->class_path = $this->getService()->getClassPath();
$this->title = lang("{$this->getService()->getClassPath()}.title");; $this->title = lang("{$this->getService()->getClassPath()}.title");;
$this->helper = new Helper($this->getService()); $this->helper = new Helper();
} }
final public function getService(): Service final public function getService(): Service
{ {

View File

@ -4,24 +4,25 @@ namespace App\Controllers;
use App\Controllers\BaseController; use App\Controllers\BaseController;
use App\Libraries\LogCollector;
use App\Services\MyLogService;
use CodeIgniter\HTTP\DownloadResponse;
use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Validation\Validation; use CodeIgniter\Validation\Validation;
use CodeIgniter\HTTP\DownloadResponse;
use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\Html; use PhpOffice\PhpSpreadsheet\Reader\Html;
use PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf; use PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use App\Libraries\LogCollector;
use App\Services\MyLogService;
abstract class CommonController extends BaseController abstract class CommonController extends BaseController
{ {
private $_myAuth = null;
private $_myLogService = null; private $_myLogService = null;
private $_helper = null;
private $_viewDatas = []; private $_viewDatas = [];
abstract public function getService(): mixed; abstract public function getService(): mixed;
abstract public function getFields(): array; abstract public function getFields(): array;
@ -30,7 +31,16 @@ abstract class CommonController extends BaseController
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);
$this->myauth = service('myauth'); $this->_myAuth = service('myauth');
if ($this->getMyAuth()->isLoggedIn()) {
$this->isLoggedIn = true;
$this->myAuthName = $this->getMyAuth()->getNameByAuthInfo();
$this->myAuthUID = $this->getMyAuth()->getUIDByAuthInfo();
}
}
final protected function getMyAuth(): mixed
{
return $this->_myAuth;
} }
final public function __get($name) final public function __get($name)
{ {
@ -50,6 +60,13 @@ abstract class CommonController extends BaseController
} }
return $this->_myLogService; return $this->_myLogService;
} }
final public function getHelper(): mixed
{
if (!$this->_helper) {
$this->_helper = new MyLogService($this->request);
}
return $this->_helper;
}
protected function getResultPageByActon(string $action, string $message = MESSAGES["SUCCESS"]): RedirectResponse|string protected function getResultPageByActon(string $action, string $message = MESSAGES["SUCCESS"]): RedirectResponse|string
{ {
switch ($action) { switch ($action) {
@ -57,6 +74,7 @@ abstract class CommonController extends BaseController
case 'modify_form': case 'modify_form':
case 'index': case 'index':
case 'view': case 'view':
$this->helper->setViewDatas($this->getViewDatas());
$result = view($this->view_path . $action, ['viewDatas' => $this->getViewDatas()]); $result = view($this->view_path . $action, ['viewDatas' => $this->getViewDatas()]);
break; break;
default: default:

View File

@ -2,11 +2,15 @@
namespace App\Helpers; namespace App\Helpers;
use CodeIgniter\HTTP\IncomingRequest;
use App\Models\UserModel as Model;
class AuthHelper extends CommonHelper class AuthHelper extends CommonHelper
{ {
public function __construct($service) protected ?IncomingRequest $request = null;
public function __construct(?IncomingRequest $request = null)
{ {
parent::__construct($service); parent::__construct($request);
} }
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
{ {
@ -16,7 +20,7 @@ class AuthHelper extends CommonHelper
$value = $value ?: DEFAULTS['EMPTY']; $value = $value ?: DEFAULTS['EMPTY'];
switch ($field) { switch ($field) {
case 'id': case 'id':
case $this->getService()->getModel()::TITLE: case Model::TITLE:
$form = form_input($field, $value, $extras); $form = form_input($field, $value, $extras);
break; break;
case 'passwd': case 'passwd':

View File

@ -2,17 +2,26 @@
namespace App\Helpers; namespace App\Helpers;
use CodeIgniter\HTTP\IncomingRequest;
class CommonHelper class CommonHelper
{ {
private $_service = null; protected ?IncomingRequest $request = null;
public function __construct($service) private $_viewDatas = [];
public function __construct(?IncomingRequest $_request = null)
{ {
$this->_service = $service; $this->request = $_request;
} }
final public function setViewDatas(array $viewDatas): void
final protected function getService(): mixed
{ {
return $this->_service; $this->_viewDatas = $viewDatas;
}
final public function getViewDatas(string $key)
{
if (!array_key_exists($key, $this->_viewDatas)) {
throw new \Exception("{$key}에 해당하는 ViewData가 존재하지 않습니다.");
}
return $this->_viewDatas[$key];
} }
final public function isDomainName(string $domain): bool final public function isDomainName(string $domain): bool
@ -151,7 +160,7 @@ class CommonHelper
switch ($field) { switch ($field) {
default: default:
$extras = (strpos($viewDatas['field_rules'][$field], 'required') !== false) ? ["class" => "text-danger", "required" => "", ...$extras] : $extras; $extras = (strpos($viewDatas['field_rules'][$field], 'required') !== false) ? ["class" => "text-danger", "required" => "", ...$extras] : $extras;
$label = form_label(lang("{$this->getService()->getClassPath()}.label.{$field}"), $field, $extras); $label = form_label(lang("{$viewDatas['class_path']}.label.{$field}"), $field, $extras);
break; break;
} }
return $label; return $label;
@ -167,7 +176,7 @@ class CommonHelper
switch ($field) { switch ($field) {
case 'status': case 'status':
$form = form_dropdown($field, [ $form = form_dropdown($field, [
"" => lang($this->getService()->getClassPath() . '.label.' . $field) . ' 선택', "" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
] + $viewDatas['field_options'][$field], $value, $extras); ] + $viewDatas['field_options'][$field], $value, $extras);
break; break;
case 'updated_at': case 'updated_at':
@ -228,7 +237,7 @@ class CommonHelper
if (isset($viewDatas['order_field']) && $viewDatas['order_field'] == $field) { if (isset($viewDatas['order_field']) && $viewDatas['order_field'] == $field) {
$label .= $viewDatas['order_value'] == 'ASC' ? ICONS["UP"] : ICONS["DOWN"]; $label .= $viewDatas['order_value'] == 'ASC' ? ICONS["UP"] : ICONS["DOWN"];
} }
$query = $this->getService()->getRequest()->getUri()->getQuery(['except' => ['order_field', 'order_value']]); $query = $this->request->getUri()->getQuery(['except' => ['order_field', 'order_value']]);
$query .= empty($query) ? "" : "&"; $query .= empty($query) ? "" : "&";
$query .= "order_field={$field}&order_value="; $query .= "order_field={$field}&order_value=";
$query .= isset($viewDatas['order_value']) && $viewDatas['order_value'] == 'DESC' ? "ASC" : "DESC"; $query .= isset($viewDatas['order_value']) && $viewDatas['order_value'] == 'DESC' ? "ASC" : "DESC";
@ -247,7 +256,7 @@ class CommonHelper
'입력', '입력',
$action, $action,
[ [
"data-src" => current_url() . '/' . $action . '?' . $this->getService()->getRequest()->getUri()->getQuery(), "data-src" => current_url() . '/' . $action . '?' . $this->request->getUri()->getQuery(),
"data-bs-toggle" => "modal", "data-bs-toggle" => "modal",
"data-bs-target" => "#index_action_form", "data-bs-target" => "#index_action_form",
...$extras ...$extras

View File

@ -2,13 +2,15 @@
namespace App\Helpers; namespace App\Helpers;
use CodeIgniter\HTTP\IncomingRequest;
use App\Models\MyLogModel as Model; use App\Models\MyLogModel as Model;
class MyLogHelper extends CommonHelper class MyLogHelper extends CommonHelper
{ {
public function __construct($service) protected ?IncomingRequest $request = null;
public function __construct(?IncomingRequest $request = null)
{ {
parent::__construct($service); parent::__construct($request);
} }
public function getFieldView(string $field, array $viewDatas, array $extras = []): string public function getFieldView(string $field, array $viewDatas, array $extras = []): string

View File

@ -2,11 +2,15 @@
namespace App\Helpers; namespace App\Helpers;
use CodeIgniter\HTTP\IncomingRequest;
use App\Models\UserModel as Model;
class UserHelper extends CommonHelper class UserHelper extends CommonHelper
{ {
public function __construct($service) protected ?IncomingRequest $request = null;
public function __construct(?IncomingRequest $request = null)
{ {
parent::__construct($service); parent::__construct($request);
} }
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
{ {
@ -16,7 +20,7 @@ class UserHelper extends CommonHelper
$value = $value ?: DEFAULTS['EMPTY']; $value = $value ?: DEFAULTS['EMPTY'];
switch ($field) { switch ($field) {
case 'id': case 'id':
case $this->getService()->getModel()::TITLE: case Model::TITLE:
$form = form_input($field, $value, $extras); $form = form_input($field, $value, $extras);
break; break;
case 'passwd': case 'passwd':
@ -45,7 +49,7 @@ class UserHelper extends CommonHelper
$form = form_dropdown( $form = form_dropdown(
$field, $field,
[ [
"" => lang($this->getService()->getClassPath() . '.label.' . $field) . ' 선택', "" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
] + $viewDatas['field_options'][$field], ] + $viewDatas['field_options'][$field],
$value, $value,
$extras $extras
@ -62,7 +66,7 @@ class UserHelper extends CommonHelper
{ {
$value = $viewDatas['entity']->$field ?: DEFAULTS['EMPTY']; $value = $viewDatas['entity']->$field ?: DEFAULTS['EMPTY'];
switch ($field) { switch ($field) {
case $this->getService()->getModel()::TITLE: case Model::TITLE:
$value = form_label( $value = form_label(
$value, $value,
'view', 'view',

View File

@ -18,11 +18,10 @@
</ul> </ul>
<ul class="nav justify-content-end"> <ul class="nav justify-content-end">
<li class="nav-item"> <li class="nav-item">
<?php if ($viewDatas['myauth']->isLoggedIn()): ?> <?php if ($viewDatas['isLoggedIn']): ?>
<div class="btn-group"> <div class="btn-group">
<button type="button" class="btn btn-outline-primary dropdown-toggle" data-bs-toggle="dropdown" <button type="button" class="btn btn-outline-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
aria-expanded="false"> <b><?= ICONS['LOGIN'] . $viewDatas['myAuthName'] ?></b>
<b><?= ICONS['LOGIN'] . $viewDatas['myauth']->getNameByAuthInfo('name') ?></b>
</button> </button>
<ul class="dropdown-menu dropdown-menu-end"> <ul class="dropdown-menu dropdown-menu-end">
<li><?= form_label( <li><?= form_label(
@ -30,7 +29,7 @@
"modify", "modify",
[ [
"class" => "dropdown-item", "class" => "dropdown-item",
"data-src" => "/admin/user/modify/" . $viewDatas['myauth']->getUIDByAuthInfo(), "data-src" => "/admin/user/modify/" . $viewDatas['myAuthUID'],
"data-bs-toggle" => "modal", "data-bs-toggle" => "modal",
"data-bs-target" => "#index_action_form" "data-bs-target" => "#index_action_form"
] ]
@ -41,8 +40,9 @@
<li><a class="dropdown-item" href="<?= URLS['LOGOUT'] ?>"><?= ICONS['LOGOUT'] ?>Logout</a></li> <li><a class="dropdown-item" href="<?= URLS['LOGOUT'] ?>"><?= ICONS['LOGOUT'] ?>Logout</a></li>
</ul> </ul>
</div> </div>
<?php else: ?><a class="nav-link dropdown-toggle" href="<?= URLS['LOGIN'] ?>" <?php else: ?>
role="button"><?= ICONS['LOGIN'] ?>Login</a><?php endif ?> <a class="nav-link dropdown-toggle" href="<?= URLS['LOGIN'] ?>" role="button"><?= ICONS['LOGIN'] ?>Login</a>
<?php endif ?>
</li> </li>
</ul> </ul>
</div> </div>

View File

@ -10,11 +10,10 @@
</ul> </ul>
<ul class="nav justify-content-end"> <ul class="nav justify-content-end">
<li class="nav-item"> <li class="nav-item">
<?php if ($viewDatas['myauth']->isLoggedIn()): ?> <?php if ($viewDatas['isLoggedIn']): ?>
<div class="btn-group"> <div class="btn-group">
<button type="button" class="btn btn-outline-primary dropdown-toggle" data-bs-toggle="dropdown" <button type="button" class="btn btn-outline-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
aria-expanded="false"> <b><?= ICONS['LOGIN'] . $viewDatas['myAuthName'] ?></b>
<b><?= ICONS['LOGIN'] . $viewDatas['myauth']->getNameByAuthInfo('name') ?></b>
</button> </button>
<ul class="dropdown-menu dropdown-menu-end"> <ul class="dropdown-menu dropdown-menu-end">
<li><?= form_label( <li><?= form_label(
@ -22,7 +21,7 @@
"modify", "modify",
[ [
"class" => "dropdown-item", "class" => "dropdown-item",
"data-src" => "/user/modify/" . $viewDatas['myauth']->getUIDByAuthInfo('uid'), "data-src" => "/user/modify/" . $viewDatas['myAuthUID'],
"data-bs-toggle" => "modal", "data-bs-toggle" => "modal",
"data-bs-target" => "#index_action_form" "data-bs-target" => "#index_action_form"
] ]
@ -33,8 +32,9 @@
<li><a class="dropdown-item" href="<?= URLS['LOGOUT'] ?>"><?= ICONS['LOGOUT'] ?>Logout</a></li> <li><a class="dropdown-item" href="<?= URLS['LOGOUT'] ?>"><?= ICONS['LOGOUT'] ?>Logout</a></li>
</ul> </ul>
</div> </div>
<?php else: ?><a class="nav-link dropdown-toggle" href="<?= URLS['LOGIN'] ?>" <?php else: ?>
role="button"><?= ICONS['LOGIN'] ?>Login</a><?php endif ?> <a class="nav-link dropdown-toggle" href="<?= URLS['LOGIN'] ?>" role="button"><?= ICONS['LOGIN'] ?>Login</a>
<?php endif ?>
</li> </li>
</ul> </ul>
</div> </div>

View File

@ -13,7 +13,6 @@
"php": "^8.2", "php": "^8.2",
"cloudflare/sdk": "^1.3", "cloudflare/sdk": "^1.3",
"codeigniter4/framework": "^4.5", "codeigniter4/framework": "^4.5",
"google/apiclient": "^2.15.0",
"guzzlehttp/guzzle": "^7.9", "guzzlehttp/guzzle": "^7.9",
"io-developer/php-whois": "^4.1", "io-developer/php-whois": "^4.1",
"phpoffice/phpspreadsheet": "^1.27", "phpoffice/phpspreadsheet": "^1.27",