diff --git a/app/Config/Constants.php b/app/Config/Constants.php index b24722f..ac19746 100644 --- a/app/Config/Constants.php +++ b/app/Config/Constants.php @@ -140,7 +140,7 @@ define('SESSION_NAMES', [ 'ISLOGIN' => "islogined", 'AUTH' => 'auth' ]); -define('AUTH_FIELDS', ['id', 'title', 'role']); +define('AUTH_FIELDS', ['ID' => 'id', 'TITLE' => 'title', 'ROLE' => 'role']); //인증 관련 define('AUTH_ADAPTERS', [ @@ -158,9 +158,9 @@ define('AUTH_ADAPTERS', [ ]); //등급 관련 define('ROLES', [ - 'CUSTOMERS' => ['user' => '일반회원', 'vip' => 'VIP회원'], - 'SELLERS' => ['bronze' => '일반판매자', 'silver' => '고급판매자', 'gold' => '파워리셀러'], - 'OPERATORS' => ['manager' => '관리자', 'cloudflare' => "Cloudflare관리자", 'director' => '감독자', 'master' => "마스터"], + 'guest' => '비회원', 'user' => '일반회원', 'vip' => 'VIP회원', + 'bronze' => '일반판매자', 'silver' => '고급판매자', 'gold' => '파워리셀러', + 'manager' => '관리자', 'cloudflare' => "Cloudflare관리자", 'director' => '감독자', 'master' => "마스터", ]); define('STATUS', ["use" => "사용", "unuse" => "사용않함",]); @@ -180,6 +180,7 @@ foreach (PATHS as $key => $path) { //아이콘 및 Sound관련 define('ICONS', [ 'NEW' => '', + 'REPLY' => '', 'DELETE' => '', 'RELOAD' => '', 'SETTING' => '', diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 1846dee..3d09778 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -74,14 +74,28 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au $routes->get('toggle/(:num)/(:hash)', 'LoggerController::toggle/$1/$2', ['filter' => 'authFilter:master,director']); $routes->post('batchjob', 'LoggerController::batchjob', ['filter' => 'authFilter:master']); }); + $routes->group('boardconfig', static function ($routes) { + $routes->get('', 'BoardConfigController::index'); + $routes->get('excel', 'BoardConfigController::excel/$1'); + $routes->get('insert', 'BoardConfigController::insert_form', ['filter' => 'authFilter:master,director']); + $routes->post('insert', 'BoardConfigController::insert', ['filter' => 'authFilter:master,director']); + $routes->get('update/(:uuid)', 'BoardConfigController::update_form/$1'); + $routes->post('update/(:uuid)', 'BoardConfigController::update/$1'); + $routes->get('view/(:uuid)', 'BoardConfigController::view/$1'); + $routes->get('delete/(:uuid)', 'BoardConfigController::delete/$1', ['filter' => 'authFilter:master,director']); + $routes->get('toggle/(:uuid)/(:hash)', 'BoardConfigController::toggle/$1/$2', ['filter' => 'authFilter:master,director']); + $routes->post('batchjob', 'BoardConfigController::batchjob', ['filter' => 'authFilter:master,director']); + }); $routes->group('board', static function ($routes) { $routes->get('', 'BoardController::index'); - $routes->get('excel', 'BoardController::excel'); + $routes->get('excel', 'BoardController::excel/$1'); $routes->get('insert', 'BoardController::insert_form', ['filter' => 'authFilter:master,director']); $routes->post('insert', 'BoardController::insert', ['filter' => 'authFilter:master,director']); $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/BoardConfigController.php b/app/Controllers/Admin/BoardConfigController.php new file mode 100644 index 0000000..33b6b4a --- /dev/null +++ b/app/Controllers/Admin/BoardConfigController.php @@ -0,0 +1,123 @@ +_className .= '/BoardConfig'; + $this->_model = new BoardConfigModel(); + $this->_defines = [ + 'insert' => [ + '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', + 'head' => 'if_exist|string', + 'tail' => 'if_exist|string', + 'status' => 'if_exist|string', + ] + ], + 'update' => [ + 'fields' => ['name', 'isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status', 'head', 'tail'], + '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', + 'head' => 'if_exist|string', + 'tail' => 'if_exist|string', + 'status' => 'if_exist|string', + ] + ], + 'view' => [ + 'fields' => ['name', 'isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status', 'head', 'tail'], + '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', + 'head' => 'if_exist|string', + 'tail' => 'if_exist|string', + 'status' => 'if_exist|string', + ] + ], + 'index' => [ + 'fields' => ['name', 'isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status', 'created_at'], + 'fieldFilters' => ['isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status', 'created_at'], + 'batchjobFilters' => ['isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status'], + ], + 'excel' => [ + 'fields' => ['name', 'isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status', 'created_at'], + 'fieldFilters' => ['isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status', 'created_at'], + ], + ]; + helper($this->_className); + $this->_viewPath = strtolower($this->_className); + $this->_viewDatas['title'] = lang($this->_className . '.title'); + $this->_viewDatas['className'] = $this->_className; + } + + ////Action 모음 + //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(); + } + //Delete 관련 + final public function delete($uid) + { + return $this->delete_procedure($uid); + } + //View 관련 + final public function view($uid) + { + return $this->view_procedure($uid); + } + //Index 관련 + final public function index() + { + return $this->index_procedure(); + } + //Excel 관련 + final public function excel() + { + return $this->excel_procedure(); + } +} diff --git a/app/Controllers/Admin/BoardController.php b/app/Controllers/Admin/BoardController.php index 953d5ac..63d48b7 100644 --- a/app/Controllers/Admin/BoardController.php +++ b/app/Controllers/Admin/BoardController.php @@ -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); diff --git a/app/Controllers/Admin/UserSNSController.php b/app/Controllers/Admin/UserSNSController.php index a1305b4..d94ab51 100644 --- a/app/Controllers/Admin/UserSNSController.php +++ b/app/Controllers/Admin/UserSNSController.php @@ -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) { diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php index 5995fdd..dc05846 100644 --- a/app/Controllers/BaseController.php +++ b/app/Controllers/BaseController.php @@ -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'])) { @@ -258,6 +315,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..531dced 100644 --- a/app/Database/board.sql +++ b/app/Database/board.sql @@ -1,16 +1,35 @@ + +DROP TABLE IF EXISTS tw_board_config; +CREATE TABLE tw_board_config ( + uid varchar(36) NOT NULL, + name varchar(255) NOT NULL COMMENT '게시판명', + isaccess varchar(255) NOT NULL DEFAULT 'manager|cloudflare|director|master' COMMENT '접근권한', + isread varchar(255) NOT NULL DEFAULT 'manager|cloudflare|director|master' COMMENT '읽기권한', + iswrite varchar(255) NOT NULL DEFAULT 'manager|cloudflare|director|master' COMMENT '쓰기권한', + isreply varchar(255) NOT NULL DEFAULT 'manager|cloudflare|director|master' COMMENT '답글권한', + isupload varchar(255) NOT NULL DEFAULT 'manager|cloudflare|director|master' COMMENT 'Upload권한', + isdownload varchar(255) NOT NULL DEFAULT 'manager|cloudflare|director|master' COMMENT 'Download권한', + head text NOT NULL DEFAULT ' ' COMMENT '게시판 위 내용', + tail text NOT NULL DEFAULT ' ' 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) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT ='게시판 설정정보'; + 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씩 추가필요', - board_category varchar(10) NOT NULL COMMENT '게시판구분', + 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 '게시판구분', user_uid varchar(36) NULL COMMENT '작성자 정보', title varchar(255) NOT NULL COMMENT '제목', content text NOT NULL COMMENT '내용', @@ -20,5 +39,19 @@ 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 (user_uid) REFERENCES tw_user (uid) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT ='게시판 정보'; \ No newline at end of file +) 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정보'; \ No newline at end of file diff --git a/app/Entities/CommonEntity.php b/app/Entities/BaseEntity.php similarity index 78% rename from app/Entities/CommonEntity.php rename to app/Entities/BaseEntity.php index 194d7e8..f88ec67 100644 --- a/app/Entities/CommonEntity.php +++ b/app/Entities/BaseEntity.php @@ -4,7 +4,7 @@ namespace App\Entities; use CodeIgniter\Entity\Entity; -abstract class CommonEntity extends Entity +abstract class BaseEntity extends Entity { abstract public function getPrimaryKey(); abstract public function getTitle(); diff --git a/app/Entities/BoardConfigEntity.php b/app/Entities/BoardConfigEntity.php new file mode 100644 index 0000000..59f9cda --- /dev/null +++ b/app/Entities/BoardConfigEntity.php @@ -0,0 +1,29 @@ +attributes['uid']; + } + public function getTitle() + { + return $this->attributes['name']; + } + public function getHead() + { + return $this->attributes['head']; + } + public function getTail() + { + return $this->attributes['tail']; + } +} diff --git a/app/Entities/BoardEntity.php b/app/Entities/BoardEntity.php index 22befdf..9b496d4 100644 --- a/app/Entities/BoardEntity.php +++ b/app/Entities/BoardEntity.php @@ -2,9 +2,9 @@ namespace App\Entities; -use App\Entities\CommonEntity; +use App\Entities\BaseEntity; -class BoardEntity extends CommonEntity +class BoardEntity extends BaseEntity { protected $datamap = []; protected $dates = ['created_at', 'updated_at', 'deleted_at']; diff --git a/app/Entities/HPILOEntity.php b/app/Entities/HPILOEntity.php index 9055fbe..e7eb728 100644 --- a/app/Entities/HPILOEntity.php +++ b/app/Entities/HPILOEntity.php @@ -2,9 +2,9 @@ namespace App\Entities; -use App\Entities\CommonEntity; +use App\Entities\BaseEntity; -class HPILOEntity extends CommonEntity +class HPILOEntity extends BaseEntity { protected $datamap = []; protected $dates = ['created_at', 'updated_at', 'deleted_at']; diff --git a/app/Entities/LoggerEntity.php b/app/Entities/LoggerEntity.php index 40fccc4..e066c50 100644 --- a/app/Entities/LoggerEntity.php +++ b/app/Entities/LoggerEntity.php @@ -2,17 +2,20 @@ namespace App\Entities; -use App\Entities\CommonEntity; -class LoggerEntity extends CommonEntity +use App\Entities\BaseEntity; + +class LoggerEntity extends BaseEntity { protected $datamap = []; protected $dates = ['created_at', 'updated_at', 'deleted_at']; protected $casts = []; - public function getPrimaryKey(){ + public function getPrimaryKey() + { return $this->attributes['uid']; } - public function getTitle(){ + public function getTitle() + { return $this->attributes['title']; } } diff --git a/app/Entities/UserEntity.php b/app/Entities/UserEntity.php index a187cdc..c3b8031 100644 --- a/app/Entities/UserEntity.php +++ b/app/Entities/UserEntity.php @@ -2,9 +2,9 @@ namespace App\Entities; -use App\Entities\CommonEntity; +use App\Entities\BaseEntity; -class UserEntity extends CommonEntity +class UserEntity extends BaseEntity { protected $datamap = []; protected $dates = ['created_at', 'updated_at', 'deleted_at']; diff --git a/app/Entities/UserSNSEntity.php b/app/Entities/UserSNSEntity.php index 1834b41..01ccc62 100644 --- a/app/Entities/UserSNSEntity.php +++ b/app/Entities/UserSNSEntity.php @@ -2,9 +2,9 @@ namespace App\Entities; -use App\Entities\CommonEntity; +use App\Entities\BaseEntity; -class UserSNSEntity extends CommonEntity +class UserSNSEntity extends BaseEntity { protected $datamap = []; protected $dates = ['created_at', 'updated_at', 'deleted_at']; diff --git a/app/Filters/AuthFilter.php b/app/Filters/AuthFilter.php index 211d8f5..48180b9 100644 --- a/app/Filters/AuthFilter.php +++ b/app/Filters/AuthFilter.php @@ -30,11 +30,13 @@ class AuthFilter implements FilterInterface $auth = session()->get(SESSION_NAMES['AUTH']); // dd($auth); // 회원 ROLE이 필요ROLE 목록에 존재하지 않으면(ACL) - if (!in_array($auth['role'], $arguments)) { + if (!in_array($auth[AUTH_FIELDS['ROLE']], $arguments)) { return redirect()->to('/login')->with( 'error', sprintf( - "{$auth['role']},{$$auth['title']}회원님은 접속에 필요한 권한[%s]이 없습니다. ", + "%s,%s회원님은 접속에 필요한 권한[%s]이 없습니다. ", + $auth[AUTH_FIELDS['ROLE']], + $auth[AUTH_FIELDS['TITLE']], implode(",", $arguments) ) ); diff --git a/app/Helpers/Admin/BoardConfig_helper.php b/app/Helpers/Admin/BoardConfig_helper.php new file mode 100644 index 0000000..dcec12f --- /dev/null +++ b/app/Helpers/Admin/BoardConfig_helper.php @@ -0,0 +1,103 @@ +%s", implode(" ", $attributes), lang("Admin/BoardConfig.label.{$field}")); + break; + } +} + +//header.php에서 getFieldForm_Helper사용 +function getFieldForm_BoardConfigHelper($field, $value, array $formOptions, array $attributes = array()) +{ + $value = is_null($value) ? DEFAULTS['EMPTY'] : $value; + switch ($field) { + case 'isaccess': + case 'isread': + case 'iswrite': + case 'isreply': + case 'isupload': + case 'isdownload': + case 'status': + return form_multiselect($field, $formOptions[$field], explode('|', $value), [...$attributes, 'row' => 10]); + break; + case 'updated_at': + case 'created_at': + return form_input($field, $value, [...$attributes, 'class' => 'calender']); + break; + case 'passwd': + case 'confirmpassword': + return form_password($field, DEFAULTS['EMPTY'], $attributes); + break; + case 'head': + case 'tail': + return form_textarea($field, html_entity_decode($value), [...$attributes, 'class' => 'editor', 'rows' => '20', 'cols' => '100']); + break; + default: + return form_input($field, $value, $attributes); + break; + } +} // + +function getFieldView_BoardConfigHelper($field, $entity, array $fieldFilters, array $fieldFormOptions, array $attributes = array()) +{ + switch ($field) { + default: + if (in_array($field, $fieldFilters)) { + return getFieldForm_BoardConfigHelper($field, $entity->$field, $fieldFormOptions, $attributes); + } + return $entity->$field; + break; + } +} // + +function getFieldFilter_BoardConfigHelper($field, $value, array $formOptions, array $attributes = array()) +{ + $value = is_null($value) ? DEFAULTS['EMPTY'] : $value; + switch ($field) { + case 'isaccess': + case 'isread': + case 'iswrite': + case 'isreply': + case 'isupload': + case 'isdownload': + case 'status': + return form_dropdown($field, $formOptions[$field], explode('|', $value), [...$attributes, 'row' => 10]); + break; + default: + return getFieldForm_BoardConfigHelper($field, $value, $formOptions, $attributes); + break; + } +} // + +function getFieldIndex_Column_BoardConfigHelper($field, $order_field, $order_value, array $attributes = array()) +{ + $label = lang("Admin/BoardConfig.label.{$field}"); + $label = $field == $order_field ? sprintf('%s ', $label, $order_value == 'ASC' ? "up" : "down") : $label; + $order_value = $order_value == 'DESC' ? "ASC" : "DESC"; + return anchor(current_url() . "?order_field={$field}&order_value={$order_value}", $label, $attributes); +} // + +function getFieldIndex_Row_BoardConfigHelper($field, array $row, array $fieldFilters, $fieldFormOptions, $attributes = array()): string +{ + switch ($field) { + case 'name': + return anchor(current_url() . '/view/' . $row['uid'], $row[$field], ["target" => "_self"]); + break; + case 'updated_at': + case 'created_at': + return isset($row[$field]) ? str_split($row[$field], 10)[0] : ""; + break; + default: + if (in_array($field, $fieldFilters)) { + $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $row['uid'], $field, $field); + return getFieldFilter_BoardConfigHelper($field, $row[$field], $fieldFormOptions, $attributes); + } + return $row[$field]; + break; + } +} // \ No newline at end of file diff --git a/app/Helpers/Admin/Board_helper.php b/app/Helpers/Admin/Board_helper.php index a1e9dea..ebb5ccb 100644 --- a/app/Helpers/Admin/Board_helper.php +++ b/app/Helpers/Admin/Board_helper.php @@ -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; @@ -53,6 +56,16 @@ function getFieldView_BoardHelper($field, $entity, array $fieldFilters, array $f } } // +function getFieldFilter_BoardHelper($field, $value, array $formOptions, array $attributes = array()) +{ + $value = is_null($value) ? DEFAULTS['EMPTY'] : $value; + switch ($field) { + default: + return getFieldForm_BoardHelper($field, $value, $formOptions, $attributes); + break; + } +} // + function getFieldIndex_Column_BoardHelper($field, $order_field, $order_value, array $attributes = array()) { $label = lang("Admin/Board.label.{$field}"); @@ -65,7 +78,12 @@ 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  %s
', + $row['grpdepth'] * 30, + anchor(current_url() . '/view/' . $row['uid'], $row[$field], ["target" => "_self"]), + anchor(current_url() . '/reply/' . $row['uid'], ICONS['REPLY'], ["target" => "_self"]) + ); break; case 'updated_at': case 'created_at': @@ -74,7 +92,7 @@ function getFieldIndex_Row_BoardHelper($field, array $row, array $fieldFilters, default: if (in_array($field, $fieldFilters)) { $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $row['uid'], $field, $field); - return getFieldForm_BoardHelper($field, $row[$field], $fieldFormOptions, $attributes); + return getFieldFilter_BoardHelper($field, $row[$field], $fieldFormOptions, $attributes); } return $row[$field]; break; diff --git a/app/Helpers/Admin/Logger_helper.php b/app/Helpers/Admin/Logger_helper.php index adb8e80..77d5182 100644 --- a/app/Helpers/Admin/Logger_helper.php +++ b/app/Helpers/Admin/Logger_helper.php @@ -46,6 +46,16 @@ function getFieldView_LoggerHelper($field, $entity, array $fieldFilters, array $ } } // +function getFieldFilter_LoggerHelper($field, $value, array $formOptions, array $attributes = array()) +{ + $value = is_null($value) ? DEFAULTS['EMPTY'] : $value; + switch ($field) { + default: + return getFieldForm_LoggerHelper($field, $value, $formOptions, $attributes); + break; + } +} // + function getFieldIndex_Column_LoggerHelper($field, $order_field, $order_value, array $attributes = array()) { $label = lang("Admin/Logger.label.{$field}"); @@ -71,7 +81,7 @@ function getFieldIndex_Row_LoggerHelper($field, array $row, array $fieldFilters, default: if (in_array($field, $fieldFilters)) { $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $row['uid'], $field, $field); - return getFieldForm_LoggerHelper($field, $row[$field], $fieldFormOptions, $attributes); + return getFieldFilter_LoggerHelper($field, $row[$field], $fieldFormOptions, $attributes); } return $row[$field]; break; diff --git a/app/Helpers/Admin/UserSNS_helper.php b/app/Helpers/Admin/UserSNS_helper.php index 3bd3303..aa50cd6 100644 --- a/app/Helpers/Admin/UserSNS_helper.php +++ b/app/Helpers/Admin/UserSNS_helper.php @@ -43,6 +43,16 @@ function getFieldView_UserSNSHelper($field, $entity, array $fieldFilters, array } } // +function getFieldFilter_UserSNSHelper($field, $value, array $formOptions, array $attributes = array()) +{ + $value = is_null($value) ? DEFAULTS['EMPTY'] : $value; + switch ($field) { + default: + return getFieldForm_UserSNSHelper($field, $value, $formOptions, $attributes); + break; + } +} // + function getFieldIndex_Column_UserSNSHelper($field, $order_field, $order_value, array $attributes = array()) { $label = lang("Admin/UserSNS.label.{$field}"); @@ -64,7 +74,7 @@ function getFieldIndex_Row_UserSNSHelper($field, array $row, array $fieldFilters default: if (in_array($field, $fieldFilters)) { $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $row['uid'], $field, $field); - return getFieldForm_UserSNSHelper($field, $row[$field], $fieldFormOptions, $attributes); + return getFieldFilter_UserSNSHelper($field, $row[$field], $fieldFormOptions, $attributes); } return $row[$field]; break; diff --git a/app/Helpers/Admin/User_helper.php b/app/Helpers/Admin/User_helper.php index 7ed18ee..7015b80 100644 --- a/app/Helpers/Admin/User_helper.php +++ b/app/Helpers/Admin/User_helper.php @@ -46,6 +46,16 @@ function getFieldView_UserHelper($field, $entity, array $fieldFilters, array $fi } } // +function getFieldFilter_UserHelper($field, $value, array $formOptions, array $attributes = array()) +{ + $value = is_null($value) ? DEFAULTS['EMPTY'] : $value; + switch ($field) { + default: + return getFieldForm_UserHelper($field, $value, $formOptions, $attributes); + break; + } +} // + function getFieldIndex_Column_UserHelper($field, $order_field, $order_value, array $attributes = array()) { $label = lang("Admin/User.label.{$field}"); @@ -67,7 +77,7 @@ function getFieldIndex_Row_UserHelper($field, array $row, array $fieldFilters, $ default: if (in_array($field, $fieldFilters)) { $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $row['uid'], $field, $field); - return getFieldForm_UserHelper($field, $row[$field], $fieldFormOptions, $attributes); + return getFieldFilter_UserHelper($field, $row[$field], $fieldFormOptions, $attributes); } return $row[$field]; break; diff --git a/app/Language/en/Admin/Board.php b/app/Language/en/Admin/Board.php index 531f6b7..c86f4ae 100644 --- a/app/Language/en/Admin/Board.php +++ b/app/Language/en/Admin/Board.php @@ -13,6 +13,7 @@ return [ 'passwd' => "암호", 'confirmpassword' => "암호확인", 'view_cnt' => "조회수", + 'upload_file' => "UploadFile", 'status' => "상태", 'updated_at' => "수정일", 'created_at' => "작성일" diff --git a/app/Language/en/Admin/BoardConfig.php b/app/Language/en/Admin/BoardConfig.php new file mode 100644 index 0000000..e8fefdc --- /dev/null +++ b/app/Language/en/Admin/BoardConfig.php @@ -0,0 +1,26 @@ + "계정정보", + '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], +]; diff --git a/app/Libraries/Adapter/Auth/Adapter.php b/app/Libraries/Adapter/Auth/Adapter.php index 7b2ec5f..0497d75 100644 --- a/app/Libraries/Adapter/Auth/Adapter.php +++ b/app/Libraries/Adapter/Auth/Adapter.php @@ -50,7 +50,7 @@ abstract class Adapter { $this->_session->set(SESSION_NAMES['ISLOGIN'], true); $auths = []; - foreach (AUTH_FIELDS as $field) { + foreach (AUTH_FIELDS as $key => $field) { switch ($field) { case 'id': $auths[$field] = $entity->getPrimaryKey(); diff --git a/app/Models/CommonModel.php b/app/Models/BaseModel.php similarity index 62% rename from app/Models/CommonModel.php rename to app/Models/BaseModel.php index 3c9ee43..14f2639 100644 --- a/app/Models/CommonModel.php +++ b/app/Models/BaseModel.php @@ -4,9 +4,9 @@ namespace App\Models; use CodeIgniter\Model; use App\Libraries\Log\Log; -use App\Entities\CommonEntity; +use App\Entities\BaseEntity; -abstract class CommonModel extends Model +abstract class BaseModel extends Model { protected $DBGroup = 'default'; // protected $table = 'user'; @@ -41,8 +41,8 @@ abstract class CommonModel extends Model protected $beforeDelete = []; protected $afterDelete = []; - abstract public function getEntityByField($field, $value): ?CommonEntity; - abstract public function getEntity($uid): ?CommonEntity; + abstract public function getEntityByField($field, $value): ?BaseEntity; + 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 @@ -73,6 +73,60 @@ abstract class CommonModel extends Model substr($hashing, 20, 12) ); } + + //계층형구조구현 + 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; + } + final protected function setHierarchyReply($entity, $replyEntity) + { + //부모의 그룹과 grpno가 같고, 부모의 grporder보다 1 큰것을 grporder+1을 해서 update + //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; + + //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 +134,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 +153,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()); @@ -106,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) { diff --git a/app/Models/BoardConfigModel.php b/app/Models/BoardConfigModel.php new file mode 100644 index 0000000..de9d144 --- /dev/null +++ b/app/Models/BoardConfigModel.php @@ -0,0 +1,88 @@ + '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', + 'head' => 'if_exist|string', + 'tail' => 'if_exist|string', + 'status' => 'if_exist|string', + 'updated_at' => 'if_exist|valid_date', + 'created_at' => 'if_exist|valid_date', + ]; + + public function getEntityByField($field, $value): ?BoardConfigEntity + { + $entity = $this->asObject(BoardConfigEntity::class)->where($field, $value)->first(); + if (is_null($entity)) { + throw new \Exception("해당 데이터가 없습니다.\n {$field}->{$value}"); + } + return $entity; + } + public function getEntity($uid): ?BoardConfigEntity + { + return $this->getEntityByField($this->primaryKey, $uid); + } + public function getFieldFormOptions(array $wheres = array(), $temps = array()): array + { + foreach ($this->asObject(BoardConfigEntity::class)->where($wheres)->findAll() as $entity) { + $temps[$entity->getPrimaryKey()] = $entity->getTitle(); + } + return $temps; + } + + protected function changeFormData($field, $value) + { + switch ($field) { + case 'head': + case 'tail': + return htmlentities($value); + break; + default: + return $value; + break; + } + } + 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); + } + public function modify(BoardConfigEntity $entity, array $formDatas): BoardConfigEntity + { + foreach ($formDatas as $field => $value) { + $entity->$field = $this->changeFormData($field, $value); + } + return parent::modify_process($entity); + } + + //Index관련 + public function setIndexWordFilter(string $word) + { + parent::setIndexWordFilter($word); + $this->orLike('name', $word, 'both'); //befor , after , both + } + public function setIndexOrderBy($field, $order = 'ASC') + { + $this->orderBy("name", "ASC"); + parent::setIndexOrderBy($field, $order); + } +} diff --git a/app/Models/BoardModel.php b/app/Models/BoardModel.php index 801948d..a800997 100644 --- a/app/Models/BoardModel.php +++ b/app/Models/BoardModel.php @@ -4,25 +4,25 @@ namespace App\Models; use App\Entities\BoardEntity; -class BoardModel extends CommonModel +class BoardModel extends BaseModel { 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', - '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', + 'grpno' => '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', 'content' => 'required|string', 'passwd' => 'if_exist|trim|string', - 'view_cnt' => 'if_exist|numeric', - 'status' => 'if_exist|string', - 'updated_at' => 'if_exist|valid_date', - 'created_at' => 'if_exist|valid_date', + 'view_cnt' => 'if_exist|numeric', + 'status' => 'if_exist|string', + 'updated_at' => 'if_exist|valid_date', + 'created_at' => 'if_exist|valid_date', ]; public function getEntityByField($field, $value): ?BoardEntity @@ -44,35 +44,22 @@ 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); //로그인 여부 확인후 필요한 데이터 저장 if (session()->get(SESSION_NAMES['ISLOGIN'])) { $auth = session()->get(SESSION_NAMES['AUTH']); - $entity->user_uid = $auth['id']; + $entity->user_uid = $auth[AUTH_FIELDS['ID']]; } 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/HPILOModel.php b/app/Models/HPILOModel.php index a312b10..4d002df 100644 --- a/app/Models/HPILOModel.php +++ b/app/Models/HPILOModel.php @@ -4,7 +4,7 @@ namespace App\Models; use App\Entities\HPILOEntity; -class HPILOModel extends CommonModel +class HPILOModel extends BaseModel { protected $table = 'tw_hpilo'; // protected $primaryKey = 'uid'; diff --git a/app/Models/LoggerModel.php b/app/Models/LoggerModel.php index cb91808..4b23a6c 100644 --- a/app/Models/LoggerModel.php +++ b/app/Models/LoggerModel.php @@ -4,7 +4,7 @@ namespace App\Models; use App\Entities\LoggerEntity; -class LoggerModel extends CommonModel +class LoggerModel extends BaseModel { protected $table = 'tw_logger'; // protected $primaryKey = 'uid'; @@ -45,16 +45,17 @@ class LoggerModel extends CommonModel //로그인 여부 확인후 필요한 데이터 저장 if (session()->get(SESSION_NAMES['ISLOGIN'])) { $auth = session()->get(SESSION_NAMES['AUTH']); - $entity->user_uid = $auth['id']; + $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..533884c 100644 --- a/app/Models/UserModel.php +++ b/app/Models/UserModel.php @@ -4,7 +4,7 @@ namespace App\Models; use App\Entities\UserEntity; -class UserModel extends CommonModel +class UserModel extends BaseModel { protected $table = 'tw_user'; // protected $primaryKey = 'uid'; @@ -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..f6dfd6a 100644 --- a/app/Models/UserSNSModel.php +++ b/app/Models/UserSNSModel.php @@ -4,7 +4,7 @@ namespace App\Models; use App\Entities\UserSNSEntity; -class UserSNSModel extends CommonModel +class UserSNSModel extends BaseModel { protected $table = 'tw_user_sns'; // protected $primaryKey = 'uid'; @@ -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/index.php b/app/Views/admin/board/index.php index 4827a70..c319873 100644 --- a/app/Views/admin/board/index.php +++ b/app/Views/admin/board/index.php @@ -5,7 +5,7 @@
"get")) ?> @@ -35,7 +35,7 @@ diff --git a/app/Views/admin/board/insert.php b/app/Views/admin/board/insert.php index 537bb58..13660d6 100644 --- a/app/Views/admin/board/insert.php +++ b/app/Views/admin/board/insert.php @@ -1,7 +1,7 @@ extend('layouts/admin') ?> section('content') ?> include('templates/admin/header'); ?> - + diff --git a/app/Views/admin/board/reply.php b/app/Views/admin/board/reply.php new file mode 100644 index 0000000..1b1937a --- /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 diff --git a/app/Views/admin/board/update.php b/app/Views/admin/board/update.php index f187aee..1b1937a 100644 --- a/app/Views/admin/board/update.php +++ b/app/Views/admin/board/update.php @@ -1,7 +1,7 @@ extend('layouts/admin') ?> section('content') ?> include('templates/admin/header'); ?> - + diff --git a/app/Views/admin/boardconfig/index.php b/app/Views/admin/boardconfig/index.php new file mode 100644 index 0000000..6b21d51 --- /dev/null +++ b/app/Views/admin/boardconfig/index.php @@ -0,0 +1,49 @@ +extend('layouts/admin') ?> +section('content') ?> +include('templates/admin/header'); ?> +
+
+ "get")) ?> + + +
+
+ +
+ + + + + + + + onClick="indexRowCheckBoxToggle(this);"> + + + + + + + + +
번호작업
+ "checkbox_uid_{$row['uid']}", "name" => "batchjob_uids[]", "value" => $row['uid'], "class" => "batchjobuids_checkboxs"]); ?> + "_self"]) ?> + "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?>
+ + +
+
+ +
+ +include('templates/admin/footer'); ?> +endSection() ?> \ No newline at end of file diff --git a/app/Views/admin/boardconfig/insert.php b/app/Views/admin/boardconfig/insert.php new file mode 100644 index 0000000..2fe0e75 --- /dev/null +++ b/app/Views/admin/boardconfig/insert.php @@ -0,0 +1,24 @@ +extend('layouts/admin') ?> +section('content') ?> +include('templates/admin/header'); ?> + + + + + + + + + + + +
+ + + + +
"btn btn-outline btn-primary")); ?>
+ +getFlashdata('error')) : ?>getFlashdata('error') ?> +include('templates/admin/footer'); ?> +endSection() ?> \ No newline at end of file diff --git a/app/Views/admin/boardconfig/update.php b/app/Views/admin/boardconfig/update.php new file mode 100644 index 0000000..3134fb4 --- /dev/null +++ b/app/Views/admin/boardconfig/update.php @@ -0,0 +1,24 @@ +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 diff --git a/app/Views/admin/boardconfig/view.php b/app/Views/admin/boardconfig/view.php new file mode 100644 index 0000000..f479e12 --- /dev/null +++ b/app/Views/admin/boardconfig/view.php @@ -0,0 +1,15 @@ +extend('layouts/admin') ?> +section('content') ?> +include('templates/admin/header'); ?> + + + + + + + +
+ +
+include('templates/admin/footer'); ?> +endSection() ?> \ No newline at end of file diff --git a/app/Views/admin/logger/index.php b/app/Views/admin/logger/index.php index 1eaa5c4..aee6173 100644 --- a/app/Views/admin/logger/index.php +++ b/app/Views/admin/logger/index.php @@ -5,7 +5,7 @@
"get")) ?> @@ -33,7 +33,7 @@ diff --git a/app/Views/admin/user/index.php b/app/Views/admin/user/index.php index 60e0415..3dcc6eb 100644 --- a/app/Views/admin/user/index.php +++ b/app/Views/admin/user/index.php @@ -5,7 +5,7 @@
"get")) ?> @@ -35,7 +35,7 @@ diff --git a/app/Views/admin/usersns/index.php b/app/Views/admin/usersns/index.php index b2f35d9..7f0c8e8 100644 --- a/app/Views/admin/usersns/index.php +++ b/app/Views/admin/usersns/index.php @@ -5,7 +5,7 @@
"get")) ?> @@ -35,7 +35,7 @@ diff --git a/app/Views/layouts/admin/left_menu/board.php b/app/Views/layouts/admin/left_menu/board.php index 95df6ed..01426f9 100644 --- a/app/Views/layouts/admin/left_menu/board.php +++ b/app/Views/layouts/admin/left_menu/board.php @@ -1,3 +1,13 @@ +
+

+ +

+
\ No newline at end of file +

설정 관리

+
+ +
+
\ No newline at end of file diff --git a/app/Views/layouts/admin/member_link.php b/app/Views/layouts/admin/member_link.php index a0b5297..ff72dbf 100644 --- a/app/Views/layouts/admin/member_link.php +++ b/app/Views/layouts/admin/member_link.php @@ -3,10 +3,10 @@