servermgrv2 init...
This commit is contained in:
parent
f304e172fc
commit
e0f7632966
@ -158,9 +158,9 @@ define('AUTH_ADAPTERS', [
|
||||
]);
|
||||
//등급 관련
|
||||
define('ROLES', [
|
||||
'CUSTOMERS' => ['user' => '일반회원', 'vip' => 'VIP회원'],
|
||||
'SELLERS' => ['bronze' => '일반판매자', 'silver' => '고급판매자', 'gold' => '파워리셀러'],
|
||||
'OPERATORS' => ['manager' => '관리자', 'cloudflare' => "Cloudflare관리자", 'director' => '감독자', 'master' => "마스터"],
|
||||
'user' => '일반회원', 'vip' => 'VIP회원',
|
||||
'bronze' => '일반판매자', 'silver' => '고급판매자', 'gold' => '파워리셀러',
|
||||
'manager' => '관리자', 'cloudflare' => "Cloudflare관리자", 'director' => '감독자', 'master' => "마스터",
|
||||
]);
|
||||
define('STATUS', ["use" => "사용", "unuse" => "사용않함",]);
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@ 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
|
||||
{
|
||||
@ -19,30 +20,32 @@ class BoardController extends \App\Controllers\Admin\AdminController
|
||||
$this->_model = new BoardModel();
|
||||
$this->_defines = [
|
||||
'insert' => [
|
||||
'fields' => ['board_category', 'title', 'content', 'passwd', 'confirmpassword', 'status'],
|
||||
'fields' => ['board_category', 'title', 'content', 'passwd', 'confirmpassword', 'upload_file', 'status'],
|
||||
'fieldFilters' => ['board_category', 'user_uid', 'status'],
|
||||
'fieldRules' => [
|
||||
'board_category' => 'required|string',
|
||||
'title' => 'required|string',
|
||||
'content' => 'required|string',
|
||||
'passwd' => 'if_exist|trim|string',
|
||||
'confirmpassword' => 'if_exist|trim|matches[passwd]',
|
||||
'view_cnt' => 'if_exist|numeric',
|
||||
'status' => 'if_exist|string',
|
||||
'board_category' => 'required|string',
|
||||
'title' => 'required|string',
|
||||
'content' => 'required|string',
|
||||
'passwd' => 'if_exist|trim|string',
|
||||
'confirmpassword' => 'if_exist|trim|matches[passwd]',
|
||||
'view_cnt' => 'if_exist|numeric',
|
||||
'status' => 'if_exist|string',
|
||||
'upload_file' => 'if_exist|uploaded[upload_file]|is_image[upload_file]|mime_in[upload_file,image/jpg,image/jpeg,image/gif,image/png,image/webp]|max_size[upload_file,100]|max_dims[upload_file,1024,768]'
|
||||
]
|
||||
],
|
||||
'update' => [
|
||||
'fields' => ['board_category', 'title', 'content', 'passwd', 'confirmpassword', 'status'],
|
||||
'fields' => ['board_category', 'title', 'content', 'passwd', 'confirmpassword', 'upload_file', 'status'],
|
||||
'fieldFilters' => ['board_category', 'user_uid', 'status'],
|
||||
'fieldRules' => [
|
||||
'board_category' => 'required|string',
|
||||
'title' => 'required|string',
|
||||
'content' => 'required|string',
|
||||
'passwd' => 'if_exist|trim|string',
|
||||
'confirmpassword' => 'if_exist|trim|matches[passwd]',
|
||||
'view_cnt' => 'if_exist|numeric',
|
||||
'status' => 'if_exist|string',
|
||||
]
|
||||
'board_category' => 'required|string',
|
||||
'title' => 'required|string',
|
||||
'content' => 'required|string',
|
||||
'passwd' => 'if_exist|trim|string',
|
||||
'confirmpassword' => 'if_exist|trim|matches[passwd]',
|
||||
'view_cnt' => 'if_exist|numeric',
|
||||
'status' => 'if_exist|string',
|
||||
'upload_file' => 'if_exist|uploaded[upload_file]|is_image[upload_file]|mime_in[upload_file,image/jpg,image/jpeg,image/gif,image/png,image/webp]|max_size[upload_file,100]|max_dims[upload_file,1024,768]',
|
||||
],
|
||||
],
|
||||
'view' => [
|
||||
'fields' => ['board_category', 'user_uid', 'title', 'view_cnt', 'status', 'updated_at', 'created_at', 'content'],
|
||||
@ -63,6 +66,29 @@ class BoardController extends \App\Controllers\Admin\AdminController
|
||||
$this->_viewPath = strtolower($this->_className);
|
||||
$this->_viewDatas['title'] = lang($this->_className . '.title');
|
||||
$this->_viewDatas['className'] = $this->_className;
|
||||
//게시판 초기화
|
||||
$this->initConfig();
|
||||
}
|
||||
|
||||
private function initConfig()
|
||||
{
|
||||
foreach ((array)lang($this->_className . '.BOARD_CATEGORY') as $key => $label) {
|
||||
$this->_viewDatas['board_configs'][$key] = [
|
||||
'isHierarchy' => getenv("board.{$key}.hierarchy") ?: false,
|
||||
'isAccess' => getenv("board.{$key}.access") ?: true,
|
||||
'isAccessRoles' => getenv("board.{$key}.access.roles") ?: array_values(ROLES),
|
||||
'isRead' => getenv("board.{$key}.read") ?: true,
|
||||
'isReadRoles' => getenv("board.{$key}.read.roles") ?: array_values(ROLES),
|
||||
'isWrite' => getenv("board.{$key}.write") ?: false,
|
||||
'isWriteRoles' => getenv("board.{$key}.write.roles") ?: array_values(ROLES),
|
||||
'isReply' => getenv("board.{$key}.reply") ?: false,
|
||||
'isReplyRoles' => getenv("board.{$key}.reply.roles") ?: array_values(ROLES),
|
||||
'isUpload' => getenv("board.{$key}.upload") ?: false,
|
||||
'isUploadRoles' => getenv("board.{$key}.upload.roles") ?: array_values(ROLES),
|
||||
];
|
||||
}
|
||||
// echo var_export($this->_viewDatas['board_configs'], true);
|
||||
// exit;
|
||||
}
|
||||
|
||||
private function getUserModel(): UserModel
|
||||
@ -89,8 +115,26 @@ class BoardController extends \App\Controllers\Admin\AdminController
|
||||
}
|
||||
}
|
||||
|
||||
//Field별 Form Datas 처리용
|
||||
protected function getFieldFormData(string $field, $entity = null)
|
||||
{
|
||||
switch ($field) {
|
||||
case 'upload_file':
|
||||
$this->_viewDatas['fieldDatas'][$field] = $this->single_upload_procedure($field, $entity);
|
||||
break;
|
||||
default:
|
||||
return parent::getFieldFormData($field, $entity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
////Action 모음
|
||||
//Insert관련
|
||||
protected function insert_process()
|
||||
{
|
||||
// upload처리
|
||||
return parent::insert_process();
|
||||
}
|
||||
final public function insert()
|
||||
{
|
||||
return $this->insert_procedure();
|
||||
@ -100,6 +144,11 @@ class BoardController extends \App\Controllers\Admin\AdminController
|
||||
{
|
||||
return $this->update_procedure($uid);
|
||||
}
|
||||
//Reply 관련
|
||||
final public function reply(int $uid)
|
||||
{
|
||||
return $this->reply_procedure($uid);
|
||||
}
|
||||
//Toggle관련
|
||||
final public function toggle($uid, string $field)
|
||||
{
|
||||
@ -116,6 +165,12 @@ class BoardController extends \App\Controllers\Admin\AdminController
|
||||
return $this->delete_procedure($uid);
|
||||
}
|
||||
//View 관련
|
||||
protected function view_process($entity)
|
||||
{
|
||||
// view_cnt에 추가하기위함
|
||||
$this->_model->increaseViewCount($entity->getPrimaryKey());
|
||||
return parent::view_process($entity);
|
||||
}
|
||||
final public function view($uid)
|
||||
{
|
||||
return $this->view_procedure($uid);
|
||||
@ -130,10 +185,4 @@ class BoardController extends \App\Controllers\Admin\AdminController
|
||||
{
|
||||
return $this->excel_procedure();
|
||||
}
|
||||
//추가기능
|
||||
//Reply 관련
|
||||
final public function reply(int $uid)
|
||||
{
|
||||
return $this->reply_procedure($uid);
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,26 +65,26 @@ class UserSNSController extends \App\Controllers\Admin\AdminController
|
||||
}
|
||||
|
||||
////Action 모음
|
||||
//Insert관련
|
||||
// final public function insert()
|
||||
// {
|
||||
// return $this->insert_procedure();
|
||||
// }
|
||||
// //Update관련
|
||||
// final public function update($uid)
|
||||
// {
|
||||
// return $this->update_procedure($uid);
|
||||
// }
|
||||
// Insert관련
|
||||
final public function insert()
|
||||
{
|
||||
return $this->insert_procedure();
|
||||
}
|
||||
//Update관련
|
||||
final public function update($uid)
|
||||
{
|
||||
return $this->update_procedure($uid);
|
||||
}
|
||||
//Toggle관련
|
||||
final public function toggle($uid, string $field)
|
||||
{
|
||||
return $this->toggle_procedure($uid, $field);
|
||||
}
|
||||
// //Batchjob 관련
|
||||
// final public function batchjob()
|
||||
// {
|
||||
// return $this->batchjob_procedure();
|
||||
// }
|
||||
//Batchjob 관련
|
||||
final public function batchjob()
|
||||
{
|
||||
return $this->batchjob_procedure();
|
||||
}
|
||||
//Delete 관련
|
||||
final public function delete($uid)
|
||||
{
|
||||
|
||||
@ -79,14 +79,14 @@ abstract class BaseController extends Controller
|
||||
{
|
||||
switch ($field) {
|
||||
default:
|
||||
$temps = lang($this->_className . '.' . strtoupper($field));
|
||||
if (!is_array($temps)) {
|
||||
throw new \Exception(__FUNCTION__ . "에서 {$field}의 데이터가 array가 아닙니다.\n" . var_export($temps, true));
|
||||
$fieldFormOptionDatas = (array)lang($this->_className . '.' . strtoupper($field));
|
||||
if (!is_array($fieldFormOptionDatas)) {
|
||||
throw new \Exception(__FUNCTION__ . "에서 {$field}의 데이터가 array가 아닙니다.\n" . var_export($fieldFormOptionDatas, true));
|
||||
}
|
||||
return array_merge(
|
||||
[DEFAULTS['EMPTY'] => lang($this->_className . '.label.' . $field) . ' 선택'],
|
||||
lang($this->_className . '.' . strtoupper($field))
|
||||
);
|
||||
return [
|
||||
DEFAULTS['EMPTY'] => lang($this->_className . '.label.' . $field) . ' 선택',
|
||||
...$fieldFormOptionDatas
|
||||
];
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -117,6 +117,73 @@ abstract class BaseController extends Controller
|
||||
return $tempRules;
|
||||
}
|
||||
|
||||
//Field별 Form Datas 처리용
|
||||
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]}"
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Upload FIle관련
|
||||
protected function upload_file_process($upfile)
|
||||
{
|
||||
$fileName = "";
|
||||
if ($upfile->isValid() && !$upfile->hasMoved()) {
|
||||
$fileName = $upfile->getRandomName();
|
||||
$upfile->move(PATHS['UPLOAD'], $fileName);
|
||||
//move시 중복된파일명이 있다면 파일명이 바뀌므로 여기서 한번더 파일명 확인 필요
|
||||
$fileName = $upfile->getRandomName();
|
||||
}
|
||||
return $fileName;
|
||||
}
|
||||
protected function single_upload_procedure(string $field, $entity = null)
|
||||
{
|
||||
$upfile = $this->request->getFile($field);
|
||||
$fileName = $this->upload_file_process($upfile);
|
||||
// $fileDatas=array();
|
||||
// if ($upfile->isValid() && !$upfile->hasMoved()) {
|
||||
// $filepath = PATHS['UPLOAD'] . $upfile->store();
|
||||
// $fileDatas = [
|
||||
// 'uploaded_fileinfo' => new \CodeIgniter\Files\File($filepath)
|
||||
// ];
|
||||
// return $fileDatas;
|
||||
// }
|
||||
return $fileName;
|
||||
}
|
||||
protected function multiple_upload_procedure(string $field, $entity = null): array
|
||||
{
|
||||
//Multiple파일의경우 html에서는 필드명[]를 넣어야하며
|
||||
//rule에서 "uploaded[필드명.0]|is_image[필드명]~~" 이런식으로 넣어야함
|
||||
$fileNames = array();
|
||||
if ($upfiles = $this->request->getFiles()) {
|
||||
foreach ($upfiles[$field] as $upfile) {
|
||||
if ($upfile->isValid() && !$upfile->hasMoved()) {
|
||||
$fileName = $this->upload_file_process($upfile);
|
||||
array_push(
|
||||
$this->_viewDatas['fieldDatas'][$field],
|
||||
$fileName
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $fileNames;
|
||||
}
|
||||
|
||||
//Insert관련
|
||||
protected function insert_init()
|
||||
{
|
||||
@ -150,8 +217,7 @@ abstract class BaseController extends Controller
|
||||
//변경된 값 적용
|
||||
$this->_viewDatas['fieldDatas'] = array();
|
||||
foreach ($this->_viewDatas['fields'] as $field) {
|
||||
$this->_viewDatas['fieldDatas'][$field] = rtrim($this->request->getVar($field));
|
||||
Log::add("info", "{$field} : {$this->_viewDatas['fieldDatas'][$field]}");
|
||||
$this->getFieldFormData($field);
|
||||
}
|
||||
//변경할 값 확인
|
||||
if (!$this->validate($this->_viewDatas['fieldRules'])) {
|
||||
@ -217,16 +283,7 @@ abstract class BaseController extends Controller
|
||||
//변경된 값 적용
|
||||
$this->_viewDatas['fieldDatas'] = array();
|
||||
foreach ($this->_viewDatas['fields'] as $field) {
|
||||
$this->_viewDatas['fieldDatas'][$field] = rtrim($this->request->getVar($field));
|
||||
if ($entity->$field != $this->_viewDatas['fieldDatas'][$field]) {
|
||||
// 기존값을 DB에서 수정전까지 유지하기위해서
|
||||
// $entity->$field = $this->_viewDatas['fieldDatas'][$field];
|
||||
//암호는 보안상 log에 남지 않게하기 위함
|
||||
Log::add(
|
||||
$field == 'passwd' ? "debug" : "info",
|
||||
"{$field} : {$entity->$field} => {$this->_viewDatas['fieldDatas'][$field]}"
|
||||
);
|
||||
}
|
||||
$this->getFieldFormData($field, $entity);
|
||||
}
|
||||
//변경할 값 확인
|
||||
if (!$this->validate($this->_viewDatas['fieldRules'])) {
|
||||
|
||||
@ -21,4 +21,17 @@ CREATE TABLE tw_board (
|
||||
created_at timestamp NOT NULL DEFAULT current_timestamp(),
|
||||
PRIMARY KEY (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 ='게시판 정보';
|
||||
|
||||
CREATE TABLE tw_board_file (
|
||||
uid int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
tw_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 '실제파일명',
|
||||
status varchar(10) NOT NULL DEFAULT 'use' COMMENT 'use: 사용, unuse: 사용않함 등등',
|
||||
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)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT ='게시판 File정보';
|
||||
@ -32,6 +32,9 @@ function getFieldForm_BoardHelper($field, $value, array $formOptions, array $att
|
||||
case 'content':
|
||||
return form_textarea($field, html_entity_decode($value), [...$attributes, 'class' => 'editor', 'rows' => '20', 'cols' => '100']);
|
||||
break;
|
||||
case 'upload_file':
|
||||
return form_upload($field);
|
||||
break;
|
||||
default:
|
||||
return form_input($field, $value, [...$attributes, 'size' => '80']);
|
||||
break;
|
||||
|
||||
@ -13,6 +13,7 @@ return [
|
||||
'passwd' => "암호",
|
||||
'confirmpassword' => "암호확인",
|
||||
'view_cnt' => "조회수",
|
||||
'upload_file' => "UploadFile",
|
||||
'status' => "상태",
|
||||
'updated_at' => "수정일",
|
||||
'created_at' => "작성일"
|
||||
|
||||
@ -77,13 +77,21 @@ abstract class CommonModel extends Model
|
||||
//계층형구조구현
|
||||
final protected function setHierarchyCreate($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));
|
||||
}
|
||||
return $entity;
|
||||
}
|
||||
//부모의 그룹과 grpno가 같고, 부모의 grporder보다 1 큰것을 grporder+1을 해서 update
|
||||
private function setHierarchyUpdate($entity)
|
||||
final protected function setHierarchyReply($entity, $replyEntity)
|
||||
{
|
||||
// return false;
|
||||
//부모의 그룹과 grpno가 같고, 부모의 grporder보다 1 큰것을 grporder+1을 해서 update
|
||||
//escape -> false옵션 반드시 있어야함
|
||||
$this->builder()->set('grporder', 'grporder+1', false);
|
||||
$this->builder()->where([
|
||||
@ -93,10 +101,7 @@ abstract class CommonModel extends Model
|
||||
$this->builder()->update();
|
||||
// echo $this->getLastQuery();
|
||||
// exit;
|
||||
}
|
||||
final protected function setHierarchyReply($entity, $replyEntity)
|
||||
{
|
||||
$this->setHierarchyUpdate($entity);
|
||||
|
||||
//reply용 설정
|
||||
$replyEntity->grpno = $entity->grpno;
|
||||
$replyEntity->grporder = $entity->grporder + 1;
|
||||
@ -161,6 +166,17 @@ abstract class CommonModel extends Model
|
||||
return $entity;
|
||||
}
|
||||
|
||||
//View관련 (게시판등의 조회수 증가함수)
|
||||
final public function increaseViewCount($uid, $field = 'view_cnt', int $cnt = 1)
|
||||
{
|
||||
//escape -> false옵션 반드시 있어야함
|
||||
$this->builder()->set($field, "{$field}+{$cnt}", false);
|
||||
$this->builder()->where($this->primaryKey, $uid);
|
||||
$this->builder()->update();
|
||||
// echo $this->getLastQuery();
|
||||
// exit;
|
||||
}
|
||||
|
||||
//Index관련
|
||||
public function setIndexWordFilter(string $word)
|
||||
{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<?= $this->extend('layouts/admin') ?>
|
||||
<?= $this->section('content') ?>
|
||||
<?= $this->include('templates/admin/header'); ?>
|
||||
<?= form_open(current_url(), $forms['attributes'], $forms['hiddens']) ?>
|
||||
<?= form_open_multipart(current_url(), $forms['attributes'], $forms['hiddens']) ?>
|
||||
<table class="table table-bordered table-hover table-striped indexTable ">
|
||||
<?php foreach ($fields as $field) : ?>
|
||||
<tr>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<?= $this->extend('layouts/admin') ?>
|
||||
<?= $this->section('content') ?>
|
||||
<?= $this->include('templates/admin/header'); ?>
|
||||
<?= form_open(current_url(), $forms['attributes'], $forms['hiddens']) ?>
|
||||
<?= form_open_multipart(current_url(), $forms['attributes'], $forms['hiddens']) ?>
|
||||
<table class="table table-bordered table-hover table-striped indexTable ">
|
||||
<?php foreach ($fields as $field) : ?>
|
||||
<tr>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<?= $this->extend('layouts/admin') ?>
|
||||
<?= $this->section('content') ?>
|
||||
<?= $this->include('templates/admin/header'); ?>
|
||||
<?= form_open(current_url(), $forms['attributes'], $forms['hiddens']) ?>
|
||||
<?= form_open_multipart(current_url(), $forms['attributes'], $forms['hiddens']) ?>
|
||||
<table class="table table-bordered table-hover table-striped indexTable ">
|
||||
<?php foreach ($fields as $field) : ?>
|
||||
<tr>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user