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);
$this->uri_path .= strtolower($this->getService()->getClassName()) . DIRECTORY_SEPARATOR;
$this->title = lang("MyLog.title");
$this->helper = new Helper($this->getService());
$this->class_path = $this->getService()->getClassPath();
$this->title = lang("{$this->getService()->getClassPath()}.title");
$this->helper = new Helper();
}
final public function getService(): Service
{

View File

@ -18,8 +18,9 @@ class UserController extends AdminController
{
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 = new Helper($this->getService());
$this->helper = new Helper();
}
final public function getService(): Service
{

View File

@ -17,8 +17,9 @@ class GoogleController extends AuthController
{
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 = new Helper($this->getService());
$this->helper = new Helper();
}
final public function getService(): Service

View File

@ -18,8 +18,9 @@ class LocalController extends AuthController
{
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 = new Helper($this->getService());
$this->helper = new Helper();
}
final public function getService(): Service
{

View File

@ -4,24 +4,25 @@ namespace App\Controllers;
use App\Controllers\BaseController;
use App\Libraries\LogCollector;
use App\Services\MyLogService;
use CodeIgniter\HTTP\DownloadResponse;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Validation\Validation;
use CodeIgniter\HTTP\DownloadResponse;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\Html;
use PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf;
use Psr\Log\LoggerInterface;
use App\Libraries\LogCollector;
use App\Services\MyLogService;
abstract class CommonController extends BaseController
{
private $_myAuth = null;
private $_myLogService = null;
private $_helper = null;
private $_viewDatas = [];
abstract public function getService(): mixed;
abstract public function getFields(): array;
@ -30,7 +31,16 @@ abstract class CommonController extends BaseController
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $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)
{
@ -50,6 +60,13 @@ abstract class CommonController extends BaseController
}
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
{
switch ($action) {
@ -57,6 +74,7 @@ abstract class CommonController extends BaseController
case 'modify_form':
case 'index':
case 'view':
$this->helper->setViewDatas($this->getViewDatas());
$result = view($this->view_path . $action, ['viewDatas' => $this->getViewDatas()]);
break;
default:

View File

@ -2,11 +2,15 @@
namespace App\Helpers;
use CodeIgniter\HTTP\IncomingRequest;
use App\Models\UserModel as Model;
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
{
@ -16,7 +20,7 @@ class AuthHelper extends CommonHelper
$value = $value ?: DEFAULTS['EMPTY'];
switch ($field) {
case 'id':
case $this->getService()->getModel()::TITLE:
case Model::TITLE:
$form = form_input($field, $value, $extras);
break;
case 'passwd':

View File

@ -2,17 +2,26 @@
namespace App\Helpers;
use CodeIgniter\HTTP\IncomingRequest;
class CommonHelper
{
private $_service = null;
public function __construct($service)
protected ?IncomingRequest $request = null;
private $_viewDatas = [];
public function __construct(?IncomingRequest $_request = null)
{
$this->_service = $service;
$this->request = $_request;
}
final protected function getService(): mixed
final public function setViewDatas(array $viewDatas): void
{
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
@ -151,7 +160,7 @@ class CommonHelper
switch ($field) {
default:
$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;
}
return $label;
@ -167,7 +176,7 @@ class CommonHelper
switch ($field) {
case 'status':
$form = form_dropdown($field, [
"" => lang($this->getService()->getClassPath() . '.label.' . $field) . ' 선택',
"" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
] + $viewDatas['field_options'][$field], $value, $extras);
break;
case 'updated_at':
@ -228,7 +237,7 @@ class CommonHelper
if (isset($viewDatas['order_field']) && $viewDatas['order_field'] == $field) {
$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 .= "order_field={$field}&order_value=";
$query .= isset($viewDatas['order_value']) && $viewDatas['order_value'] == 'DESC' ? "ASC" : "DESC";
@ -247,7 +256,7 @@ class CommonHelper
'입력',
$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-target" => "#index_action_form",
...$extras

View File

@ -2,13 +2,15 @@
namespace App\Helpers;
use CodeIgniter\HTTP\IncomingRequest;
use App\Models\MyLogModel as Model;
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

View File

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

View File

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

View File

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

View File

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