servermgrv2 init...

This commit is contained in:
최준흠git config git config --helpgit config --global user.name 최준흠 2023-07-28 20:06:09 +09:00
parent 6560c17778
commit 7b3a94390a
16 changed files with 72 additions and 124 deletions

View File

@ -138,7 +138,7 @@ define('LAYOUTS', [
define('SESSION_NAMES', [
'RETURN_URL' => "return_url",
'ISLOGIN' => "islogined",
'AUTH' => 'auth'
'AUTH' => 'auth',
]);
define('AUTH_FIELDS', ['ID' => 'id', 'TITLE' => 'title', 'ROLE' => 'role']);

View File

@ -108,31 +108,6 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au
});
$routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($routes) {
$routes->get('/', 'Home::index');
$routes->group('user', static function ($routes) {
$routes->get('', 'UserController::index');
$routes->get('excel', 'UserController::excel');
$routes->get('insert', 'UserController::insert_form');
$routes->post('insert', 'UserController::insert');
$routes->get('update/(:uuid)', 'UserController::update_form/$1');
$routes->post('update/(:uuid)', 'UserController::update/$1');
$routes->get('view/(:uuid)', 'UserController::view/$1');
$routes->get('delete/(:uuid)', 'UserController::delete/$1', ['filter' => 'authFilter:master']);
$routes->get('toggle/(:uuid)/(:hash)', 'UserController::toggle/$1/$2');
$routes->post('batchjob', 'UserController::batchjob');
});
$routes->group('board', static function ($routes) {
$routes->get('', 'BoardController::index');
$routes->get('excel', 'BoardController::excel/$1');
$routes->get('insert', 'BoardController::insert_form');
$routes->post('insert', 'BoardController::insert');
$routes->get('update/(:num)', 'BoardController::update_form/$1');
$routes->post('update/(:num)', 'BoardController::update/$1');
$routes->get('view/(:num)', 'BoardController::view/$1');
$routes->get('reply/(:num)', 'BoardController::reply_form/$1');
$routes->post('reply/(:num)', 'BoardController::reply/$1');
$routes->get('delete/(:num)', 'BoardController::delete/$1', ['filter' => 'authFilter:master']);
$routes->get('download/(:alpha)/(:num)', 'BoardController::download/$1/$2');
});
});
/*
* --------------------------------------------------------------------

View File

@ -5,7 +5,6 @@ namespace App\Controllers\Admin;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use App\Libraries\Log\Log;
abstract class AdminHierarchyController extends AdminController
{

View File

@ -2,14 +2,14 @@
namespace App\Controllers;
use App\Models\UserModel;
use CodeIgniter\Controller;
use CodeIgniter\HTTP\CLIRequest;
use CodeIgniter\HTTP\Files\UploadedFile;
use CodeIgniter\HTTP\IncomingRequest;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\HTTP\Files\UploadedFile;
use Psr\Log\LoggerInterface;
use App\Models\UserModel;
/**
* Class BaseController
@ -208,7 +208,7 @@ abstract class BaseController extends Controller
//$this->_session->setTempdata('success', 'Page updated successfully', 3);
return alert_CommonHelper($message, $this->_session->get(SESSION_NAMES['RETURN_URL']));
} catch (\Exception $e) {
$message = __FUNCTION__ . " 실패하였습니다.";
$message = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.";
log_message("warning", $e->getMessage());
log_message("warning", var_export($this->_viewDatas['fieldDatas'], true));
log_message("info", "{$this->_viewDatas['title']} {$message}");
@ -227,7 +227,7 @@ abstract class BaseController extends Controller
final public function update_form($uid)
{
try {
$entity = $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$this->_viewDatas['fields'] = $this->_model->getFields('update');
$this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'update');
$this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters();
@ -262,7 +262,7 @@ abstract class BaseController extends Controller
{
$message = "";
try {
$entity = $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$this->_viewDatas['fields'] = $this->_model->getFields('update');
$this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'update');
$this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters();
@ -272,7 +272,7 @@ abstract class BaseController extends Controller
log_message("info", "{$this->_viewDatas['title']} {$message}");
return alert_CommonHelper($message, $this->_session->get(SESSION_NAMES['RETURN_URL']));
} catch (\Exception $e) {
$message = __FUNCTION__ . " 실패하였습니다.";
$message = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.";
log_message("warning", $e->getMessage());
log_message("warning", var_export($this->_viewDatas['fieldDatas'], true));
log_message("info", "{$this->_viewDatas['title']} {$message}");
@ -294,7 +294,7 @@ abstract class BaseController extends Controller
{
$message = "";
try {
$entity = $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$this->_viewDatas['fields'] = [$field];
$this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'toggle');
$this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters();
@ -304,7 +304,7 @@ abstract class BaseController extends Controller
log_message("info", "{$this->_viewDatas['title']} {$message}");
return alert_CommonHelper($message, $this->_session->get(SESSION_NAMES['RETURN_URL']));
} catch (\Exception $e) {
$message = __FUNCTION__ . " 실패하였습니다.";
$message = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.";
log_message("warning", $e->getMessage());
log_message("warning", var_export($this->_viewDatas['fieldDatas'], true));
log_message("info", "{$this->_viewDatas['title']} {$message}");
@ -322,12 +322,13 @@ abstract class BaseController extends Controller
}
public function batchjob()
{
$uids = $this->request->getVar('batchjob_uids');
if (is_null($uids) || !is_array($uids) || !count($uids)) {
return alert_CommonHelper($this->_viewDatas['title'] . '에서 변경할 항목(uid)이 선택되지 않았습니다.', 'back');
}
$message = "";
$messages = array();
$this->_model->transStart();
try {
$uids = $this->request->getVar('batchjob_uids');
if (is_null($uids) || !is_array($uids) || !count($uids)) {
throw new \Exception($this->_viewDatas['title'] . '에서 변경할 항목(uid)이 선택되지 않았습니다.', 'back');
}
//fields 해당하는 field중 선택된 값이 있는경우만 fields로 정의
$fields = array();
foreach ($this->_model->getFieldBatchFilters() as $field) {
@ -344,23 +345,25 @@ abstract class BaseController extends Controller
$this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters();
$entitys = array();
foreach ($uids as $uid) {
$entity = $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
try {
$entity = $this->batchjob_validate($entity);
array_push($entitys, $this->batchjob_process($entity));
array_push($messages, "{$entity->getTitle()}는 수정이 완료되었습니다.");
} catch (\Exception $e) {
log_message("warning", "{$entity->getTitle()}는 다음과 같은 이유로 수정되지 않았습니다.\n<br>" . $e->getMessage());
array_push($messages, "{$entity->getTitle()}는 다음과 같은 이유로 수정되지 않았습니다.\\n<br>" . $e->getMessage());
throw new \Exception($e->getMessage());
}
}
$message = "총: " . count($entitys) . "개의 수정(Batchjob)을 완료하였습니다.";
log_message("info", "{$this->_viewDatas['title']} {$message}");
return alert_CommonHelper($message, $this->_session->get(SESSION_NAMES['RETURN_URL']));
$this->_model->transComplete();
log_message("info", "{$this->_viewDatas['title']}에서 " . implode("\n" . $messages));
return alert_CommonHelper(implode("\\n" . $messages), $this->_session->get(SESSION_NAMES['RETURN_URL']));
} catch (\Exception $e) {
$message = "총: " . count($uids) . "개의 수정(Batchjob)을 실패하였습니다.";
$this->_model->transRollback();
log_message("warning", $e->getMessage());
log_message("info", implode("\n" . $messages));
log_message("warning", var_export($this->_viewDatas['fieldDatas'], true));
log_message("info", "{$this->_viewDatas['title']} {$message}");
return alert_CommonHelper($message . "<br>\n{$e->getMessage()}", 'back');
return alert_CommonHelper($e->getMessage() . "\\n" . implode("\\n" . $messages), 'back');
}
}
@ -378,13 +381,13 @@ abstract class BaseController extends Controller
{
$message = "";
try {
$entity = $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$this->delete_process($entity);
$message = "{$entity->getTitle()} " . __FUNCTION__ . " 완료하였습니다.";
log_message("info", "{$this->_viewDatas['title']} {$message}");
return alert_CommonHelper($message, $this->_session->get(SESSION_NAMES['RETURN_URL']));
} catch (\Exception $e) {
$message = __FUNCTION__ . " 실패하였습니다.";
$message = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.";
log_message("warning", $e->getMessage());
log_message("info", "{$this->_viewDatas['title']} {$message}");
return alert_CommonHelper($message . "<br>\n{$e->getMessage()}", 'back');
@ -399,7 +402,6 @@ abstract class BaseController extends Controller
public function view($uid)
{
try {
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$this->_viewDatas['fields'] = $this->_model->getFields('view');
$this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'view');
@ -442,9 +444,7 @@ abstract class BaseController extends Controller
//Rows 처리
$this->index_setCondition();
//OrderBy
$order_field = $this->request->getVar('order_field') ?: 'uid';
$order_value = $this->request->getVar('order_value') ?: 'DESC';
$this->_model->setIndexOrderBy($order_field, $order_value);
$this->_model->setIndexOrderBy($this->request->getVar('order_field'), $this->request->getVar('order_value'));
//Limit
$entitys = $per_page ? $this->_model->findAll($per_page, $page * $per_page - $per_page) : $this->_model->findAll();
// log_message("debug", __METHOD__ . "에서 호출[{$per_page}:{$page}=>{$page}*{$per_page}-{$per_page}]\n" . $this->_model->getLastQuery());

View File

@ -11,6 +11,7 @@ CREATE TABLE servermgr.tw_user (
status varchar(10) NOT NULL DEFAULT 'use' COMMENT 'use: 사용,unuse: 사용않함',
updated_at timestamp NULL DEFAULT NULL,
created_at timestamp NOT NULL DEFAULT current_timestamp(),
deleted_at timestamp NULL DEFAULT NULL,
PRIMARY KEY (uid),
UNIQUE KEY (id),
UNIQUE KEY (email)

View File

@ -55,10 +55,11 @@ abstract class BaseHierarchyModel extends BaseModel
return parent::create_process($entity, $formDatas);
}
public function setIndexOrderBy($field, $order = "DESC")
public function setIndexOrderBy(?string $field, ?string $order)
{
parent::setIndexOrderBy($field, $order);
//계단식의 경우는 먼저 다른것보다 먼저 orderBy가 수행되어야 하므로
$this->orderBy("grpno", "DESC");
$this->orderBy("grporder", "ASC");
parent::setIndexOrderBy($field, $order);
}
}

View File

@ -55,9 +55,12 @@ abstract class BaseModel extends Model
}
abstract public function getTitle(): string;
abstract public function getEntity($uid): BaseEntity;
abstract public function getEntitys($conditions): array;
abstract public function getFieldFilters(): array;
abstract public function getFields(string $action): array;
final public function getEntitys($conditions = false): array
{
return $conditions ? $this->where($conditions)->findAll() : $this->findAll();
}
protected function getFieldRule(string $field, array $rules, string $action = ""): array
{
switch ($field) {
@ -101,16 +104,9 @@ abstract class BaseModel extends Model
}
return $rules;
}
public function getFieldBatchFilters(array $skips = array()): array
public function getFieldBatchFilters(): array
{
//allowedFields에서 추가했으므로 Controller에는 적용되지 않게하기위함
$fields = array();
foreach ($this->getFieldFilters() as $field) {
if (!in_array($field, $skips)) {
array_push($fields, $field);
}
}
return $fields;
return $this->getFieldFilters();
}
public function getFieldFormOptions($conditions, $options = array()): array
@ -230,7 +226,10 @@ abstract class BaseModel extends Model
$this->where("created_at >=", $start);
$this->where("created_at <=", $end);
}
public function setIndexOrderBy($field, $order = "ASC")
public function setIndexOrderBy(?string $field, ?string $order)
{
if (!is_null($field) && !is_null($order)) {
$this->orderBy($field ?: $this->primaryKey, $order ?: "DESC");
}
}
}

View File

@ -45,10 +45,9 @@ class BoardConfigModel extends BaseModel
{
return ["isaccess", "isread", "iswrite", "isreply", "isupload", "isdownload", "status"];
}
public function getFieldBatchFilters(array $skips = array()): array
public function getFieldBatchFilters(): array
{
$skips = ["isupload", "isdownload", ...$skips];
return parent::getFieldBatchFilters($skips);
return parent::getFieldBatchFilters();
}
protected function getFieldRule(string $field, array $rules, string $action = ""): array
{
@ -77,12 +76,7 @@ class BoardConfigModel extends BaseModel
}
public function getEntity($conditions): BoardConfigEntity
{
$entity = $this->where($conditions)->first();
return $entity ?: throw new \Exception("{$conditions}의 해당 데이터가 없습니다.\n ");
}
public function getEntitys($conditions): array
{
return $this->where($conditions)->findAll();
return $this->where($conditions)->first() ?: throw new \Exception("해당 데이터가 없습니다.\n" . var_export($conditions, true));
}
protected function changeFormData(string $field, array $formDatas, $entity)
@ -132,9 +126,4 @@ class BoardConfigModel extends BaseModel
$this->orLike("isupload", $word, "both"); //befor , after , both
$this->orLike("isdownload", $word, "both"); //befor , after , both
}
public function setIndexOrderBy($field, $order = "ASC")
{
parent::setIndexOrderBy($field, $order);
$this->orderBy($this->getTitle(), "ASC");
}
}

View File

@ -35,9 +35,13 @@ class BoardModel extends BaseHierarchyModel
break;
}
}
public function getFieldFilters(array $fields = array()): array
public function getFieldFilters(): array
{
return ["board_config_uid", "user_uid", "status", ...$fields];
return ["board_config_uid", "user_uid", "status"];
}
public function getFieldBatchFilters(): array
{
return parent::getFieldBatchFilters();
}
protected function getFieldRule(string $field, array $rules, string $action = ""): array
{
@ -64,13 +68,9 @@ class BoardModel extends BaseHierarchyModel
public function getEntity($conditions): BoardEntity
{
$entity = $this->where($conditions)->first();
return $entity ?: throw new \Exception("{$conditions}의 해당 데이터가 없습니다.\n ");
}
public function getEntitys($conditions): array
{
return $this->where($conditions)->findAll();
return $this->where($conditions)->first() ?: throw new \Exception("해당 데이터가 없습니다.\n" . var_export($conditions, true));
}
public function create(array $formDatas): BoardEntity
{
return $this->create_process(new BoardEntity(), $formDatas);
@ -91,9 +91,4 @@ class BoardModel extends BaseHierarchyModel
$this->orLike($this->getTitle(), $word, "both");
$this->orLike("content", $word, "both"); //befor , after , both
}
public function setIndexOrderBy($field, $order = "ASC")
{
parent::setIndexOrderBy($field, $order);
$this->orderBy($this->getTitle(), "ASC");
}
}

View File

@ -9,6 +9,7 @@ class UserModel extends BaseModel
protected $table = "tw_user";
protected $useAutoIncrement = false;
protected $returnType = UserEntity::class;
protected $useSoftDeletes = false;
public function __construct()
{
parent::__construct();
@ -35,9 +36,13 @@ class UserModel extends BaseModel
break;
}
}
public function getFieldFilters(array $fields = array()): array
public function getFieldFilters(): array
{
return ["role", "status", ...$fields];
return ["role", "status"];
}
public function getFieldBatchFilters(): array
{
return parent::getFieldBatchFilters();
}
protected function getFieldRule(string $field, array $rules, string $action = ""): array
{
@ -67,12 +72,7 @@ class UserModel extends BaseModel
}
public function getEntity($conditions): UserEntity
{
$entity = $this->where($conditions)->first();
return $entity ?: throw new \Exception("{$conditions}의 해당 사용자가 없습니다.\n ");
}
public function getEntitys($conditions): array
{
return $this->where($conditions)->findAll();
return $this->where($conditions)->first() ?: throw new \Exception("해당 데이터가 없습니다.\n" . var_export($conditions, true));
}
protected function changeFormData(string $field, array $formDatas, $entity)
@ -105,9 +105,4 @@ class UserModel extends BaseModel
$this->orLike("id", $word, "both");
$this->orLike($this->getTitle(), $word, "both"); //befor , after , both
}
public function setIndexOrderBy($field, $order = "ASC")
{
parent::setIndexOrderBy($field, $order);
$this->orderBy($this->getTitle(), "ASC");
}
}

View File

@ -34,9 +34,13 @@ class UserSNSModel extends BaseModel
break;
}
}
public function getFieldFilters(array $fields = array()): array
public function getFieldFilters(): array
{
return ["user_uid", "status", ...$fields];
return ["user_uid", "status"];
}
public function getFieldBatchFilters(): array
{
return parent::getFieldBatchFilters();
}
protected function getFieldRule(string $field, array $rules, string $action = ""): array
{
@ -65,12 +69,7 @@ class UserSNSModel extends BaseModel
}
public function getEntity($conditions): UserSNSEntity
{
$entity = $this->where($conditions)->first();
return $entity ?: throw new \Exception("{$conditions}의 해당 데이터가 없습니다.\n ");
}
public function getEntitys($conditions): array
{
return $this->where($conditions)->findAll();
return $this->where($conditions)->first() ?: throw new \Exception("해당 데이터가 없습니다.\n" . var_export($conditions, true));
}
public function create(array $formDatas): UserSNSEntity
@ -89,9 +88,4 @@ class UserSNSModel extends BaseModel
$this->orLike($this->getTitle(), $word, "both");
$this->orLike("email", $word, "both"); //befor , after , both
}
public function setIndexOrderBy($field, $order = "ASC")
{
parent::setIndexOrderBy($field, $order);
$this->orderBy($this->getTitle(), "ASC");
}
}

View File

@ -20,7 +20,7 @@
</tr>
<?php $i = 0; ?>
<?php foreach ($entitys as $entity) : ?>
<tr id="<?= $entity->getPrimaryKey() ?>" <?= $entity->getStatus() != 'use' ? 'class="table-danger" rowcolor="red"' : 'rowcolor="red"' ?> onClick="indexRowCheckBoxToggle(this);">
<tr id="<?= $entity->getPrimaryKey() ?>" <?= $entity->getStatus() != DEFAULTS['STATUS'] ? 'class="table-danger" rowcolor="red"' : 'rowcolor="red"' ?> onClick="indexRowCheckBoxToggle(this);">
<td>
<?= form_checkbox(["id" => "checkbox_uid_{$entity->getPrimaryKey()}", "name" => "batchjob_uids[]", "value" => $entity->getPrimaryKey(), "class" => "batchjobuids_checkboxs"]); ?>
<?= anchor(current_url() . '/update/' . $entity->getPrimaryKey(), $total_count - (($page - 1) * $per_page + $i), ["target" => "_self"]) ?>

View File

@ -20,7 +20,7 @@
</tr>
<?php $i = 0; ?>
<?php foreach ($entitys as $entity) : ?>
<tr id="<?= $entity->getPrimaryKey() ?>" <?= $entity->getStatus() != 'use' ? 'class="table-danger" rowcolor="red"' : 'rowcolor="red"' ?> onClick="indexRowCheckBoxToggle(this);">
<tr id="<?= $entity->getPrimaryKey() ?>" <?= $entity->getStatus() != DEFAULTS['STATUS'] ? 'class="table-danger" rowcolor="red"' : 'rowcolor="red"' ?> onClick="indexRowCheckBoxToggle(this);">
<td>
<?= form_checkbox(["id" => "checkbox_uid_{$entity->getPrimaryKey()}", "name" => "batchjob_uids[]", "value" => $entity->getPrimaryKey(), "class" => "batchjobuids_checkboxs"]); ?>
<?= anchor(current_url() . '/update/' . $entity->getPrimaryKey(), $total_count - (($page - 1) * $per_page + $i), ["target" => "_self"]) ?>

View File

@ -20,7 +20,7 @@
</tr>
<?php $i = 0; ?>
<?php foreach ($entitys as $entity) : ?>
<tr id="<?= $entity->getPrimaryKey() ?>" <?= $entity->getStatus() != 'use' ? 'class="table-danger" rowcolor="red"' : 'rowcolor="red"' ?> onClick="indexRowCheckBoxToggle(this);">
<tr id="<?= $entity->getPrimaryKey() ?>" <?= $entity->getStatus() != DEFAULTS['STATUS'] ? 'class="table-danger" rowcolor="red"' : 'rowcolor="red"' ?> onClick="indexRowCheckBoxToggle(this);">
<td>
<?= form_checkbox(["id" => "checkbox_uid_{$entity->getPrimaryKey()}", "name" => "batchjob_uids[]", "value" => $entity->getPrimaryKey(), "class" => "batchjobuids_checkboxs"]); ?>
<?= anchor(current_url() . '/update/' . $entity->getPrimaryKey(), $total_count - (($page - 1) * $per_page + $i), ["target" => "_self"]) ?>

View File

@ -1,6 +1,6 @@
<li class="nav-item">검색어:<?= form_input('word', $word) ?></li>
<li class="nav-item">검색일:
<?= form_input('start', $start, array("class" => "calender")) ?><?= form_input('end', $end, array("class" => "calender")) ?>
<?= form_input('start', $start, ["class" => "calender"]) ?><?= form_input('end', $end, ["class" => "calender"]) ?>
<?= form_submit('', '검색', array("class" => "btn btn-outline btn-primary")); ?><?= anchor(current_url() . '/excel?' . $uri->getQuery(), '<i class="bi bi-file-excel"></i>', ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?>
</li>
<li class="nav-item">page:<?= $page ?> / total:<?= $total_page ?> <?= form_dropdown('per_page', $pageOptions, $per_page, array('onChange' => 'this.form.submit()')) ?> / 총:<?= $total_count ?></li>