servermgrv2 init...

This commit is contained in:
최준흠git config git config --helpgit config --global user.name 최준흠 2023-07-22 23:19:44 +09:00
parent de0b53f4f6
commit b3659ee820
37 changed files with 339 additions and 537 deletions

View File

@ -157,12 +157,14 @@ define('AUTH_ADAPTERS', [
],
]);
//등급 관련
define('ROLES', [
define('FORM_OPTIONS', [
'ROLE' => [
'guest' => '비회원', 'user' => '일반회원', 'vip' => 'VIP회원',
'bronze' => '일반판매자', 'silver' => '고급판매자', 'gold' => '파워리셀러',
'manager' => '관리자', 'cloudflare' => "Cloudflare관리자", 'director' => '감독자', 'master' => "마스터",
],
'STATUS' => ["use" => "사용", "unuse" => "사용않함",],
]);
define('STATUS', ["use" => "사용", "unuse" => "사용않함",]);
//Upload , Download 관련
define('PATHS', [
@ -199,8 +201,9 @@ define('DEFAULTS', [
'PERPAGE' => getenv('default.perpage') ?: 20,
]);
//UUID초기값 정의
define('UUIDS', [
'NAMESPACE' => getenv('uuid.namespace') ?: "8fc990b07418d5826d98de952cfb268dee4a23a3",
'SECRET' => getenv('uuid.secret') ?: "delftstack1",
//API Adapter초기갑 정의
define('API', [
'SSL_VERIFY' => getenv('api.ssl') == 'true' ? true : false,
'COOKIE_FILE' => PATHS['API'] . getenv('api.cookie.file') ?: "api-cookie_" . date("Ymd") . ".log",
'DEBUG_FILE' => PATHS['API'] . getenv('api.debug.file') ?: "api-debug_" . date("Ymd") . ".log",
]);

View File

@ -19,13 +19,13 @@ class BoardConfigController extends \App\Controllers\Admin\AdminController
'fields' => ['name', 'isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status', 'head', 'tail'],
'fieldFilters' => ['isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status'],
'fieldRules' => [
'name' => 'required|string|is_unique[tw_board_conifg.name]',
'isaccess' => 'required|string',
'isread' => 'required|string',
'iswrite' => 'required|string',
'isreply' => 'required|string',
'isupload' => 'required|string',
'isdownload' => 'required|string',
'name' => 'required|string|is_unique[tw_board_config.name]',
'isaccess' => 'required',
'isread' => 'required',
'iswrite' => 'required',
'isreply' => 'required',
'isupload' => 'required',
'isdownload' => 'required',
'head' => 'if_exist|string',
'tail' => 'if_exist|string',
'status' => 'if_exist|string',
@ -36,12 +36,12 @@ class BoardConfigController extends \App\Controllers\Admin\AdminController
'fieldFilters' => ['isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status'],
'fieldRules' => [
'name' => 'required|string',
'isaccess' => 'required|string',
'isread' => 'required|string',
'iswrite' => 'required|string',
'isreply' => 'required|string',
'isupload' => 'required|string',
'isdownload' => 'required|string',
'isaccess' => 'required',
'isread' => 'required',
'iswrite' => 'required',
'isreply' => 'required',
'isupload' => 'required',
'isdownload' => 'required',
'head' => 'if_exist|string',
'tail' => 'if_exist|string',
'status' => 'if_exist|string',
@ -52,12 +52,12 @@ class BoardConfigController extends \App\Controllers\Admin\AdminController
'fieldFilters' => ['isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status'],
'fieldRules' => [
'name' => 'required|string',
'isaccess' => 'required|string',
'isread' => 'required|string',
'iswrite' => 'required|string',
'isreply' => 'required|string',
'isupload' => 'required|string',
'isdownload' => 'required|string',
'isaccess' => 'required',
'isread' => 'required',
'iswrite' => 'required',
'isreply' => 'required',
'isupload' => 'required',
'isdownload' => 'required',
'head' => 'if_exist|string',
'tail' => 'if_exist|string',
'status' => 'if_exist|string',
@ -66,7 +66,7 @@ class BoardConfigController extends \App\Controllers\Admin\AdminController
'index' => [
'fields' => ['name', 'isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status', 'created_at'],
'fieldFilters' => ['isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status'],
'batchjobFilters' => ['isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status'],
'batchjobFilters' => ['status'],
],
'excel' => [
'fields' => ['name', 'isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status', 'created_at'],

View File

@ -2,17 +2,16 @@
namespace App\Controllers\Admin;
use App\Models\UserModel;
use App\Models\BoardConfigModel;
use App\Models\BoardModel;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use App\Libraries\Log\Log;
class BoardController extends \App\Controllers\Admin\AdminController
{
private $_userModel = null;
private $_user_uids = null;
private $_boardConfigModel = null;
private $_board_config_uids = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
@ -20,10 +19,10 @@ class BoardController extends \App\Controllers\Admin\AdminController
$this->_model = new BoardModel();
$this->_defines = [
'insert' => [
'fields' => ['board_category', 'title', 'content', 'passwd', 'confirmpassword', 'upload_file', 'status'],
'fieldFilters' => ['board_category', 'user_uid', 'status'],
'fields' => ['board_config_uid', 'title', 'content', 'passwd', 'confirmpassword', 'upload_file', 'status'],
'fieldFilters' => ['board_config_uid', 'user_uid', 'status'],
'fieldRules' => [
'board_category' => 'required|string',
'board_config_uid' => 'required|string',
'title' => 'required|string',
'content' => 'required|string',
'passwd' => 'if_exist|trim|string',
@ -34,10 +33,10 @@ class BoardController extends \App\Controllers\Admin\AdminController
]
],
'update' => [
'fields' => ['board_category', 'title', 'content', 'passwd', 'confirmpassword', 'upload_file', 'status'],
'fieldFilters' => ['board_category', 'user_uid', 'status'],
'fields' => ['board_config_uid', 'title', 'content', 'passwd', 'confirmpassword', 'upload_file', 'status'],
'fieldFilters' => ['board_config_uid', 'user_uid', 'status'],
'fieldRules' => [
'board_category' => 'required|string',
'board_config_uid' => 'required|string',
'title' => 'required|string',
'content' => 'required|string',
'passwd' => 'if_exist|trim|string',
@ -48,18 +47,18 @@ class BoardController extends \App\Controllers\Admin\AdminController
],
],
'view' => [
'fields' => ['board_category', 'user_uid', 'title', 'view_cnt', 'status', 'updated_at', 'created_at', 'content'],
'fieldFilters' => ['board_category', 'user_uid', 'status'],
'fieldRules' => ['board_category', 'user_uid', 'status'],
'fields' => ['board_config_uid', 'user_uid', 'title', 'view_cnt', 'status', 'updated_at', 'created_at', 'content'],
'fieldFilters' => ['board_config_uid', 'user_uid', 'status'],
'fieldRules' => ['board_config_uid', 'user_uid', 'status'],
],
'index' => [
'fields' => ['board_category', 'user_uid', 'title', 'view_cnt', 'status', 'updated_at', 'created_at'],
'fieldFilters' => ['board_category', 'user_uid', 'status'],
'batchjobFilters' => ['board_category', 'user_uid', 'status'],
'fields' => ['board_config_uid', 'user_uid', 'title', 'view_cnt', 'status', 'updated_at', 'created_at'],
'fieldFilters' => ['board_config_uid', 'user_uid', 'status'],
'batchjobFilters' => ['board_config_uid', 'user_uid', 'status'],
],
'excel' => [
'fields' => ['board_category', 'user_uid', 'title', 'view_cnt', 'status', 'updated_at', 'created_at'],
'fieldFilters' => ['board_category', 'user_uid', 'status'],
'fields' => ['board_config_uid', 'user_uid', 'title', 'view_cnt', 'status', 'updated_at', 'created_at'],
'fieldFilters' => ['board_config_uid', 'user_uid', 'status'],
],
];
helper($this->_className);
@ -68,21 +67,22 @@ class BoardController extends \App\Controllers\Admin\AdminController
$this->_viewDatas['className'] = $this->_className;
}
private function getUserModel(): UserModel
//BoardConfig모델
final protected function getBoardConfigModel(): BoardConfigModel
{
return is_null($this->_userModel) ? new UserModel() : $this->_userModel;
return is_null($this->_boardConfigModel) ? new BoardConfigModel() : $this->_boardConfigModel;
}
//Field별 Form Option용
protected function getFieldFormOption(string $field): array
{
switch ($field) {
case 'user_uid':
if (is_null($this->_user_uids)) {
case 'board_config_uid':
if (is_null($this->_board_config_uids)) {
//모든 필요한 FormOption등 조기화작업 필요
$this->_user_uids = $this->getUserModel()->getFieldFormOptions(['status' => 'use']);
$this->_board_config_uids = $this->getBoardConfigModel()->getFieldFormOptions(['status' => 'use']);
}
return $this->_user_uids;
return $this->_board_config_uids;
default:
return parent::getFieldFormOption($field);
break;
@ -94,7 +94,7 @@ class BoardController extends \App\Controllers\Admin\AdminController
{
switch ($field) {
case 'upload_file':
$this->_viewDatas['fieldDatas'][$field] = $this->single_upload_procedure($field, $entity);
return $this->single_upload_procedure($field, $entity);
break;
default:
return parent::getFieldFormData($field, $entity);

View File

@ -20,17 +20,17 @@ class LoggerController extends \App\Controllers\Admin\AdminController
$this->_defines = [
'view' => [
'fields' => ['user_uid', 'title', 'content', 'status', 'created_at'],
'fieldFilters' => ['user_uid', 'status'],
'fieldFilters' => ['user_uid'],
'fieldRules' => [],
],
'index' => [
'fields' => ['user_uid', 'title', 'status', 'created_at'],
'fieldFilters' => ['user_uid', 'status'],
'fieldFilters' => ['user_uid'],
'batchjobFilters' => [],
],
'excel' => [
'fields' => ['user_uid', 'title', 'status', 'created_at'],
'fieldFilters' => ['user_uid', 'status'],
'fieldFilters' => ['user_uid'],
],
];
helper($this->_className);
@ -39,22 +39,10 @@ class LoggerController extends \App\Controllers\Admin\AdminController
$this->_viewDatas['className'] = $this->_className;
}
private function getUserModel(): UserModel
{
return is_null($this->_userModel) ? new UserModel() : $this->_userModel;
}
//Field별 Form Option용
protected function getFieldFormOption(string $field): array
{
switch ($field) {
case 'user_uid':
if (is_null($this->_user_uids)) {
//모든 필요한 FormOption등 조기화작업 필요
$this->_user_uids = $this->getUserModel()->getFieldFormOptions(['status' => 'use']);
}
return $this->_user_uids;
break;
default:
return parent::getFieldFormOption($field);
break;

View File

@ -2,7 +2,6 @@
namespace App\Controllers\Admin;
use App\Models\UserModel;
use App\Models\UserSNSModel;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
@ -10,7 +9,6 @@ use Psr\Log\LoggerInterface;
class UserSNSController extends \App\Controllers\Admin\AdminController
{
private $_userModel = null;
private $_user_uids = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
@ -39,11 +37,6 @@ class UserSNSController extends \App\Controllers\Admin\AdminController
$this->_viewDatas['className'] = $this->_className;
}
private function getUserModel(): UserModel
{
return is_null($this->_userModel) ? new UserModel() : $this->_userModel;
}
//Field별 Form Option용
protected function getFieldFormOption(string $field): array
{

View File

@ -9,6 +9,7 @@ use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use App\Libraries\Log\Log;
use App\Models\UserModel;
/**
* Class BaseController
@ -47,6 +48,8 @@ abstract class BaseController extends Controller
/**
* Constructor.
*/
private $_userModel = null;
private $_user_uids = array();
protected $_model = null;
protected $_className = '';
protected $_defines = array();
@ -74,26 +77,39 @@ abstract class BaseController extends Controller
}
}
//User모델
final protected function getUserModel(): UserModel
{
return is_null($this->_userModel) ? new UserModel() : $this->_userModel;
}
//Field별 Form Option용
protected function getFieldFormOption(string $field): array
{
switch ($field) {
default:
$fieldFormOptionDatas = lang($this->_className . '.' . strtoupper($field));
if (!is_array($fieldFormOptionDatas)) {
throw new \Exception(__FUNCTION__ . "에서 {$field}의 데이터가 array가 아닙니다.\n" . var_export($fieldFormOptionDatas, true));
case 'user_uid':
if (is_null($this->_user_uids)) {
//모든 필요한 FormOption등 조기화작업 필요
$this->_user_uids = $this->getUserModel()->getFieldFormOptions(['status' => 'use']);
}
return $fieldFormOptionDatas;
return $this->_user_uids;
break;
default:
$formOptionDatas = lang($this->_className . '.' . strtoupper($field));
if (!is_array($formOptionDatas)) {
throw new \Exception("{$this->_className}에서 Field:{$field}의 FormOptionData가 array가 아닙니다.\n" . var_export($formOptionDatas, true));
}
return $formOptionDatas;
break;
}
}
//Field별 Form Option용
final protected function getFieldFormOptions(array $fieldFilters): array
final protected function getFieldFormOptions(array $fields): array
{
$fieldFormOptions = array();
foreach ($fieldFilters as $field) {
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "에서 field가 array 입니다.\n" . var_export($fieldFilters, true));
foreach ($fields as $field) {
if (!is_string($field)) {
throw new \Exception(__FUNCTION__ . "에서 {$this->_className}의 Field:{$field}가 string 아닙니다.\n" . var_export($fields, true));
}
$fieldFormOptions[$field] = $this->getFieldFormOption($field);
}
@ -104,8 +120,8 @@ abstract class BaseController extends Controller
{
$tempRules = $this->_model->getValidationRules(['only' => $fields]);
foreach ($fields as $field) {
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "에서 field가 array 입니다.\n" . var_export($fieldRules, true));
if (!is_string($field)) {
throw new \Exception(__FUNCTION__ . "에서 {$field}가 string 아닙니다.\n" . var_export($fieldRules, true));
}
if (array_key_exists($field, $fieldRules)) {
$tempRules[$field] = $fieldRules[$field];
@ -118,20 +134,8 @@ abstract class BaseController extends Controller
protected function getFieldFormData(string $field, $entity = null)
{
switch ($field) {
case 'passwd':
//암호는 보안상 log에 남지 않기
$this->_viewDatas['fieldDatas'][$field] = $this->request->getVar($field);
break;
default:
$this->_viewDatas['fieldDatas'][$field] = $this->request->getVar($field);
if (is_null($entity)) {
Log::add("info", "{$field} : {$this->_viewDatas['fieldDatas'][$field]}");
} else {
Log::add(
"info",
"{$field} : {$entity->$field} => {$this->_viewDatas['fieldDatas'][$field]}"
);
}
return $this->request->getVar($field);
break;
}
}
@ -214,7 +218,8 @@ abstract class BaseController extends Controller
//변경된 값 적용
$this->_viewDatas['fieldDatas'] = array();
foreach ($this->_viewDatas['fields'] as $field) {
$this->getFieldFormData($field);
$this->_viewDatas['fieldDatas'][$field] = $this->getFieldFormData($field);
Log::add("info", "{$field} : " . var_export($this->_viewDatas['fieldDatas'][$field], true));
}
//변경할 값 확인
if (!$this->validate($this->_viewDatas['fieldRules'])) {
@ -241,7 +246,7 @@ abstract class BaseController extends Controller
$message = __FUNCTION__ . " 실패하였습니다.";
Log::add("warning", $e->getMessage());
Log::add("warning", var_export($this->_viewDatas['fieldDatas'], true));
Log::save("{$this->_viewDatas['title']} {$message}", false);
Log::save("{$this->_viewDatas['title']} {$message}", 'error');
return redirect()->back()->withInput()->with("error", $message . "<br>\n{$e->getMessage()}");
}
}
@ -280,7 +285,11 @@ abstract class BaseController extends Controller
//변경된 값 적용
$this->_viewDatas['fieldDatas'] = array();
foreach ($this->_viewDatas['fields'] as $field) {
$this->getFieldFormData($field, $entity);
$this->_viewDatas['fieldDatas'][$field] = $this->getFieldFormData($field, $entity);
Log::add(
"info",
"{$field} : {$entity->$field} => " . var_export($this->_viewDatas['fieldDatas'][$field])
);
}
//변경할 값 확인
if (!$this->validate($this->_viewDatas['fieldRules'])) {
@ -307,7 +316,7 @@ abstract class BaseController extends Controller
$message = __FUNCTION__ . " 실패하였습니다.";
Log::add("warning", $e->getMessage());
Log::add("warning", var_export($this->_viewDatas['fieldDatas'], true));
Log::save("{$this->_viewDatas['title']} {$message}", false);
Log::save("{$this->_viewDatas['title']} {$message}", 'error');
return redirect()->back()->withInput()->with("error", $message . "<br>\n{$e->getMessage()}");
}
}
@ -360,7 +369,7 @@ abstract class BaseController extends Controller
$message = __FUNCTION__ . " 실패하였습니다.";
Log::add("warning", $e->getMessage());
Log::add("warning", var_export($this->_viewDatas['fieldDatas'], true));
Log::save("{$this->_viewDatas['title']} {$message}", false);
Log::save("{$this->_viewDatas['title']} {$message}", 'error');
return redirect()->back()->withInput()->with("error", $message . "<br>\n{$e->getMessage()}");
}
}
@ -394,7 +403,7 @@ abstract class BaseController extends Controller
$message = __FUNCTION__ . " 실패하였습니다.";
Log::add("warning", $e->getMessage());
Log::add("warning", var_export($this->_viewDatas['fieldDatas'], true));
Log::save("{$this->_viewDatas['title']} {$message}", false);
Log::save("{$this->_viewDatas['title']} {$message}", 'error');
return alert_CommonHelper($message . "<br>\n{$e->getMessage()}", 'back');
}
}
@ -449,7 +458,7 @@ abstract class BaseController extends Controller
$message = "총: " . count($uids) . "개의 수정(Batchjob)을 실패하였습니다.";
Log::add("warning", $e->getMessage());
Log::add("warning", var_export($this->_viewDatas['fieldDatas'], true));
Log::save("{$this->_viewDatas['title']} {$message}", false);
Log::save("{$this->_viewDatas['title']} {$message}", 'error');
return alert_CommonHelper($message . "<br>\n{$e->getMessage()}", 'back');
}
}
@ -476,7 +485,7 @@ abstract class BaseController extends Controller
} catch (\Exception $e) {
$message = __FUNCTION__ . " 실패하였습니다.";
Log::add("warning", $e->getMessage());
Log::save("{$this->_viewDatas['title']} {$message}", false);
Log::save("{$this->_viewDatas['title']} {$message}", 'error');
return alert_CommonHelper($message . "<br>\n{$e->getMessage()}", 'back');
}
}
@ -615,7 +624,7 @@ abstract class BaseController extends Controller
$this->_viewDatas['fieldFilters'] = $this->_defines['excel']['fieldFilters'];
$this->_viewDatas['fieldFormOptions'] = $this->getFieldFormOptions($this->_viewDatas['fieldFilters']);
}
private function excel_getSpreadSheet()
protected function excel_spreadSheet()
{
//Excepl 초기화
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
@ -642,13 +651,18 @@ abstract class BaseController extends Controller
protected function excel_process()
{
$fileName = date('Y-m-d_Hm') . '.xlsx';
//파일저장 참고:https://teserre.tistory.com/19
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($this->excel_getSpreadSheet(), 'Xlsx');
//파일저장용
// $writer->save(Excel_FilePath . '/' . $fileName);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($this->excel_spreadSheet(), 'Xlsx');
//결과파일저장
$writer->save(PATHS['EXCEL'] . '/' . $fileName);
//Download시
header("Content-Type: application/vnd.ms-excel");
header(sprintf("Content-Disposition: attachment; filename=%s", urlencode($fileName)));
header("Expires: 0");
header("Cache-Control: must-revalidate");
header("Pragma: public");
header("Content-Length:" . filesize(PATHS['EXCEL'] . '/' . $fileName));
// flush();
// return readfile(PATHS['EXCEL'] . '/' . $fileName);
return $writer->save('php://output');
}
protected function excel_procedure()

View File

@ -26,10 +26,10 @@ DROP TABLE IF EXISTS tw_board;
-- select * from tw_board order by grpno desc,grporder asc
CREATE TABLE tw_board (
uid int(10) unsigned NOT NULL AUTO_INCREMENT,
grpno int(5) UNSIGNED NOT NULL DEFAULT 1 COMMENT 'Group번호: 상위가없을시 기본 uid와 같음',
grporder int(5) UNSIGNED NOT NULL DEFAULT 1 COMMENT 'Group순서: 상위가없을시 0부터시작',
grpdepth int(3) UNSIGNED NOT NULL DEFAULT 1 COMMENT 'Group깊이: 상위가없을시 1부터시작 , 상위 grpdpt+1씩 추가필요',
board_category_uid varchar(36) NOT NULL COMMENT '게시판구분',
grpno int(10) UNSIGNED NOT NULL DEFAULT 1 COMMENT 'Group번호: uid와 Type맞춰야함 , 상위가없을시 기본 uid와 같음',
grporder int(5) UNSIGNED NOT NULL DEFAULT 1 COMMENT 'Group순서: 최상위시 1부터시작',
grpdepth int(2) UNSIGNED NOT NULL DEFAULT 1 COMMENT 'Group깊이: 상위시 1부터시작 , 상위 grpdpt+1씩 추가필요',
board_config_uid varchar(36) NOT NULL COMMENT '게시판구분',
user_uid varchar(36) NULL COMMENT '작성자 정보',
title varchar(255) NOT NULL COMMENT '제목',
content text NOT NULL COMMENT '내용',
@ -39,13 +39,14 @@ CREATE TABLE tw_board (
updated_at timestamp NULL DEFAULT NULL,
created_at timestamp NOT NULL DEFAULT current_timestamp(),
PRIMARY KEY (uid),
CONSTRAINT FOREIGN KEY (board_category_uid) REFERENCES tw_board_config (uid),
CONSTRAINT FOREIGN KEY (board_config_uid) REFERENCES tw_board_config (uid),
CONSTRAINT FOREIGN KEY (user_uid) REFERENCES tw_user (uid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT ='게시 정보';
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT ='게시 정보';
DROP TABLE IF EXISTS tw_board_file;
CREATE TABLE tw_board_file (
uid int(10) unsigned NOT NULL AUTO_INCREMENT,
tw_board_uid int(10) unsigned NOT NULL COMMENT '게시 정보',
board_uid int(10) unsigned NOT NULL COMMENT '게시 정보',
mime_type varchar(50) NOT NULL COMMENT 'Mime_Type',
name varchar(255) NOT NULL COMMENT '파일명',
real_name varchar(255) NOT NULL COMMENT '실제파일명',
@ -53,5 +54,5 @@ CREATE TABLE tw_board_file (
updated_at timestamp NULL DEFAULT NULL,
created_at timestamp NOT NULL DEFAULT current_timestamp(),
PRIMARY KEY (uid),
CONSTRAINT FOREIGN KEY (tw_board_uid) REFERENCES tw_board (uid)
CONSTRAINT FOREIGN KEY (board_uid) REFERENCES tw_board (uid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT ='게시판 File정보';

View File

@ -12,7 +12,7 @@ function getFieldLabel_BoardConfigHelper($field, array $fieldRules, array $attri
}
//header.php에서 getFieldForm_Helper사용
function getFieldForm_BoardConfigHelper($field, $value, array $formOptions, array $attributes = array())
function getFieldForm_BoardConfigHelper($field, $value, array $fieldFormOptions, array $attributes = array())
{
$value = $value ?: DEFAULTS['EMPTY'];
switch ($field) {
@ -22,14 +22,14 @@ function getFieldForm_BoardConfigHelper($field, $value, array $formOptions, arra
case 'isreply':
case 'isupload':
case 'isdownload':
foreach ($formOptions[$field] as $key => $label) {
$checkboxs[] = form_checkbox("{$field}[]", $key, $key != 'guest' || $key == $value, $attributes) . $label;
foreach ($fieldFormOptions[$field] as $key => $label) {
$checkboxs[] = form_checkbox("{$field}[]", $key, in_array($key, is_array($value) ? $value : explode("|", $value)), $attributes) . $label;
}
return implode("&nbsp;", $checkboxs);
break;
case 'status':
$formOptions[$field] = [DEFAULTS['EMPTY'] => lang("Admin/BoardConfig.label.{$field}") . " 선택", ...$formOptions[$field]];
return form_dropdown($field, $formOptions[$field], $value, $attributes);
$fieldFormOptions[$field] = [DEFAULTS['EMPTY'] => lang("Admin/BoardConfig.label.{$field}") . " 선택", ...$fieldFormOptions[$field]];
return form_dropdown($field, $fieldFormOptions[$field], $value, $attributes);
break;
case 'updated_at':
case 'created_at':
@ -52,6 +52,17 @@ function getFieldForm_BoardConfigHelper($field, $value, array $formOptions, arra
function getFieldView_BoardConfigHelper($field, $entity, array $fieldFilters, array $fieldFormOptions, array $attributes = array())
{
switch ($field) {
case 'isaccess':
case 'isread':
case 'iswrite':
case 'isreply':
case 'isupload':
case 'isdownload':
foreach ($fieldFormOptions[$field] as $key => $label) {
$checkboxs[] = form_checkbox("{$field}[]", $key, in_array($key, explode("|", $entity->$field)), $attributes) . $label;
}
return implode("&nbsp;", $checkboxs);
break;
case 'head':
case 'tail':
return html_entity_decode($entity->$field);
@ -65,7 +76,7 @@ function getFieldView_BoardConfigHelper($field, $entity, array $fieldFilters, ar
}
} //
function getFieldFilter_BoardConfigHelper($field, $value, array $formOptions, array $attributes = array())
function getFieldFilter_BoardConfigHelper($field, $value, array $fieldFormOptions, array $attributes = array())
{
$value = $value ?: DEFAULTS['EMPTY'];
switch ($field) {
@ -75,11 +86,11 @@ function getFieldFilter_BoardConfigHelper($field, $value, array $formOptions, ar
case 'isreply':
case 'isupload':
case 'isdownload':
$formOptions[$field] = [DEFAULTS['EMPTY'] => lang("Admin/BoardConfig.label.{$field}") . " 선택", ...$formOptions[$field]];
return form_dropdown($field, $formOptions[$field], $value, $attributes);
$fieldFormOptions[$field] = [DEFAULTS['EMPTY'] => lang("Admin/BoardConfig.label.{$field}") . " 선택", ...$fieldFormOptions[$field]];
return form_dropdown($field, $fieldFormOptions[$field], $value, $attributes);
break;
default:
return getFieldForm_BoardConfigHelper($field, $value, $formOptions, $attributes);
return getFieldForm_BoardConfigHelper($field, $value, $fieldFormOptions, $attributes);
break;
}
} //
@ -98,6 +109,17 @@ function getFieldIndex_Row_BoardConfigHelper($field, array $row, array $fieldFil
case 'name':
return anchor(current_url() . '/view/' . $row['uid'], $row[$field], ["target" => "_self"]);
break;
case 'isaccess':
case 'isread':
case 'iswrite':
case 'isreply':
case 'isupload':
case 'isdownload':
foreach ($fieldFormOptions[$field] as $key => $label) {
$checkboxs[] = form_checkbox($field, $key, in_array($key, explode("|", $row[$field])), $attributes) . $label;
}
return '<div style="text-align:left; padding-left:%spx;">' . implode("<BR>", $checkboxs) . '</div>';
break;
case 'updated_at':
case 'created_at':
return isset($row[$field]) ? str_split($row[$field], 10)[0] : "";

View File

@ -12,15 +12,15 @@ function getFieldLabel_BoardHelper($field, array $fieldRules, array $attributes
}
//header.php에서 getFieldForm_Helper사용
function getFieldForm_BoardHelper($field, $value, array $formOptions, array $attributes = array())
function getFieldForm_BoardHelper($field, $value, array $fieldFormOptions, array $attributes = array())
{
$value = $value ?: DEFAULTS['EMPTY'];
switch ($field) {
case 'board_category':
case 'board_config_uid':
case 'user_uid':
case 'status':
$formOptions[$field] = [DEFAULTS['EMPTY'] => lang("Admin/Board.label.{$field}") . " 선택", ...$formOptions[$field]];
return form_dropdown($field, $formOptions[$field], $value, $attributes);
$fieldFormOptions[$field] = [DEFAULTS['EMPTY'] => lang("Admin/Board.label.{$field}") . " 선택", ...$fieldFormOptions[$field]];
return form_dropdown($field, $fieldFormOptions[$field], $value, $attributes);
break;
case 'updated_at':
case 'created_at':
@ -57,12 +57,12 @@ function getFieldView_BoardHelper($field, $entity, array $fieldFilters, array $f
}
} //
function getFieldFilter_BoardHelper($field, $value, array $formOptions, array $attributes = array())
function getFieldFilter_BoardHelper($field, $value, array $fieldFormOptions, array $attributes = array())
{
$value = $value ?: DEFAULTS['EMPTY'];
switch ($field) {
default:
return getFieldForm_BoardHelper($field, $value, $formOptions, $attributes);
return getFieldForm_BoardHelper($field, $value, $fieldFormOptions, $attributes);
break;
}
} //

View File

@ -12,14 +12,14 @@ function getFieldLabel_LoggerHelper($field, array $fieldRules, array $attributes
}
//header.php에서 getFieldForm_Helper사용
function getFieldForm_LoggerHelper($field, $value, array $formOptions, array $attributes = array())
function getFieldForm_LoggerHelper($field, $value, array $fieldFormOptions, array $attributes = array())
{
$value = $value ?: DEFAULTS['EMPTY'];
switch ($field) {
case 'user_uid':
case 'status':
$formOptions[$field] = [DEFAULTS['EMPTY'] => lang("Admin/Logger.label.{$field}") . " 선택", ...$formOptions[$field]];
return form_dropdown($field, $formOptions[$field], $value, $attributes);
$fieldFormOptions[$field] = [DEFAULTS['EMPTY'] => lang("Admin/Logger.label.{$field}") . " 선택", ...$fieldFormOptions[$field]];
return form_dropdown($field, $fieldFormOptions[$field], $value, $attributes);
break;
case 'updated_at':
case 'created_at':
@ -46,12 +46,12 @@ function getFieldView_LoggerHelper($field, $entity, array $fieldFilters, array $
}
} //
function getFieldFilter_LoggerHelper($field, $value, array $formOptions, array $attributes = array())
function getFieldFilter_LoggerHelper($field, $value, array $fieldFormOptions, array $attributes = array())
{
$value = $value ?: DEFAULTS['EMPTY'];
switch ($field) {
default:
return getFieldForm_LoggerHelper($field, $value, $formOptions, $attributes);
return getFieldForm_LoggerHelper($field, $value, $fieldFormOptions, $attributes);
break;
}
} //

View File

@ -12,14 +12,14 @@ function getFieldLabel_UserSNSHelper($field, array $fieldRules, array $attribute
}
//header.php에서 getFieldForm_Helper사용
function getFieldForm_UserSNSHelper($field, $value, array $formOptions, array $attributes = array())
function getFieldForm_UserSNSHelper($field, $value, array $fieldFormOptions, array $attributes = array())
{
$value = $value ?: DEFAULTS['EMPTY'];
switch ($field) {
case 'user_uid':
case 'status':
$formOptions[$field] = [DEFAULTS['EMPTY'] => lang("Admin/UserSNS.label.{$field}") . " 선택", ...$formOptions[$field]];
return form_dropdown($field, $formOptions[$field], $value, $attributes);
$fieldFormOptions[$field] = [DEFAULTS['EMPTY'] => lang("Admin/UserSNS.label.{$field}") . " 선택", ...$fieldFormOptions[$field]];
return form_dropdown($field, $fieldFormOptions[$field], $value, $attributes);
break;
case 'updated_at':
case 'created_at':
@ -43,12 +43,12 @@ function getFieldView_UserSNSHelper($field, $entity, array $fieldFilters, array
}
} //
function getFieldFilter_UserSNSHelper($field, $value, array $formOptions, array $attributes = array())
function getFieldFilter_UserSNSHelper($field, $value, array $fieldFormOptions, array $attributes = array())
{
$value = $value ?: DEFAULTS['EMPTY'];
switch ($field) {
default:
return getFieldForm_UserSNSHelper($field, $value, $formOptions, $attributes);
return getFieldForm_UserSNSHelper($field, $value, $fieldFormOptions, $attributes);
break;
}
} //

View File

@ -12,14 +12,14 @@ function getFieldLabel_UserHelper($field, array $fieldRules, array $attributes =
}
//header.php에서 getFieldForm_Helper사용
function getFieldForm_UserHelper($field, $value, array $formOptions, array $attributes = array())
function getFieldForm_UserHelper($field, $value, array $fieldFormOptions, array $attributes = array())
{
$value = $value ?: DEFAULTS['EMPTY'];
switch ($field) {
case 'role':
case 'status':
$formOptions[$field] = [DEFAULTS['EMPTY'] => lang("Admin/User.label.{$field}") . " 선택", ...$formOptions[$field]];
return form_dropdown($field, $formOptions[$field], $value, $attributes);
$fieldFormOptions[$field] = [DEFAULTS['EMPTY'] => lang("Admin/User.label.{$field}") . " 선택", ...$fieldFormOptions[$field]];
return form_dropdown($field, $fieldFormOptions[$field], $value, $attributes);
break;
case 'updated_at':
case 'created_at':
@ -47,12 +47,12 @@ function getFieldView_UserHelper($field, $entity, array $fieldFilters, array $fi
}
} //
function getFieldFilter_UserHelper($field, $value, array $formOptions, array $attributes = array())
function getFieldFilter_UserHelper($field, $value, array $fieldFormOptions, array $attributes = array())
{
$value = $value ?: DEFAULTS['EMPTY'];
switch ($field) {
default:
return getFieldForm_UserHelper($field, $value, $formOptions, $attributes);
return getFieldForm_UserHelper($field, $value, $fieldFormOptions, $attributes);
break;
}
} //

View File

@ -1,29 +0,0 @@
<?php
return [
'title' => "게시판정보",
'label' => [
'uid' => "번호",
'grpno' => "그룹번호",
'grpord' => "부모번호",
'grpdpt' => "그룸Depth",
'board_category' => "게시판구분",
'user_uid' => "작성자",
'title' => "제목",
'content' => "내용",
'passwd' => "암호",
'confirmpassword' => "암호확인",
'view_cnt' => "조회수",
'upload_file' => "UploadFile",
'status' => "상태",
'updated_at' => "수정일",
'created_at' => "작성일"
],
"BOARD_CATEGORY" => [
'notice' => '공지사항',
'faq' => 'FAQ',
'qna' => '1:1문의',
'data' => '자료실'
],
"USER_UID" => [],
"STATUS" => [...STATUS],
];

View File

@ -1,26 +0,0 @@
<?php
return [
'title' => "계정정보",
'label' => [
'uid' => "번호",
'name' => "이름",
'isaccess' => "접속권한",
'isread' => "일기권한",
'iswrite' => "쓰기권한",
'isreply' => "답변권한",
'isupload' => "Upload권한",
'isdownload' => "Download권한",
'head' => "머리글",
'tail' => "아래글",
'status' => "상태",
'updated_at' => "수정일",
'created_at' => "작성일"
],
"ISACCESS" => [...ROLES],
"ISREAD" => [...ROLES],
"ISWRITE" => [...ROLES],
"ISREPLY" => [...ROLES],
"ISUPLOAD" => [...ROLES],
"ISDOWNLOAD" => [...ROLES],
"STATUS" => [...STATUS],
];

View File

@ -1,30 +0,0 @@
<?php
return [
'title' => "HP Server 정보",
'label' => [
'uid' => "번호",
'customer' => "고객",
'id' => "계정",
'passwd' => "암호",
'ip' => "IP",
'port' => "Port",
'model' => "Model",
'processor' => "CPU",
'memory' => "Memory",
'health' => "기타장비상태",
'power' => "전원",
'detail' => "상세내용",
'status' => "상태",
'updated_at' => "수정일",
'created_at' => "작성일"
],
"POWER" => [
"On" => "On",
"Off" => "Off",
"Restart" => "Restart",
],
"STATUS" => [
"use" => "사용",
"unuse" => "사용않함",
]
];

View File

@ -1,18 +0,0 @@
<?php
return [
'title' => "Logger 정보",
'label' => [
'uid' => "번호",
'user_uid' => "사용자명",
'title' => "제목",
'content' => "내용",
'status' => "상태",
'updated_at' => "수정일",
'created_at' => "작성일"
],
"USER_UID" => [],
"STATUS" => [
"use" => "정상",
"unuse" => "오류",
]
];

View File

@ -1,18 +0,0 @@
<?php
return [
'title' => "계정정보",
'label' => [
'uid' => "번호",
'id' => "계정",
'passwd' => "암호",
'confirmpassword' => "암호확인",
'email' => "메일",
'role' => "권한",
'name' => "이름",
'status' => "상태",
'updated_at' => "수정일",
'created_at' => "작성일"
],
"ROLE" => [...ROLES],
"STATUS" => [...STATUS],
];

View File

@ -1,18 +0,0 @@
<?php
return [
'title' => "SNS 계정정보",
'label' => [
'uid' => "인증번호",
'user_uid' => "사용자",
'site' => "SNS명",
'id' => "SNS ID",
'name' => "SNS 이름",
'email' => "SNS 메일",
'detail' => "SNS 정보",
'status' => "상태",
'updated_at' => "수정일",
'created_at' => "작성일"
],
"USER_UID" => [],
"STATUS" => [...STATUS, "standby" => "승인대기"],
];

View File

@ -1,4 +0,0 @@
<?php
// override core en language system validation or define your own en language validation message
return [];

View File

@ -6,7 +6,7 @@ return [
'grpno' => "그룹번호",
'grpord' => "부모번호",
'grpdpt' => "그룸Depth",
'board_category' => "게시판구분",
'board_config_uid' => "설정",
'user_uid' => "작성자",
'title' => "제목",
'content' => "내용",
@ -18,12 +18,5 @@ return [
'updated_at' => "수정일",
'created_at' => "작성일"
],
"BOARD_CATEGORY" => [
'notice' => '공지사항',
'faq' => 'FAQ',
'qna' => '1:1문의',
'data' => '자료실'
],
"USER_UID" => [],
"STATUS" => [...STATUS],
"STATUS" => FORM_OPTIONS['STATUS'],
];

View File

@ -11,16 +11,16 @@ return [
'isupload' => "Upload권한",
'isdownload' => "Download권한",
'head' => "머리글",
'tail' => "아래",
'tail' => "꼬리",
'status' => "상태",
'updated_at' => "수정일",
'created_at' => "작성일"
],
"ISACCESS" => [...ROLES],
"ISREAD" => [...ROLES],
"ISWRITE" => [...ROLES],
"ISREPLY" => [...ROLES],
"ISUPLOAD" => [...ROLES],
"ISDOWNLOAD" => [...ROLES],
"STATUS" => [...STATUS],
"ISACCESS" => FORM_OPTIONS['ROLE'],
"ISREAD" => FORM_OPTIONS['ROLE'],
"ISWRITE" => FORM_OPTIONS['ROLE'],
"ISREPLY" => FORM_OPTIONS['ROLE'],
"ISUPLOAD" => FORM_OPTIONS['ROLE'],
"ISDOWNLOAD" => FORM_OPTIONS['ROLE'],
"STATUS" => FORM_OPTIONS['STATUS'],
];

View File

@ -10,9 +10,4 @@ return [
'updated_at' => "수정일",
'created_at' => "작성일"
],
"USER_UID" => [],
"STATUS" => [
"use" => "정상",
"unuse" => "오류",
]
];

View File

@ -1,18 +1,18 @@
<?php
return [
'title' => "회원 정보",
'title' => '회원 정보',
'label' => [
'uid' => "번호",
'id' => "계정",
'passwd' => "암호",
'confirmpassword' => "암호확인",
'email' => "메일",
'role' => "권한",
'name' => "이름",
'status' => "상태",
'updated_at' => "수정일",
'created_at' => "작성일"
'uid' => '번호',
'id' => '계정',
'passwd' => '암호',
'confirmpassword' => '암호확인',
'email' => '메일',
'role' => '권한',
'name' => '이름',
'status' => '상태',
'updated_at' => '수정일',
'created_at' => '작성일'
],
"ROLE" => [...ROLES],
"STATUS" => [...STATUS],
'ROLE' => FORM_OPTIONS['ROLE'],
'STATUS' => FORM_OPTIONS['STATUS'],
];

View File

@ -13,6 +13,10 @@ return [
'updated_at' => "수정일",
'created_at' => "작성일"
],
"USER_UID" => [],
"STATUS" => [...STATUS, "standby" => "승인대기"],
"STATUS" => [
"use" => "승인완료",
"unuse" => "승인취소",
"reject" => "승인거부",
"standby" => "승인대기"
],
];

View File

@ -34,18 +34,6 @@ abstract class Adapter
//type: basic , digest
return array($this->_serverInfo['id'], $this->_serverInfo['password'], $authType);
}
protected function isSSLVerifiy(): bool
{
return getenv('api.ssl') == 'true' ? true : false;
}
protected function getCookieFile()
{
return PATHS['API'] . getenv('api.cookie.file') ?: "api-cookie_" . date("Ymd") . ".log";
}
protected function getDebugFile()
{
return PATHS['API'] . getenv('api.debug.file') ?: "api-debug_" . date("Ymd") . ".log";
}
final public function get(string $url): object
{

View File

@ -169,8 +169,8 @@ class CurlAdapter extends Adapter
curl_setopt($this->getClient(), CURLOPT_POSTFIELDS, json_encode($datas));
curl_setopt($this->getClient(), CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
//cookie값 파일저장용
curl_setopt($this->getClient(), CURLOPT_COOKIEJAR, $this->getCookieFile());
curl_setopt($this->getClient(), CURLOPT_COOKIEFILE, $this->getCookieFile());
curl_setopt($this->getClient(), CURLOPT_COOKIEJAR, API['COOKIE_FILE']);
curl_setopt($this->getClient(), CURLOPT_COOKIEFILE, API['COOKIE_FILE']);
break;
default:
break;
@ -180,8 +180,8 @@ class CurlAdapter extends Adapter
curl_setopt($this->getClient(), CURLOPT_COOKIELIST, $cookie_line);
}
//SSL 확인여부용
curl_setopt($this->getClient(), CURLOPT_SSL_VERIFYPEER, $this->isSSLVerifiy());
curl_setopt($this->getClient(), CURLOPT_SSL_VERIFYHOST, $this->isSSLVerifiy());
curl_setopt($this->getClient(), CURLOPT_SSL_VERIFYPEER, API['SSL_VERIFY']);
curl_setopt($this->getClient(), CURLOPT_SSL_VERIFYHOST, API['SSL_VERIFY']);
curl_setopt($this->getClient(), CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->getClient(), CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($this->getClient(), CURLOPT_USERPWD, implode(":", $this->getAccountInfo()));

View File

@ -35,8 +35,8 @@ class GuzzleAdapter extends Adapter
$options = [
'base_uri' => $this->getServerInfo(),
'auth' => $this->getAccountInfo(),
'verify' => $this->isSSLVerifiy(),
'cookie' => $this->getCookieFile(),
'verify' => API['SSL_VERIFY'],
'cookie' => API['COOKIE_FILE'],
// \GuzzleHttp\RequestOptions::ALLOW_REDIRECTS => [
// 'max' => 10, // allow at most 10 redirects.
// 'strict' => true, // use "strict" RFC compliant redirects.

View File

@ -17,11 +17,11 @@ class LocalAdapter extends Adapter
$options = [
'baseURI' => $this->getServerInfo(),
'auth' => $this->getAccountInfo(),
'verify' => $this->isSSLVerifiy(),
'cookie' => $this->getCookieFile(),
'verify' => API['SSL_VERIFY'],
'cookie' => API['COOKIE_FILE'],
];
if ($this->_debug) {
$options['debug'] = $this->getDebugFile();
$options['debug'] = API['DEBUG_FILE'];
}
$this->_client = \Config\Services::curlrequest($options);
}

View File

@ -64,7 +64,7 @@ class GoogleAdapter extends Adapter
$this->setAccessToken($formDatas);
//Google 서비스 설정
$service = new \Google\Service\Oauth2($this->getClient());
$result = (array)$service->userinfo->get();
$result = $service->userinfo->get();
if ($this->_debug) {
log_message("debug", var_export($result, true));
}
@ -103,7 +103,14 @@ class GoogleAdapter extends Adapter
)->first();
//snsEntity 없으면 신규등록
if (is_null($snsEntity)) {
$snsEntity = $this->getUserSNSModel()->create($this->getSiteName(), $result);
$snsEntity = $this->getUserSNSModel()->create([
'site' => $this->getSiteName(),
'id' => $result['id'],
'name' => $result['name'],
'email' => $result['email'],
'detail' => json_encode($result),
'status' => 'standby'
]);
}
//상태가 use(승인완료)가 아니라면
if ($snsEntity->status !== DEFAULTS['STATUS']) {

View File

@ -11,11 +11,11 @@ class DataBase
{
$this->_model = new LoggerModel();
}
public function save(string $title, bool $status, array $logs)
public function save(string $title, string $status, array $logs)
{
$datas = array(
'title' => $title,
'status' => $status ? 'use' : 'unuse',
'status' => $status,
'content' => implode("\n", $logs)
);
return $this->_model->create($datas);

View File

@ -17,12 +17,12 @@ class Log
}
log_message($level, $content);
}
final static public function save(string $title, bool $status = true)
final static public function save(string $title, string $status = 'success')
{
if (self::$_dbInstance === null) {
self::$_dbInstance = new \App\Libraries\Log\DataBase();
}
self::$_dbInstance->save($title, $status, self::$_logs);
// self::$_dbInstance->save($title, $status, self::$_logs);
self::$_logs = array();
}
}

View File

@ -45,115 +45,83 @@ abstract class BaseModel extends Model
abstract public function getEntity($uid): ?BaseEntity;
abstract public function getFieldFormOptions(): array;
//참고:https://www.delftstack.com/howto/php/php-uuid/#create-a-function-to-generate-v5-uuid-in-php
// $v5_uuid = getUUIDv5_CommonTrait('8fc990b07418d5826d98de952cfb268dee4a23a3', 'delftstack!');
final public function getUUIDv5_CommonTrait()
final public function getUUID()
{
$n_hex = str_replace(array('-', '{', '}'), '', UUIDS['NAMESPACE']); // Getting hexadecimal components of namespace
$binray_str = ''; // Binary value string
//Namespace UUID to bits conversion
for ($i = 0; $i < strlen($n_hex); $i += 2) {
$binray_str .= chr(hexdec($n_hex[$i] . $n_hex[$i + 1]));
}
//hash value
$hashing = sha1($binray_str . UUIDS['SECRET']);
$randomBytes = bin2hex(random_bytes(16));
return sprintf(
'%08s-%04s-%04x-%04x-%12s',
// 32 bits for the time_low
substr($hashing, 0, 8),
// 16 bits for the time_mid
substr($hashing, 8, 4),
// 16 bits for the time_hi,
(hexdec(substr($hashing, 12, 4)) & 0x0fff) | 0x5000,
// 8 bits and 16 bits for the clk_seq_hi_res,
// 8 bits for the clk_seq_low,
(hexdec(substr($hashing, 16, 4)) & 0x3fff) | 0x8000,
// 48 bits for the node
substr($hashing, 20, 12)
"%s-%s-%s-%s-%s",
substr($randomBytes, 0, 8),
substr($randomBytes, 8, 4),
substr($randomBytes, 12, 4),
substr($randomBytes, 16, 4),
substr($randomBytes, 20)
);
}
//계층형구조구현
final protected function setHierarchyCreate($entity)
final protected function create_hierarchy($entity)
{
//자기자신이 최상위가 되게 만들기위함
$entity->grpno = $entity->getPrimaryKey();
// echo var_export($entity, true);
// exit;
//값변경후 다시 저장
if (!$this->save($entity)) {
Log::add("error", __FUNCTION__ . "에서 호출:" . $this->getLastQuery());
Log::add("error", implode("\n", $this->errors()));
throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->errors(), true));
}
//생성시는 grpno가 primarykey와 같음
//escape -> false옵션 반드시 있어야함
$this->builder()->set('grpno', $entity->getPrimaryKey(), false);
$this->builder()->where($this->primaryKey, $entity->getPrimaryKey());
$this->builder()->update();
return $entity;
}
final protected function setHierarchyReply($entity, $replyEntity)
final protected function reply_hierarchy($entity, $parent_entity)
{
//부모의 그룹과 grpno가 같고, 부모의 grporder보다 1 큰것을 grporder+1을 해서 update
//escape -> false옵션 반드시 있어야함
$this->builder()->set('grporder', 'grporder+1', false);
$this->builder()->where([
'grpno' => $entity->grpno,
'grporder >' => $entity->grporder
'grpno' => $parent_entity->grpno,
'grporder >' => $parent_entity->grporder
]);
$this->builder()->update();
// echo $this->getLastQuery();
// exit;
//reply용 설정
$replyEntity->grpno = $entity->grpno;
$replyEntity->grporder = $entity->grporder + 1;
$replyEntity->grpdepth = $entity->grpdepth + 1;
return $replyEntity;
$entity->grpno = $parent_entity->grpno;
$entity->grporder = $parent_entity->grporder + 1;
$entity->grpdepth = $parent_entity->grpdepth + 1;
return $entity;
}
protected function changeFormData($field, $value)
protected function changeFormData($field, array $formDatas, $entity)
{
switch ($field) {
case $this->primaryKey:
if (!$this->useAutoIncrement) {
$entity->$field = $this->getUUID();
}
break;
case 'user_uid':
if (array_key_exists($field, $formDatas) && $formDatas[$field]) {
$entity->$field = $formDatas[$field];
} elseif (session()->get(SESSION_NAMES['ISLOGIN'])) {
$auth = session()->get(SESSION_NAMES['AUTH']);
$entity->$field = $auth[AUTH_FIELDS['ID']];
}
break;
case 'passwd':
return $value ? password_hash($value, PASSWORD_DEFAULT) : "";
if (array_key_exists($field, $formDatas) && $formDatas[$field]) {
$entity->$field = password_hash($formDatas[$field], PASSWORD_DEFAULT);
}
break;
case 'content':
return htmlentities($value);
break;
case 'status':
return $value ?: DEFAULTS['STATUS'];
if (array_key_exists($field, $formDatas) && $formDatas[$field]) {
$entity->$field = htmlentities($formDatas[$field]);
}
break;
default:
return $value;
if (array_key_exists($field, $formDatas) && $formDatas[$field]) {
$entity->$field = $formDatas[$field];
}
break;
}
}
final protected function create_process($entity)
{
//primaryKey 할당
if ($this->useAutoIncrement === false) {
$pk = $this->primaryKey;
$entity->$pk = $this->getUUIDv5_CommonTrait();
}
// echo var_export($entity, true);
// exit;
if (!$this->save($entity)) {
Log::add("error", __FUNCTION__ . "에서 호출:" . $this->getLastQuery());
Log::add("error", implode("\n", $this->errors()));
throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->errors(), true));
}
// echo "<HR>";
// echo $this->getLastQuery();
// exit;
//primaryKey 할당
if ($this->useAutoIncrement === true) {
$pk = $this->primaryKey;
$entity->$pk = $this->insertID();
}
return $entity;
}
final protected function modify_process($entity)
private function save_process($entity)
{
$entity->updated_at = time();
if ($entity->hasChanged()) {
if (!$this->save($entity)) {
Log::add("error", __FUNCTION__ . "에서 호출:" . $this->getLastQuery());
@ -165,6 +133,23 @@ abstract class BaseModel extends Model
}
return $entity;
}
final protected function create_process($entity, array $formDatas)
{
foreach ($this->allowedFields as $field) {
$entity = $this->changeFormData($field, $formDatas, $entity);
}
return $this->save_process($entity);
}
final protected function modify_process($entity, array $formDatas)
{
foreach ($this->allowedFields as $field) {
if ($field != $this->primaryKey) {
$entity = $this->changeFormData($field, $formDatas, $entity);
}
}
$entity->updated_at = time();
return $this->save_process($entity);
}
//View관련 (게시판등의 조회수 증가함수)
final public function increaseViewCount($uid, $field = 'view_cnt', int $cnt = 1)

View File

@ -7,18 +7,18 @@ use App\Entities\BoardConfigEntity;
class BoardConfigModel extends BaseModel
{
protected $table = 'tw_board_config';
// protected $primaryKey = 'uid';
protected $primaryKey = 'uid';
protected $useAutoIncrement = false;
protected $allowedFields = ['uid', 'name', 'isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'head', 'tail', 'status', 'updated_at'];
protected $validationRules = [
'uid' => 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
'name' => 'required|string',
'isaccess' => 'required|string',
'isread' => 'required|string',
'iswrite' => 'required|string',
'isreply' => 'required|string',
'isupload' => 'required|string',
'isdownload' => 'required|string',
'isaccess' => 'required',
'isread' => 'required',
'iswrite' => 'required',
'isreply' => 'required',
'isupload' => 'required',
'isdownload' => 'required',
'head' => 'if_exist|string',
'tail' => 'if_exist|string',
'status' => 'if_exist|string',
@ -46,32 +46,39 @@ class BoardConfigModel extends BaseModel
return $temps;
}
protected function changeFormData($field, $value)
protected function changeFormData($field, array $formDatas, $entity)
{
switch ($field) {
case 'isaccess':
case 'isread':
case 'iswrite':
case 'isreply':
case 'isupload':
case 'isdownload':
case 'isaccess':
if (array_key_exists($field, $formDatas) && $formDatas[$field]) {
$entity->$field = is_array($formDatas[$field]) ? implode("|", $formDatas[$field]) : $formDatas[$field];
}
break;
case 'head':
case 'tail':
return htmlentities($value);
if (array_key_exists($field, $formDatas) && $formDatas[$field]) {
$entity->$field = htmlentities($formDatas[$field]);
}
break;
default:
return $value;
return parent::changeFormData($field, $formDatas, $entity);
break;
}
return $entity;
}
public function create(array $formDatas): BoardConfigEntity
{
$entity = new BoardConfigEntity($formDatas);
foreach ($formDatas as $field => $value) {
$entity->$field = $this->changeFormData($field, $value);
}
return parent::create_process($entity);
return $this->create_process(new BoardConfigEntity(), $formDatas);
}
public function modify(BoardConfigEntity $entity, array $formDatas): BoardConfigEntity
{
foreach ($formDatas as $field => $value) {
$entity->$field = $this->changeFormData($field, $value);
}
return parent::modify_process($entity);
return $this->modify_process($entity, $formDatas);
}
//Index관련

View File

@ -7,14 +7,14 @@ use App\Entities\BoardEntity;
class BoardModel extends BaseModel
{
protected $table = 'tw_board';
// protected $primaryKey = 'uid';
// protected $useAutoIncrement = true;
protected $allowedFields = ['grpno', 'grporder', 'grpdepth', 'board_category', 'user_uid', 'title', 'content', 'passwd', 'view_cnt', 'status', 'updated_at'];
protected $primaryKey = 'uid';
protected $useAutoIncrement = true;
protected $allowedFields = ['grpno', 'grporder', 'grpdepth', 'board_config_uid', 'user_uid', 'title', 'content', 'passwd', 'view_cnt', 'status', 'updated_at'];
protected $validationRules = [
'grpno' => 'if_exist|numeric',
'grporder' => 'if_exist|numeric',
'grpdepth' => 'if_exist|numeric',
'board_category' => 'required|string',
'board_config_uid' => 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
'user_uid' => 'if_exist|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
'title' => 'required|string',
'content' => 'required|string',
@ -47,44 +47,19 @@ class BoardModel extends BaseModel
public function create(array $formDatas): BoardEntity
{
$entity = new BoardEntity($formDatas);
//로그인 여부 확인후 필요한 데이터 저장
if (session()->get(SESSION_NAMES['ISLOGIN'])) {
$auth = session()->get(SESSION_NAMES['AUTH']);
$entity->user_uid = $auth[AUTH_FIELDS['ID']];
}
foreach ($formDatas as $field => $value) {
$entity->$field = $this->changeFormData($field, $value);
}
$entity = parent::create_process($entity);
//계층형
$entity = $this->setHierarchyCreate($entity);
return $entity;
//계층형 Create
$entity = $this->create_process(new BoardEntity(), $formDatas);
return $this->create_hierarchy($entity);
}
public function modify(BoardEntity $entity, array $formDatas): BoardEntity
{
foreach ($formDatas as $field => $value) {
$entity->$field = $this->changeFormData($field, $value);
return $this->modify_process($entity, $formDatas);
}
return parent::modify_process($entity);
}
public function reply(BoardEntity $entity, array $formDatas): BoardEntity
public function reply(BoardEntity $parent_entity, array $formDatas): BoardEntity
{
$replyEntity = new BoardEntity($formDatas);
//로그인 여부 확인후 필요한 데이터 저장
if (session()->get(SESSION_NAMES['ISLOGIN'])) {
$auth = session()->get(SESSION_NAMES['AUTH']);
$replyEntity->user_uid = $auth[AUTH_FIELDS['ID']];
}
$replyEntity->title = "RE:" . $entity->title;
foreach ($formDatas as $field => $value) {
$replyEntity->$field = $this->changeFormData($field, $value);
}
//계층형
$replyEntity = $this->setHierarchyReply($entity, $replyEntity);
// echo var_export($replyEntity, true);
// exit;
return $this->create_process($replyEntity);
//계층형 Reply
$entity = $this->reply_hierarchy(new BoardEntity(), $parent_entity);
return $this->create_process($entity, $formDatas);
}
//Index관련

View File

@ -7,15 +7,14 @@ use App\Entities\LoggerEntity;
class LoggerModel extends BaseModel
{
protected $table = 'tw_logger';
// protected $primaryKey = 'uid';
protected $primaryKey = 'uid';
// protected $useAutoIncrement = true;
protected $allowedFields = ['user_uid', 'title', 'content', 'status', 'updated_at'];
protected $validationRules = [
'uid' => 'if_exist|numeric',
'user_uid' => 'required|string',
'user_uid' => 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
'title' => 'required|string',
'content' => 'if_exist|string',
'status' => 'if_exist|string',
'status' => 'required|string',
'updated_at' => 'if_exist|valid_date',
'created_at' => 'if_exist|valid_date',
];
@ -41,23 +40,11 @@ class LoggerModel extends BaseModel
}
public function create(array $formDatas): LoggerEntity
{
$entity = new LoggerEntity($formDatas);
//로그인 여부 확인후 필요한 데이터 저장
if (session()->get(SESSION_NAMES['ISLOGIN'])) {
$auth = session()->get(SESSION_NAMES['AUTH']);
$entity->user_uid = $auth[AUTH_FIELDS['ID']];
}
foreach ($formDatas as $field => $value) {
$entity->$field = $this->changeFormData($field, $value);
}
return parent::create_process($entity);
return $this->create_process(new LoggerEntity(), $formDatas);
}
public function modify(LoggerEntity $entity, array $formDatas): LoggerEntity
{
foreach ($formDatas as $field => $value) {
$entity->$field = $this->changeFormData($field, $value);
}
return parent::modify_process($entity);
return $this->modify_process($entity, $formDatas);
}
//Index관련

View File

@ -7,7 +7,7 @@ use App\Entities\UserEntity;
class UserModel extends BaseModel
{
protected $table = 'tw_user';
// protected $primaryKey = 'uid';
protected $primaryKey = 'uid';
protected $useAutoIncrement = false;
protected $allowedFields = ['uid', 'id', 'email', 'passwd', 'name', 'role', 'status', 'updated_at'];
protected $validationRules = [
@ -43,18 +43,11 @@ class UserModel extends BaseModel
}
public function create(array $formDatas): UserEntity
{
$entity = new UserEntity($formDatas);
foreach ($formDatas as $field => $value) {
$entity->$field = $this->changeFormData($field, $value);
}
return parent::create_process($entity);
return $this->create_process(new UserEntity(), $formDatas);
}
public function modify(UserEntity $entity, array $formDatas): UserEntity
{
foreach ($formDatas as $field => $value) {
$entity->$field = $this->changeFormData($field, $value);
}
return parent::modify_process($entity);
return $this->modify_process($entity, $formDatas);
}
//Index관련

View File

@ -7,17 +7,17 @@ use App\Entities\UserSNSEntity;
class UserSNSModel extends BaseModel
{
protected $table = 'tw_user_sns';
// protected $primaryKey = 'uid';
protected $primaryKey = 'uid';
// protected $useAutoIncrement = true;
protected $allowedFields = ['user_uid', 'site', 'id', 'name', 'email', 'detail', 'status', 'updated_at', 'created_at'];
protected $validationRules = [
'user_uid' => 'if_exist|number',
'user_uid' => 'if_exist|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
'site' => 'required|string',
'id' => 'required|string',
'name' => 'required|string',
'email' => 'required|valid_email',
'detail' => 'required|string',
'status' => 'if_exist|string',
'detail' => 'if_exist|string',
'status' => 'required|string',
'updated_at' => 'if_exist|valid_date',
'created_at' => 'if_exist|valid_date',
];
@ -42,23 +42,13 @@ class UserSNSModel extends BaseModel
return $temps;
}
public function create(string $site, array $formDatas): UserSNSEntity
public function create(array $formDatas): UserSNSEntity
{
$entity = new UserSNSEntity();
$entity->site = $site;
$entity->detail = json_encode($formDatas);
$entity->status = 'standby';
foreach ($formDatas as $field => $value) {
$entity->$field = $this->changeFormData($field, $value);
}
return $this->create_process($entity);
return $this->create_process(new UserSNSEntity(), $formDatas);
}
public function modify(UserSNSEntity $entity, array $formDatas): UserSNSEntity
{
foreach ($formDatas as $field => $value) {
$entity->$field = $this->changeFormData($field, $value);
}
return $this->modify_process($entity);
return $this->modify_process($entity, $formDatas);
}
//Index관련