servermgrv2 init...
This commit is contained in:
parent
80f8b18202
commit
fac3cd62a9
@ -82,6 +82,8 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au
|
||||
$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,director']);
|
||||
$routes->get('toggle/(:num)/(:hash)', 'BoardController::toggle/$1/$2', ['filter' => 'authFilter:master,director']);
|
||||
$routes->post('batchjob', 'BoardController::batchjob', ['filter' => 'authFilter:master,director']);
|
||||
|
||||
@ -130,4 +130,10 @@ class BoardController extends \App\Controllers\Admin\AdminController
|
||||
{
|
||||
return $this->excel_procedure();
|
||||
}
|
||||
//추가기능
|
||||
//Reply 관련
|
||||
final public function reply(int $uid)
|
||||
{
|
||||
return $this->reply_procedure($uid);
|
||||
}
|
||||
}
|
||||
|
||||
@ -258,6 +258,59 @@ abstract class BaseController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
//Reply관련
|
||||
protected function reply_init()
|
||||
{
|
||||
return $this->update_init();
|
||||
}
|
||||
protected function reply_form_init()
|
||||
{
|
||||
return $this->update_form_init();
|
||||
}
|
||||
protected function reply_form_process($entity)
|
||||
{
|
||||
return $entity;
|
||||
}
|
||||
final public function reply_form($uid)
|
||||
{
|
||||
try {
|
||||
$entity = $this->_model->getEntity($uid);
|
||||
$this->reply_init();
|
||||
$this->reply_form_init();
|
||||
$this->_viewDatas['entity'] = $this->update_form_process($entity);
|
||||
return view($this->_viewPath . '/reply', $this->_viewDatas);
|
||||
} catch (\Exception $e) {
|
||||
return alert_CommonHelper($e->getMessage(), 'back');
|
||||
}
|
||||
}
|
||||
protected function reply_validate($entity)
|
||||
{
|
||||
return $this->update_validate($entity);
|
||||
}
|
||||
protected function reply_process($entity)
|
||||
{
|
||||
return $this->_model->reply($entity, $this->_viewDatas['fieldDatas']);
|
||||
}
|
||||
protected function reply_procedure($uid)
|
||||
{
|
||||
$message = "";
|
||||
try {
|
||||
$entity = $this->_model->getEntity($uid);
|
||||
$this->reply_init();
|
||||
$entity = $this->reply_validate($entity);
|
||||
$entity = $this->reply_process($entity);
|
||||
$message = "{$entity->getTitle()} " . __FUNCTION__ . " 완료하였습니다.";
|
||||
Log::save("{$this->_viewDatas['title']} {$message}");
|
||||
return alert_CommonHelper($message, $this->_session->get(SESSION_NAMES['RETURN_URL']));
|
||||
} catch (\Exception $e) {
|
||||
$message = __FUNCTION__ . " 실패하였습니다.";
|
||||
Log::add("warning", $e->getMessage());
|
||||
Log::add("warning", var_export($this->_viewDatas['fieldDatas'], true));
|
||||
Log::save("{$this->_viewDatas['title']} {$message}", false);
|
||||
return redirect()->back()->withInput()->with("error", $message . "<br>\n{$e->getMessage()}");
|
||||
}
|
||||
}
|
||||
|
||||
//Toggle 관련
|
||||
protected function toggle_init($field)
|
||||
{
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
DROP TABLE IF EXISTS tw_board;
|
||||
-- 1. 게시물 추가전 grpno에 해당하는 기존게시물의 grpord를 +1씩증가 작업
|
||||
-- update tw_board set grpord=grpord+1 where grpno=그룹번호 and grpord > 선택한 grpno
|
||||
-- update tw_board set grporder=grporder+1 where grpno=그룹번호 and grporder > 선택한 grpno
|
||||
-- 2. 게시물 추가시 작업
|
||||
-- insert tw_board grpno=그룹번호,grpord=grpord+1,grpdpt=grpdpt+1
|
||||
-- insert tw_board grpno=그룹번호,grporder=grporder+1,grpdepth=grpdepth+1
|
||||
-- 3. 게시물 조회시 작업
|
||||
-- select * from tw_board order by grpno desc,grpord asc
|
||||
-- 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와 같음',
|
||||
grpord int(5) UNSIGNED NOT NULL DEFAULT 1 COMMENT 'Group순서: 상위가없을시 0부터시작',
|
||||
grpdpt int(3) UNSIGNED NOT NULL DEFAULT 1 COMMENT 'Group깊이: 상위가없을시 1부터시작 , 상위 grpdpt+1씩 추가필요',
|
||||
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 varchar(10) NOT NULL COMMENT '게시판구분',
|
||||
user_uid varchar(36) NULL COMMENT '작성자 정보',
|
||||
title varchar(255) NOT NULL COMMENT '제목',
|
||||
|
||||
@ -65,7 +65,11 @@ function getFieldIndex_Row_BoardHelper($field, array $row, array $fieldFilters,
|
||||
{
|
||||
switch ($field) {
|
||||
case 'title':
|
||||
return anchor(current_url() . '/view/' . $row['uid'], $row[$field], ["target" => "_self"]);
|
||||
return sprintf(
|
||||
'<div style="text-align:left; padding-left:%spx;">%s</div>',
|
||||
$row['grpdepth'] * 30,
|
||||
anchor(current_url() . '/reply/' . $row['uid'], $row[$field], ["target" => "_self"])
|
||||
);
|
||||
break;
|
||||
case 'updated_at':
|
||||
case 'created_at':
|
||||
|
||||
@ -9,11 +9,11 @@ class BoardModel extends CommonModel
|
||||
protected $table = 'tw_board';
|
||||
// protected $primaryKey = 'uid';
|
||||
// protected $useAutoIncrement = true;
|
||||
protected $allowedFields = ['grpno', 'grpord', 'grpdpt', 'board_category', 'user_uid', 'title', 'content', 'passwd', 'view_cnt', 'status', 'updated_at'];
|
||||
protected $allowedFields = ['grpno', 'grporder', 'grpdepth', 'board_category', 'user_uid', 'title', 'content', 'passwd', 'view_cnt', 'status', 'updated_at'];
|
||||
protected $validationRules = [
|
||||
'grpno' => 'if_exist|numeric',
|
||||
'grpord' => 'if_exist|numeric',
|
||||
'grpdpt' => 'if_exist|numeric',
|
||||
'grporder' => 'if_exist|numeric',
|
||||
'grpdepth' => 'if_exist|numeric',
|
||||
'board_category' => 'required|string',
|
||||
'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',
|
||||
@ -44,23 +44,7 @@ class BoardModel extends CommonModel
|
||||
}
|
||||
return $temps;
|
||||
}
|
||||
private function changeFormData($field, $value)
|
||||
{
|
||||
switch ($field) {
|
||||
case 'passwd':
|
||||
return $value ? password_hash($value, PASSWORD_DEFAULT) : "";
|
||||
break;
|
||||
case 'content':
|
||||
return htmlentities($value);
|
||||
break;
|
||||
case 'status':
|
||||
return $value ?: DEFAULTS['STATUS'];
|
||||
break;
|
||||
default:
|
||||
return $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function create(array $formDatas): BoardEntity
|
||||
{
|
||||
$entity = new BoardEntity($formDatas);
|
||||
@ -72,7 +56,10 @@ class BoardModel extends CommonModel
|
||||
foreach ($formDatas as $field => $value) {
|
||||
$entity->$field = $this->changeFormData($field, $value);
|
||||
}
|
||||
return parent::create_process($entity);
|
||||
$entity = parent::create_process($entity);
|
||||
//계층형
|
||||
$entity = $this->setHierarchyCreate($entity);
|
||||
return $entity;
|
||||
}
|
||||
public function modify(BoardEntity $entity, array $formDatas): BoardEntity
|
||||
{
|
||||
@ -81,6 +68,24 @@ class BoardModel extends CommonModel
|
||||
}
|
||||
return parent::modify_process($entity);
|
||||
}
|
||||
public function reply(BoardEntity $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);
|
||||
}
|
||||
|
||||
//Index관련
|
||||
public function setIndexWordFilter(string $word)
|
||||
@ -92,7 +97,7 @@ class BoardModel extends CommonModel
|
||||
public function setIndexOrderBy($field, $order = 'DESC')
|
||||
{
|
||||
$this->orderBy("grpno", "DESC");
|
||||
$this->orderBy("grpord", "ASC");
|
||||
$this->orderBy("grporder", "ASC");
|
||||
parent::setIndexOrderBy($field, $order);
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,6 +73,55 @@ abstract class CommonModel extends Model
|
||||
substr($hashing, 20, 12)
|
||||
);
|
||||
}
|
||||
|
||||
//계층형구조구현
|
||||
final protected function setHierarchyCreate($entity)
|
||||
{
|
||||
$entity->grpno = $entity->getPrimaryKey();
|
||||
return $entity;
|
||||
}
|
||||
//부모의 그룹과 grpno가 같고, 부모의 grporder보다 1 큰것을 grporder+1을 해서 update
|
||||
private function setHierarchyUpdate($entity)
|
||||
{
|
||||
// return false;
|
||||
//escape -> false옵션 반드시 있어야함
|
||||
$this->builder()->set('grporder', 'grporder+1', false);
|
||||
$this->builder()->where([
|
||||
'grpno' => $entity->grpno,
|
||||
'grporder >' => $entity->grporder
|
||||
]);
|
||||
$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;
|
||||
$replyEntity->grpdepth = $entity->grpdepth + 1;
|
||||
return $replyEntity;
|
||||
}
|
||||
|
||||
protected function changeFormData($field, $value)
|
||||
{
|
||||
switch ($field) {
|
||||
case 'passwd':
|
||||
return $value ? password_hash($value, PASSWORD_DEFAULT) : "";
|
||||
break;
|
||||
case 'content':
|
||||
return htmlentities($value);
|
||||
break;
|
||||
case 'status':
|
||||
return $value ?: DEFAULTS['STATUS'];
|
||||
break;
|
||||
default:
|
||||
return $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
final protected function create_process($entity)
|
||||
{
|
||||
//primaryKey 할당
|
||||
@ -80,11 +129,16 @@ abstract class CommonModel extends Model
|
||||
$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;
|
||||
@ -94,6 +148,7 @@ abstract class CommonModel extends Model
|
||||
}
|
||||
final protected function modify_process($entity)
|
||||
{
|
||||
$entity->updated_at = time();
|
||||
if ($entity->hasChanged()) {
|
||||
if (!$this->save($entity)) {
|
||||
Log::add("error", __FUNCTION__ . "에서 호출:" . $this->getLastQuery());
|
||||
|
||||
@ -47,14 +47,15 @@ class LoggerModel extends CommonModel
|
||||
$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);
|
||||
}
|
||||
public function modify(LoggerEntity $entity, array $formDatas): LoggerEntity
|
||||
{
|
||||
foreach ($formDatas as $field => $value) {
|
||||
if ($entity->$field != $formDatas[$field]) {
|
||||
$entity->$field = $value;
|
||||
}
|
||||
$entity->$field = $this->changeFormData($field, $value);
|
||||
}
|
||||
return parent::modify_process($entity);
|
||||
}
|
||||
|
||||
@ -45,16 +45,14 @@ class UserModel extends CommonModel
|
||||
{
|
||||
$entity = new UserEntity($formDatas);
|
||||
foreach ($formDatas as $field => $value) {
|
||||
$entity->$field = $field === 'passwd' ? password_hash($value, PASSWORD_DEFAULT) : $value;
|
||||
$entity->$field = $this->changeFormData($field, $value);
|
||||
}
|
||||
return parent::create_process($entity);
|
||||
}
|
||||
public function modify(UserEntity $entity, array $formDatas): UserEntity
|
||||
{
|
||||
foreach ($formDatas as $field => $value) {
|
||||
if ($entity->$field != $formDatas[$field]) {
|
||||
$entity->$field = $field === 'passwd' ? password_hash($value, PASSWORD_DEFAULT) : $value;
|
||||
}
|
||||
$entity->$field = $this->changeFormData($field, $value);
|
||||
}
|
||||
return parent::modify_process($entity);
|
||||
}
|
||||
|
||||
@ -41,23 +41,22 @@ class UserSNSModel extends CommonModel
|
||||
}
|
||||
return $temps;
|
||||
}
|
||||
|
||||
public function create(string $site, array $formDatas): UserSNSEntity
|
||||
{
|
||||
$entity = new UserSNSEntity();
|
||||
$entity->site = $site;
|
||||
$entity->id = $formDatas['id'];
|
||||
$entity->name = $formDatas['name'];
|
||||
$entity->email = $formDatas['email'];
|
||||
$entity->detail = json_encode($formDatas);
|
||||
$entity->status = 'standby';
|
||||
foreach ($formDatas as $field => $value) {
|
||||
$entity->$field = $this->changeFormData($field, $value);
|
||||
}
|
||||
return $this->create_process($entity);
|
||||
}
|
||||
public function modify(UserSNSEntity $entity, array $formDatas): UserSNSEntity
|
||||
{
|
||||
foreach ($formDatas as $field => $value) {
|
||||
if ($entity->$field != $formDatas[$field]) {
|
||||
$entity->$field = $value;
|
||||
}
|
||||
$entity->$field = $this->changeFormData($field, $value);
|
||||
}
|
||||
return $this->modify_process($entity);
|
||||
}
|
||||
|
||||
32
app/Views/admin/board/reply.php
Normal file
32
app/Views/admin/board/reply.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?= $this->extend('layouts/admin') ?>
|
||||
<?= $this->section('content') ?>
|
||||
<?= $this->include('templates/admin/header'); ?>
|
||||
<?= form_open(current_url(), $forms['attributes'], $forms['hiddens']) ?>
|
||||
<table class="table table-bordered table-hover table-striped indexTable ">
|
||||
<?php foreach ($fields as $field) : ?>
|
||||
<tr>
|
||||
<td nowrap style="background-color:#e8ebe9; width:10%; text-align:right; padding-right:20px;">
|
||||
<?= getFieldLabel_BoardHelper($field, $fieldRules) ?>
|
||||
</td>
|
||||
<td style="text-align:left; padding-left:20px;">
|
||||
<?= getFieldForm_BoardHelper($field, is_null(old($field)) ? $entity->$field : old($field), $fieldFormOptions) ?>
|
||||
<?= validation_show_error($field); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<tr>
|
||||
<td valign="bottom" colspan="2" style="text-align:center;"><?= form_submit('', '수정', array("class" => "btn btn-outline btn-primary")); ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
<?= form_close(); ?>
|
||||
<?php if (session()->getFlashdata('error')) : ?><?= session()->getFlashdata('error') ?><?php endif ?>
|
||||
<script src="<?= base_url() ?>vendors/tinymce/tinymce/tinymce.min.js" referrerpolicy="origin"></script>
|
||||
<script>
|
||||
tinymce.init({
|
||||
selector: '.editor',
|
||||
theme: 'silver',
|
||||
height: 500
|
||||
});
|
||||
</script>
|
||||
<?= $this->include('templates/admin/footer'); ?>
|
||||
<?= $this->endSection() ?>
|
||||
Loading…
Reference in New Issue
Block a user