diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 1846dee..11f24bc 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -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']); diff --git a/app/Controllers/Admin/BoardController.php b/app/Controllers/Admin/BoardController.php index 953d5ac..ecba48a 100644 --- a/app/Controllers/Admin/BoardController.php +++ b/app/Controllers/Admin/BoardController.php @@ -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); + } } diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php index 5995fdd..f7af559 100644 --- a/app/Controllers/BaseController.php +++ b/app/Controllers/BaseController.php @@ -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 . "
\n{$e->getMessage()}"); + } + } + //Toggle 관련 protected function toggle_init($field) { diff --git a/app/Database/board.sql b/app/Database/board.sql index 8d0bf02..d35f13e 100644 --- a/app/Database/board.sql +++ b/app/Database/board.sql @@ -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 '제목', diff --git a/app/Helpers/Admin/Board_helper.php b/app/Helpers/Admin/Board_helper.php index a1e9dea..d1c2276 100644 --- a/app/Helpers/Admin/Board_helper.php +++ b/app/Helpers/Admin/Board_helper.php @@ -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( + '
%s
', + $row['grpdepth'] * 30, + anchor(current_url() . '/reply/' . $row['uid'], $row[$field], ["target" => "_self"]) + ); break; case 'updated_at': case 'created_at': diff --git a/app/Models/BoardModel.php b/app/Models/BoardModel.php index a4e4677..67ee00a 100644 --- a/app/Models/BoardModel.php +++ b/app/Models/BoardModel.php @@ -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); } } diff --git a/app/Models/CommonModel.php b/app/Models/CommonModel.php index 3c9ee43..7f162db 100644 --- a/app/Models/CommonModel.php +++ b/app/Models/CommonModel.php @@ -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 "
"; + // 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()); diff --git a/app/Models/LoggerModel.php b/app/Models/LoggerModel.php index 5b98918..4f89e39 100644 --- a/app/Models/LoggerModel.php +++ b/app/Models/LoggerModel.php @@ -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); } diff --git a/app/Models/UserModel.php b/app/Models/UserModel.php index a07433b..5194512 100644 --- a/app/Models/UserModel.php +++ b/app/Models/UserModel.php @@ -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); } diff --git a/app/Models/UserSNSModel.php b/app/Models/UserSNSModel.php index 95da6b7..ed7817a 100644 --- a/app/Models/UserSNSModel.php +++ b/app/Models/UserSNSModel.php @@ -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); } diff --git a/app/Views/admin/board/reply.php b/app/Views/admin/board/reply.php new file mode 100644 index 0000000..f187aee --- /dev/null +++ b/app/Views/admin/board/reply.php @@ -0,0 +1,32 @@ +extend('layouts/admin') ?> +section('content') ?> +include('templates/admin/header'); ?> + + + + + + + + + + + +
+ + + $field : old($field), $fieldFormOptions) ?> + +
"btn btn-outline btn-primary")); ?>
+ +getFlashdata('error')) : ?>getFlashdata('error') ?> + + +include('templates/admin/footer'); ?> +endSection() ?> \ No newline at end of file