diff --git a/app/Config/Routes.php b/app/Config/Routes.php
index 20ce5db..de20536 100644
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -66,13 +66,10 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au
$routes->get('delete/(:num)', 'UserSNSController::delete/$1');
$routes->get('toggle/(:num)/(:hash)', 'UserSNSController::toggle/$1/$2');
});
- $routes->group('logger', ['filter' => 'authFilter:master,director,cloudflare,manager'], static function ($routes) {
+ $routes->group('logger', static function ($routes) {
$routes->get('', 'LoggerController::index');
$routes->get('excel', 'LoggerController::excel');
$routes->get('view/(:num)', 'LoggerController::view/$1');
- $routes->get('delete/(:num)', 'LoggerController::delete/$1', ['filter' => 'authFilter:master']);
- $routes->get('toggle/(:num)/(:hash)', 'LoggerController::toggle/$1/$2');
- $routes->post('batchjob', 'LoggerController::batchjob');
});
$routes->group('boardconfig', static function ($routes) {
$routes->get('', 'BoardConfigController::index');
diff --git a/app/Controllers/Admin/BoardConfigController.php b/app/Controllers/Admin/BoardConfigController.php
index eecc3a6..152842c 100644
--- a/app/Controllers/Admin/BoardConfigController.php
+++ b/app/Controllers/Admin/BoardConfigController.php
@@ -14,75 +14,55 @@ class BoardConfigController extends \App\Controllers\Admin\AdminController
parent::initController($request, $response, $logger);
$this->_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_config.name]',
- 'isaccess' => 'required',
- 'isread' => 'required',
- 'iswrite' => 'required',
- 'isreply' => 'required',
- 'isupload' => 'required',
- 'isdownload' => 'required',
- 'head' => 'if_exist|string',
- 'tail' => 'if_exist|string',
- 'status' => 'if_exist|string',
- ]
+ 'fields' => $this->_model->getFields(),
+ 'fieldRules' => $this->_model->getFieldRules($this->_model->getFields()),
+ 'fieldFilters' => $this->_model->getFieldFilters($this->_model->getFields()),
],
'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',
- 'isread' => 'required',
- 'iswrite' => 'required',
- 'isreply' => 'required',
- 'isupload' => 'required',
- 'isdownload' => 'required',
- 'head' => 'if_exist|string',
- 'tail' => 'if_exist|string',
- 'status' => 'if_exist|string',
- ]
+ 'fields' => $this->_model->getFields(),
+ 'fieldRules' => $this->_model->getFieldRules($this->_model->getFields()),
+ 'fieldFilters' => $this->_model->getFieldFilters($this->_model->getFields()),
],
'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',
- 'isread' => 'required',
- 'iswrite' => 'required',
- 'isreply' => 'required',
- 'isupload' => 'required',
- 'isdownload' => 'required',
- 'head' => 'if_exist|string',
- 'tail' => 'if_exist|string',
- 'status' => 'if_exist|string',
- ]
+ 'fields' => $this->_model->getFields(),
+ 'fieldRules' => $this->_model->getFieldRules($this->_model->getFields()),
+ 'fieldFilters' => $this->_model->getFieldFilters($this->_model->getFields()),
],
'index' => [
- 'fields' => ['name', 'isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status', 'created_at'],
- 'fieldFilters' => ['isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status'],
- 'batchjobFilters' => ['status'],
+ 'fields' => $this->_model->getFields([], ['head', 'tail']),
+ 'fieldFilters' => $this->_model->getFieldFilters($this->_model->getFields()),
+ 'batchjobFilters' => $this->_model->getFieldFilters($this->_model->getFields(), ['isupload', 'isdownload']),
],
'excel' => [
- 'fields' => ['name', 'isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status', 'created_at'],
- 'fieldFilters' => ['isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status'],
+ 'fields' => $this->_model->getFields(),
+ 'fieldFilters' => $this->_model->getFieldFilters($this->_model->getFields()),
],
];
+
helper($this->_className);
$this->_viewPath = strtolower($this->_className);
$this->_viewDatas['title'] = lang($this->_className . '.title');
$this->_viewDatas['className'] = $this->_className;
}
+ //Field별 Form Option용
+ protected function getFieldFormOption(string $field): array
+ {
+ switch ($field) {
+ default:
+ return parent::getFieldFormOption($field);
+ break;
+ }
+ }
+
////Action 모음
//Insert관련
final public function insert()
{
+ $this->_defines[__FUNCTION__]['fieldRules']['name'] .= '|is_unique[tw_board_config.name]';
return $this->insert_procedure();
}
//Update관련
diff --git a/app/Controllers/Admin/BoardController.php b/app/Controllers/Admin/BoardController.php
index d6519a2..b873dfb 100644
--- a/app/Controllers/Admin/BoardController.php
+++ b/app/Controllers/Admin/BoardController.php
@@ -17,50 +17,34 @@ class BoardController extends \App\Controllers\Admin\AdminController
parent::initController($request, $response, $logger);
$this->_className .= '/Board';
$this->_model = new BoardModel();
+
$this->_defines = [
'insert' => [
- 'fields' => ['board_config_uid', 'title', 'content', 'passwd', 'confirmpassword', 'upload_file', 'status'],
- 'fieldFilters' => ['board_config_uid', 'user_uid', 'status'],
- 'fieldRules' => [
- 'board_config_uid' => '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]'
- ]
+ 'fields' => $this->_model->getFields([], ['user_uid', 'view_cnt']),
+ 'fieldRules' => $this->_model->getFieldRules($this->_model->getFields()),
+ 'fieldFilters' => $this->_model->getFieldFilters($this->_model->getFields()),
],
'update' => [
- 'fields' => ['board_config_uid', 'title', 'content', 'passwd', 'confirmpassword', 'upload_file', 'status'],
- 'fieldFilters' => ['board_config_uid', 'user_uid', 'status'],
- 'fieldRules' => [
- 'board_config_uid' => '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]',
- ],
+ 'fields' => $this->_model->getFields([], ['user_uid', 'view_cnt']),
+ 'fieldRules' => $this->_model->getFieldRules($this->_model->getFields()),
+ 'fieldFilters' => $this->_model->getFieldFilters($this->_model->getFields()),
],
'view' => [
- 'fields' => ['board_config_uid', 'user_uid', 'title', 'view_cnt', 'status', 'updated_at', 'created_at', 'content'],
- 'fieldFilters' => ['board_config_uid', 'user_uid', 'status'],
- 'fieldRules' => ['board_config_uid', 'user_uid', 'status'],
+ 'fields' => $this->_model->getFields(),
+ 'fieldRules' => $this->_model->getFieldRules($this->_model->getFields()),
+ 'fieldFilters' => $this->_model->getFieldFilters($this->_model->getFields()),
],
'index' => [
- 'fields' => ['board_config_uid', 'user_uid', 'title', 'view_cnt', 'status', 'updated_at', 'created_at'],
- 'fieldFilters' => ['board_config_uid', 'user_uid', 'status'],
- 'batchjobFilters' => ['board_config_uid', 'user_uid', 'status'],
+ 'fields' => $this->_model->getFields([], ['upload_file', 'passwd', 'content']),
+ 'fieldFilters' => $this->_model->getFieldFilters($this->_model->getFields()),
+ 'batchjobFilters' => $this->_model->getFieldFilters($this->_model->getFields()),
],
'excel' => [
- 'fields' => ['board_config_uid', 'user_uid', 'title', 'view_cnt', 'status', 'updated_at', 'created_at'],
- 'fieldFilters' => ['board_config_uid', 'user_uid', 'status'],
+ 'fields' => $this->_model->getFields([], ['upload_file', 'passwd']),
+ 'fieldFilters' => $this->_model->getFieldFilters($this->_model->getFields()),
],
];
+
helper($this->_className);
$this->_viewPath = strtolower($this->_className);
$this->_viewDatas['title'] = lang($this->_className . '.title');
@@ -88,16 +72,21 @@ class BoardController extends \App\Controllers\Admin\AdminController
}
//Field별 Form Datas 처리용
- protected function getFieldFormData(string $field, $entity = null)
+ protected function getFieldFormData(string $field, $entity = null): array
{
switch ($field) {
+ case 'passwd':
+ $this->_viewDatas['fieldDatas'][$field] = $this->request->getVar($field);
+ $this->_viewDatas['fieldDatas']['confirmpassword'] = $this->request->getVar('confirmpassword');
+ break;
case 'upload_file':
- return $this->single_upload_procedure($field, $entity);
+ $this->_viewDatas['fieldDatas'][$field] = $this->single_upload_procedure($field, $entity);
break;
default:
return parent::getFieldFormData($field, $entity);
break;
}
+ return $this->_viewDatas['fieldDatas'];
}
////Action 모음
diff --git a/app/Controllers/Admin/LoggerController.php b/app/Controllers/Admin/LoggerController.php
index 425804d..53e0d0d 100644
--- a/app/Controllers/Admin/LoggerController.php
+++ b/app/Controllers/Admin/LoggerController.php
@@ -3,7 +3,6 @@
namespace App\Controllers\Admin;
use App\Models\LoggerModel;
-use App\Models\UserModel;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
@@ -17,22 +16,28 @@ class LoggerController extends \App\Controllers\Admin\AdminController
parent::initController($request, $response, $logger);
$this->_className .= '/Logger';
$this->_model = new LoggerModel();
- $this->_defines = [
- 'view' => [
- 'fields' => ['user_uid', 'title', 'content', 'status', 'created_at'],
- 'fieldFilters' => ['user_uid'],
- 'fieldRules' => [],
- ],
- 'index' => [
- 'fields' => ['user_uid', 'title', 'status', 'created_at'],
- 'fieldFilters' => ['user_uid'],
- 'batchjobFilters' => [],
- ],
- 'excel' => [
- 'fields' => ['user_uid', 'title', 'status', 'created_at'],
- 'fieldFilters' => ['user_uid'],
- ],
- ];
+
+ $this->_defines = [];
+ $this->_defines['insert'] = [];
+ $this->_defines['insert']['fields'] = $this->_model->getFields();
+ $this->_defines['insert']['fieldRules'] = $this->_model->getFieldRules($this->_defines['insert']['fields']);
+ $this->_defines['insert']['fieldFilters'] = $this->_model->getFieldFilters();
+ $this->_defines['update'] = [];
+ $this->_defines['update']['fields'] = $this->_defines['insert']['fields'];
+ $this->_defines['update']['fieldRules'] = $this->_model->getFieldRules($this->_defines['update']['fields']);
+ $this->_defines['update']['fieldFilters'] = $this->_model->getFieldFilters();
+ $this->_defines['view'] = [];
+ $this->_defines['view']['fields'] = [...$this->_model->getFields(), 'updated_at', 'created_at'];
+ $this->_defines['view']['fieldRules'] = $this->_model->getFieldRules($this->_defines['view']['fields']);
+ $this->_defines['view']['fieldFilters'] = $this->_model->getFieldFilters();
+ $this->_defines['index'] = [];
+ $this->_defines['index']['fields'] = [...$this->_model->getFields(), 'created_at'];
+ $this->_defines['index']['fieldFilters'] = $this->_model->getFieldFilters();
+ $this->_defines['index']['batchjobFilters'] = ['status'];
+ $this->_defines['excel'] = [];
+ $this->_defines['excel']['fields'] = $this->_defines['index']['fields'];
+ $this->_defines['excel']['fieldFilters'] = $this->_model->getFieldFilters();
+
helper($this->_className);
$this->_viewPath = strtolower($this->_className);
$this->_viewDatas['title'] = lang($this->_className . '.title');
@@ -51,30 +56,30 @@ class LoggerController extends \App\Controllers\Admin\AdminController
////Action 모음
//Insert관련
- // final public function insert()
- // {
- // return $this->insert_procedure();
- // }
+ final public function insert()
+ {
+ return $this->insert_procedure();
+ }
//Update관련
- // final public function update($uid)
- // {
- // return $this->update_procedure($uid);
- // }
+ final public function update($uid)
+ {
+ return $this->update_procedure($uid);
+ }
// //Toggle관련
- // final public function toggle($uid, string $field)
- // {
- // return $this->toggle_procedure($uid, $field);
- // }
+ final public function toggle($uid, string $field)
+ {
+ return $this->toggle_procedure($uid, $field);
+ }
//Batchjob 관련
- // final public function batchjob()
- // {
- // return $this->batchjob_procedure();
- // }
+ final public function batchjob()
+ {
+ return $this->batchjob_procedure();
+ }
//Delete 관련
- // final public function delete($uid)
- // {
- // return $this->delete_procedure($uid);
- // }
+ final public function delete($uid)
+ {
+ return $this->delete_procedure($uid);
+ }
//View 관련
final public function view($uid)
{
diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php
index fda34b6..21608d4 100644
--- a/app/Controllers/Admin/UserController.php
+++ b/app/Controllers/Admin/UserController.php
@@ -14,47 +14,54 @@ class UserController extends \App\Controllers\Admin\AdminController
parent::initController($request, $response, $logger);
$this->_className .= '/User';
$this->_model = new UserModel();
- $this->_defines = [
- 'insert' => [
- 'fields' => ['id', 'passwd', 'confirmpassword', 'name', 'email', 'role', 'status'],
- 'fieldFilters' => ['role', 'status'],
- 'fieldRules' => [
- 'id' => 'required|min_length[4]|max_length[20]|is_unique[tw_user.id]',
- 'confirmpassword' => 'required|trim|matches[passwd]',
- ]
- ],
- 'update' => [
- 'fields' => ['passwd', 'confirmpassword', 'name', 'email', 'role', 'status'],
- 'fieldFilters' => ['role', 'status'],
- 'fieldRules' => [
- 'confirmpassword' => 'required|trim|matches[passwd]',
- ]
- ],
- 'view' => [
- 'fields' => ['id', 'name', 'email', 'role', 'status', 'updated_at', 'created_at'],
- 'fieldFilters' => ['role', 'status'],
- 'fieldRules' => [],
- ],
- 'index' => [
- 'fields' => ['id', 'name', 'email', 'role', 'status', 'created_at'],
- 'fieldFilters' => ['role', 'status'],
- 'batchjobFilters' => ['role', 'status'],
- ],
- 'excel' => [
- 'fields' => ['id', 'name', 'email', 'role', 'status', 'created_at'],
- 'fieldFilters' => ['role', 'status'],
- ],
- ];
+
+ $this->_defines = [];
+ $this->_defines['insert'] = [];
+ $this->_defines['insert']['fields'] = ['id', 'passwd', 'confirmpassword', 'name', 'email', 'role', 'status'];
+ $this->_defines['insert']['fieldRules'] = $this->_model->getFieldRules($this->_defines['insert']['fields']);
+ $this->_defines['insert']['fieldFilters'] = $this->_model->getFieldFilters();
+ $this->_defines['update'] = [];
+ $this->_defines['update']['fields'] = ['passwd', 'confirmpassword', 'name', 'email', 'role', 'status'];
+ $this->_defines['update']['fieldRules'] = $this->_model->getFieldRules($this->_defines['update']['fields']);
+ $this->_defines['update']['fieldFilters'] = $this->_model->getFieldFilters();
+ $this->_defines['view'] = [];
+ $this->_defines['view']['fields'] = ['updated_at', 'created_at'];
+ $this->_defines['view']['fieldRules'] = $this->_model->getFieldRules($this->_defines['view']['fields']);
+ $this->_defines['view']['fieldFilters'] = $this->_model->getFieldFilters();
+ $this->_defines['index'] = [];
+ $this->_defines['index']['fields'] = [...$this->_model->getFields(), 'created_at'];
+ $this->_defines['index']['fieldFilters'] = $this->_model->getFieldFilters();
+ $this->_defines['index']['batchjobFilters'] = ['status'];
+ $this->_defines['excel'] = [];
+ $this->_defines['excel']['fields'] = $this->_defines['index']['fields'];
+ $this->_defines['excel']['fieldFilters'] = $this->_model->getFieldFilters();
+
helper($this->_className);
$this->_viewPath = strtolower($this->_className);
$this->_viewDatas['title'] = lang($this->_className . '.title');
$this->_viewDatas['className'] = $this->_className;
}
+ //Field별 Form Datas 처리용
+ protected function getFieldFormData(string $field, $entity = null): array
+ {
+ switch ($field) {
+ case 'passwd':
+ $this->_viewDatas['fieldDatas'][$field] = $this->request->getVar($field);
+ $this->_viewDatas['fieldDatas']['confirmpassword'] = $this->request->getVar('confirmpassword');
+ break;
+ default:
+ return parent::getFieldFormData($field, $entity);
+ break;
+ }
+ return $this->_viewDatas['fieldDatas'];
+ }
+
////Action 모음
//Insert관련
final public function insert()
{
+ $this->_defines[__FUNCTION__]['fieldRules']['id'] .= '|is_unique[tw_user.id]';
return $this->insert_procedure();
}
//Update관련
diff --git a/app/Controllers/Admin/UserSNSController.php b/app/Controllers/Admin/UserSNSController.php
index 1d003e1..01fae6f 100644
--- a/app/Controllers/Admin/UserSNSController.php
+++ b/app/Controllers/Admin/UserSNSController.php
@@ -41,13 +41,6 @@ class UserSNSController extends \App\Controllers\Admin\AdminController
protected function getFieldFormOption(string $field): array
{
switch ($field) {
- case 'user_uid':
- if (is_null($this->_user_uids)) {
- //모든 필요한 FormOption등 조기화작업 필요
- $this->_user_uids = $this->getUserModel()->getFieldFormOptions(['status' => 'use']);
- }
- return $this->_user_uids;
- break;
default:
return parent::getFieldFormOption($field);
break;
diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php
index 3c88512..874d726 100644
--- a/app/Controllers/BaseController.php
+++ b/app/Controllers/BaseController.php
@@ -7,6 +7,7 @@ use CodeIgniter\HTTP\CLIRequest;
use CodeIgniter\HTTP\IncomingRequest;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
+use CodeIgniter\HTTP\Files\UploadedFile;
use Psr\Log\LoggerInterface;
use App\Libraries\Log\Log;
use App\Models\UserModel;
@@ -112,32 +113,33 @@ abstract class BaseController extends Controller
return $fieldFormOptions;
}
//Field별 Form Rule용
- final protected function getFieldRules(array $fields, array $fieldRules): array
- {
- $tempRules = $this->_model->getValidationRules(['only' => $fields]);
- foreach ($fields as $field) {
- if (!is_string($field)) {
- throw new \Exception(__FUNCTION__ . "에서 {$this->_className}의 Field:{$field}가 string 아닙니다.\n" . var_export($fieldRules, true));
- }
- if (array_key_exists($field, $fieldRules)) {
- $tempRules[$field] = $fieldRules[$field];
- }
- }
- return $tempRules;
- }
+ // final protected function getFieldRules(array $fields, array $fieldRules): array
+ // {
+ // $tempRules = $this->_model->getValidationRules(['only' => $fields]);
+ // foreach ($fields as $field) {
+ // if (!is_string($field)) {
+ // throw new \Exception(__FUNCTION__ . "에서 {$this->_className}의 Field:{$field}가 string 아닙니다.\n" . var_export($fieldRules, true));
+ // }
+ // if (array_key_exists($field, $fieldRules)) {
+ // $tempRules[$field] = $fieldRules[$field];
+ // }
+ // }
+ // return $tempRules;
+ // }
//Field별 Form Datas 처리용
- protected function getFieldFormData(string $field, $entity = null)
+ protected function getFieldFormData(string $field, $entity = null): array
{
switch ($field) {
default:
- return $this->request->getVar($field);
+ $this->_viewDatas['fieldDatas'][$field] = $this->request->getVar($field);
break;
}
+ return $this->_viewDatas['fieldDatas'];
}
//Upload FIle관련
- protected function upload_file_process($upfile)
+ protected function upload_file_process(UploadedFile $upfile)
{
$fileName = "";
if ($upfile->isValid() && !$upfile->hasMoved()) {
@@ -185,7 +187,7 @@ abstract class BaseController extends Controller
protected function insert_init()
{
$this->_viewDatas['fields'] = $this->_defines['insert']['fields'];;
- $this->_viewDatas['fieldRules'] = $this->getFieldRules($this->_viewDatas['fields'], $this->_defines['insert']['fieldRules']);
+ $this->_viewDatas['fieldRules'] = $this->_defines['insert']['fieldRules'];
}
protected function insert_form_init()
{
@@ -214,9 +216,16 @@ abstract class BaseController extends Controller
//변경된 값 적용
$this->_viewDatas['fieldDatas'] = array();
foreach ($this->_viewDatas['fields'] as $field) {
- $this->_viewDatas['fieldDatas'][$field] = $this->getFieldFormData($field);
+ $this->_viewDatas['fieldDatas'] = $this->getFieldFormData($field);
Log::add("info", "{$field} : " . var_export($this->_viewDatas['fieldDatas'][$field], true));
}
+
+ // echo var_export($this->_viewDatas['fields'], true);
+ // echo "
";
+ // echo var_export($this->_viewDatas['fieldDatas'], true);
+ // echo "
";
+ // echo var_export($this->_viewDatas['fieldRules'], true);
+ // exit;
//변경할 값 확인
if (!$this->validate($this->_viewDatas['fieldRules'])) {
throw new \Exception("{$this->_viewDatas['title']}의 검증 오류발생\n" . implode("\n", $this->validator->getErrors()));
@@ -251,7 +260,7 @@ abstract class BaseController extends Controller
protected function update_init()
{
$this->_viewDatas['fields'] = $this->_defines['update']['fields'];;
- $this->_viewDatas['fieldRules'] = $this->getFieldRules($this->_viewDatas['fields'], $this->_defines['update']['fieldRules']);
+ $this->_viewDatas['fieldRules'] = $this->_defines['update']['fieldRules'];
}
protected function update_form_init()
{
@@ -267,7 +276,7 @@ abstract class BaseController extends Controller
final public function update_form($uid)
{
try {
- $entity = $this->_model->getEntity($uid);
+ $entity = $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$this->update_init();
$this->update_form_init();
$this->_viewDatas['entity'] = $this->update_form_process($entity);
@@ -281,7 +290,7 @@ abstract class BaseController extends Controller
//변경된 값 적용
$this->_viewDatas['fieldDatas'] = array();
foreach ($this->_viewDatas['fields'] as $field) {
- $this->_viewDatas['fieldDatas'][$field] = $this->getFieldFormData($field, $entity);
+ $this->_viewDatas['fieldDatas'] = $this->getFieldFormData($field, $entity);
Log::add(
"info",
"{$field} : {$entity->$field} => " . var_export($this->_viewDatas['fieldDatas'][$field])
@@ -301,7 +310,7 @@ abstract class BaseController extends Controller
{
$message = "";
try {
- $entity = $this->_model->getEntity($uid);
+ $entity = $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$this->update_init();
$entity = $this->update_validate($entity);
$entity = $this->update_process($entity);
@@ -333,7 +342,7 @@ abstract class BaseController extends Controller
final public function reply_form($uid)
{
try {
- $entity = $this->_model->getEntity($uid);
+ $entity = $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$this->reply_init();
$this->reply_form_init();
$this->_viewDatas['entity'] = $this->reply_form_process($entity);
@@ -354,7 +363,7 @@ abstract class BaseController extends Controller
{
$message = "";
try {
- $entity = $this->_model->getEntity($uid);
+ $entity = $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$this->reply_init();
$entity = $this->reply_validate($entity);
$entity = $this->reply_process($entity);
@@ -374,7 +383,7 @@ abstract class BaseController extends Controller
protected function toggle_init($field)
{
$this->_viewDatas['fields'] = [$field];
- $this->_viewDatas['fieldRules'] = $this->getFieldRules($this->_viewDatas['fields'], array());
+ $this->_viewDatas['fieldRules'] = $this->_defines['update']['fieldRules'];
}
protected function toggle_validate($entity)
{
@@ -388,7 +397,7 @@ abstract class BaseController extends Controller
{
$message = "";
try {
- $entity = $this->_model->getEntity($uid);
+ $entity = $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$this->toggle_init($field);
$entity = $this->toggle_validate($entity);
$entity = $this->toggle_process($entity);
@@ -418,7 +427,7 @@ abstract class BaseController extends Controller
}
//Fields,FielRules재정의
$this->_viewDatas['fields'] = $fields;
- $this->_viewDatas['fieldRules'] = $this->getFieldRules($this->_viewDatas['fields'], array());
+ $this->_viewDatas['fieldRules'] = $this->_defines['update']['fieldRules'];
}
protected function batchjob_validate($entity)
{
@@ -439,7 +448,7 @@ abstract class BaseController extends Controller
$this->batchjob_init();
$entitys = array();
foreach ($uids as $uid) {
- $entity = $this->_model->getEntity($uid);
+ $entity = $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
try {
$entity = $this->batchjob_validate($entity);
array_push($entitys, $this->batchjob_process($entity));
@@ -473,7 +482,7 @@ abstract class BaseController extends Controller
{
$message = "";
try {
- $entity = $this->_model->getEntity($uid);
+ $entity = $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$this->delete_process($entity);
$message = "{$entity->getTitle()} " . __FUNCTION__ . " 완료하였습니다.";
Log::save("{$this->_viewDatas['title']} {$message}");
@@ -491,7 +500,7 @@ abstract class BaseController extends Controller
{
$this->_viewDatas['fields'] = $this->_defines['view']['fields'];
$this->_viewDatas['fieldFilters'] = $this->_defines['view']['fieldFilters'];
- $this->_viewDatas['fieldRules'] = $this->getFieldRules($this->_viewDatas['fields'], $this->_defines['view']['fieldRules']);
+ $this->_viewDatas['fieldRules'] = $this->_defines['view']['fieldRules'];
helper(['form']);
$this->_viewDatas['fieldFormOptions'] = $this->getFieldFormOptions($this->_viewDatas['fieldFilters']);
$this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []];
@@ -503,7 +512,7 @@ abstract class BaseController extends Controller
protected function view_procedure($uid)
{
try {
- $entity = $this->_model->getEntity($uid);
+ $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
// dd($entity);
$this->view_init();
$this->_viewDatas['entity'] = $this->view_process($entity);
@@ -523,7 +532,6 @@ abstract class BaseController extends Controller
$this->_viewDatas['fieldFormOptions'] = $this->getFieldFormOptions($this->_viewDatas['fieldFilters']);
$this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []];
$this->_session->set(SESSION_NAMES['RETURN_URL'], current_url() . '?' . $this->request->getUri()->getQuery());
-
foreach ($this->_viewDatas['fieldFilters'] as $field) {
$this->_viewDatas[$field] = $this->request->getVar($field) ? $this->request->getVar($field) : DEFAULTS['EMPTY'];
}
diff --git a/app/Helpers/Admin/BoardConfig_helper.php b/app/Helpers/Admin/BoardConfig_helper.php
index 5278374..0d8eef3 100644
--- a/app/Helpers/Admin/BoardConfig_helper.php
+++ b/app/Helpers/Admin/BoardConfig_helper.php
@@ -129,7 +129,7 @@ function getFieldIndex_Row_BoardConfigHelper($field, array $row, array $fieldFil
$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];
+ return $row[$field] ?: DEFAULTS['EMPTY'];
break;
}
} //
\ No newline at end of file
diff --git a/app/Helpers/Admin/Board_helper.php b/app/Helpers/Admin/Board_helper.php
index 1c74bac..66e1dc7 100644
--- a/app/Helpers/Admin/Board_helper.php
+++ b/app/Helpers/Admin/Board_helper.php
@@ -27,8 +27,12 @@ function getFieldForm_BoardHelper($field, $value, array $fieldFormOptions, array
return form_input($field, $value, [...$attributes, 'class' => 'calender']);
break;
case 'passwd':
- case 'confirmpassword':
- return form_password($field, DEFAULTS['EMPTY'], $attributes);
+ return sprintf(
+ "%s %s %s",
+ form_password($field, DEFAULTS['EMPTY'], $attributes),
+ lang("Admin/Board.label.confirmpassword"),
+ form_password('confirmpassword', DEFAULTS['EMPTY'], $attributes),
+ );
break;
case 'content':
return form_textarea($field, html_entity_decode($value), [...$attributes, 'class' => 'editor', 'rows' => '20', 'cols' => '100']);
@@ -95,7 +99,7 @@ function getFieldIndex_Row_BoardHelper($field, array $row, array $fieldFilters,
$attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $row['uid'], $field, $field);
return getFieldFilter_BoardHelper($field, $row[$field], $fieldFormOptions, $attributes);
}
- return $row[$field];
+ return $row[$field] ?: DEFAULTS['EMPTY'];
break;
}
} //
\ No newline at end of file
diff --git a/app/Helpers/Admin/Logger_helper.php b/app/Helpers/Admin/Logger_helper.php
index 2f0dcaa..04deaf1 100644
--- a/app/Helpers/Admin/Logger_helper.php
+++ b/app/Helpers/Admin/Logger_helper.php
@@ -83,7 +83,7 @@ function getFieldIndex_Row_LoggerHelper($field, array $row, array $fieldFilters,
$attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $row['uid'], $field, $field);
return getFieldFilter_LoggerHelper($field, $row[$field], $fieldFormOptions, $attributes);
}
- return $row[$field];
+ return $row[$field] ?: DEFAULTS['EMPTY'];
break;
}
} //
\ No newline at end of file
diff --git a/app/Helpers/Admin/UserSNS_helper.php b/app/Helpers/Admin/UserSNS_helper.php
index 37353c9..ed0ef40 100644
--- a/app/Helpers/Admin/UserSNS_helper.php
+++ b/app/Helpers/Admin/UserSNS_helper.php
@@ -76,7 +76,7 @@ function getFieldIndex_Row_UserSNSHelper($field, array $row, array $fieldFilters
$attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $row['uid'], $field, $field);
return getFieldFilter_UserSNSHelper($field, $row[$field], $fieldFormOptions, $attributes);
}
- return $row[$field];
+ return $row[$field] ?: DEFAULTS['EMPTY'];
break;
}
} //
\ No newline at end of file
diff --git a/app/Helpers/Admin/User_helper.php b/app/Helpers/Admin/User_helper.php
index e460e45..87a0509 100644
--- a/app/Helpers/Admin/User_helper.php
+++ b/app/Helpers/Admin/User_helper.php
@@ -26,8 +26,12 @@ function getFieldForm_UserHelper($field, $value, array $fieldFormOptions, array
return form_input($field, $value, [...$attributes, 'class' => 'calender']);
break;
case 'passwd':
- case 'confirmpassword':
- return form_password($field, DEFAULTS['EMPTY'], $attributes);
+ return sprintf(
+ "%s %s %s",
+ form_password($field, DEFAULTS['EMPTY'], $attributes),
+ lang("Admin/User.label.confirmpassword"),
+ form_password('confirmpassword', DEFAULTS['EMPTY'], $attributes),
+ );
break;
default:
return form_input($field, $value, $attributes);
@@ -80,7 +84,7 @@ function getFieldIndex_Row_UserHelper($field, array $row, array $fieldFilters, $
$attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $row['uid'], $field, $field);
return getFieldFilter_UserHelper($field, $row[$field], $fieldFormOptions, $attributes);
}
- return $row[$field];
+ return $row[$field] ?: DEFAULTS['EMPTY'];
break;
}
} //
\ No newline at end of file
diff --git a/app/Language/kr/Admin/Logger.php b/app/Language/kr/Admin/Logger.php
index 747395b..d271a0d 100644
--- a/app/Language/kr/Admin/Logger.php
+++ b/app/Language/kr/Admin/Logger.php
@@ -10,4 +10,5 @@ return [
'updated_at' => "수정일",
'created_at' => "작성일"
],
+ 'STATUS' => FORM_OPTIONS['STATUS'],
];
diff --git a/app/Libraries/Adapter/Auth/LocalAdapter.php b/app/Libraries/Adapter/Auth/LocalAdapter.php
index 01cfb02..a4052b8 100644
--- a/app/Libraries/Adapter/Auth/LocalAdapter.php
+++ b/app/Libraries/Adapter/Auth/LocalAdapter.php
@@ -21,11 +21,7 @@ class LocalAdapter extends Adapter
if (!isset($formDatas['id']) || !$formDatas['id'] || !isset($formDatas['passwd']) || !$formDatas['passwd']) {
throw new \Exception("ID 나 암호의 값이 없습니다.");
}
-
- $entity = $this->getUserModel()->getEntityByField('id', $formDatas['id']);
- if (is_null($entity)) {
- throw new \Exception("사용자ID: {$formDatas['id']}가 존재하지 않습니다.");
- }
+ $entity = $this->getUserModel()->getEntity(['id' => $formDatas['id']]);
if (!password_verify($formDatas['passwd'], $entity->passwd)) {
throw new \Exception("암호가 맞지않습니다.");
}
diff --git a/app/Models/BaseHierarchyModel.php b/app/Models/BaseHierarchyModel.php
index 8975c63..a16dea3 100644
--- a/app/Models/BaseHierarchyModel.php
+++ b/app/Models/BaseHierarchyModel.php
@@ -10,18 +10,41 @@ abstract class BaseHierarchyModel extends BaseModel
protected function __construct()
{
parent::__construct();
- $this->allowedFields = [...$this->allowedFields, 'grpno', 'grporder', 'grpdepth'];
- $this->validationRules = [
- ...$this->validationRules,
- 'grpno' => 'if_exist|numeric',
- 'grporder' => 'if_exist|numeric',
- 'grpdepth' => 'if_exist|numeric',
+ $this->allowedFields = [
+ ...$this->allowedFields,
+ 'grpno', 'grporder', 'grpdepth'
];
}
- abstract public function getEntity($uid): BaseEntity;
- abstract public function getEntitys($where): array;
+ protected function getFields(array $fields = array(), array $skips = array()): array
+ {
+ //allowedFields에서 추가했으므로 Controller에는 적용되지 않게하기위함
+ $skips = ['grpno', 'grporder', 'grpdepth', ...$skips];
+ return parent::getFields($fields, $skips);
+ }
+ protected function getFieldFilters(array $fields = array(), array $skips = array()): array
+ {
+ //allowedFields에서 추가했으므로 Controller에는 적용되지 않게하기위함
+ $skips = ['grpno', 'grporder', 'grpdepth', ...$skips];
+ return parent::getFieldFilters($fields, $skips);
+ }
+
abstract function reply($parent_entity, array $formDatas): BaseEntity;
+ protected function getFieldRule(string $field, array $rules): array
+ {
+ switch ($field) {
+ case 'grpno':
+ case 'grporder':
+ case 'grpdepth':
+ $rules[$field] = 'if_exist|numeric';
+ break;
+ default:
+ $rules = parent::getFieldRule($field, $rules);
+ break;
+ }
+ return $rules;
+ }
+
final protected function create_process($entity, array $formDatas)
{
$entity = parent::create_process($entity, $formDatas);
diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php
index bcbadd1..42727fd 100644
--- a/app/Models/BaseModel.php
+++ b/app/Models/BaseModel.php
@@ -45,13 +45,72 @@ abstract class BaseModel extends Model
{
parent::__construct();
$this->allowedFields = ['updated_at', 'created_at'];
- $this->validationRules = [
- 'updated_at' => 'if_exist|valid_date',
- 'created_at' => 'if_exist|valid_date',
- ];
+ $this->validationRules = [];
}
abstract public function getEntity($uid): BaseEntity;
abstract public function getEntitys($where): array;
+ protected function getFields(array $fields = array(), array $skips = array()): array
+ {
+ // echo var_export($fields, true);
+ // echo "
";
+ //allowedFields에서 추가했으므로 Controller에는 적용되지 않게하기위함
+ $skips = ['updated_at', 'created_at', ...$skips];
+ $tempFields = array();
+ foreach ($fields as $key => $field) {
+ in_array($field, $skips) ?: array_push($tempFields, $field);
+ }
+ // echo var_export($tempFields, true);
+ // exit;
+ return $tempFields;
+ }
+ protected function getFieldFilters(array $fields = array(), array $skips = array()): array
+ {
+ //allowedFields에서 추가했으므로 Controller에는 적용되지 않게하기위함
+ $skips = ['updated_at', 'created_at', ...$skips];
+ $tempFields = array();
+ foreach ($fields as $field) {
+ if (!in_array($field, $skips)) {
+ array_push($tempFields, $field);
+ }
+ }
+ return $tempFields;
+ }
+ protected function getFieldRule(string $field, array $rules): array
+ {
+ switch ($field) {
+ case 'user_uid':
+ $rules[$field] = 'if_exist|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]';
+ break;
+ case 'passwd':
+ $rules[$field] = 'if_exist|string';
+ $rules['confirmpassword'] = 'if_exist|string|matches[passwd]';
+ break;
+ case 'view_cnt':
+ $rules[$field] = 'if_exist|numeric';
+ break;
+ case 'updated_at':
+ case 'created_at':
+ case 'deleted_at':
+ $rules[$field] = 'if_exist|valid_date';
+ break;
+ default:
+ $rules[$field] = 'if_exist|string';
+ break;
+ }
+ return $rules;
+ }
+ final public function getFieldRules(array $fields, array $rules = array()): array
+ {
+ foreach ($fields as $field) {
+ $rules = $this->getFieldRule($field, $rules);
+ }
+ return $rules;
+ }
+
+ final public function getPrimaryKey()
+ {
+ return $this->primaryKey;
+ }
final public function getFieldFormOptions($where, $options = array()): array
{
@@ -74,8 +133,17 @@ abstract class BaseModel extends Model
);
}
+ //View관련 (게시판등의 조회수 증가함수)
+ final public function increaseViewCount($uid, string $field = 'view_cnt', int $cnt = 1)
+ {
+ //escape -> false옵션 반드시 있어야함
+ $this->builder()->set($field, "{$field}+{$cnt}", false);
+ $this->builder()->where($this->primaryKey, $uid);
+ $this->builder()->update();
+ }
+
//create , modify 직전 작업용 작업
- protected function changeFormData($field, array $formDatas, $entity)
+ protected function changeFormData(string $field, array $formDatas, $entity)
{
switch ($field) {
case $this->primaryKey:
@@ -132,6 +200,8 @@ abstract class BaseModel extends Model
}
protected function create_process($entity, array $formDatas)
{
+ // echo var_export($this->allowedFields, true);
+ // exit;
foreach ($this->allowedFields as $field) {
$entity = $this->changeFormData($field, $formDatas, $entity);
}
@@ -148,25 +218,16 @@ abstract class BaseModel extends Model
return $this->save_process($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();
- }
-
//Index관련
- public function setIndexWordFilter(string $word)
+ protected function setIndexWordFilter(string $word)
{
}
- public function setIndexDateFilterTrit($start, $end)
+ protected function setIndexDateFilterTrit($start, $end)
{
$this->where('created_at >=', $start);
$this->where('created_at <=', $end);
}
- public function setIndexOrderBy($field, $order = 'ASC')
+ protected function setIndexOrderBy($field, $order = 'ASC')
{
$this->orderBy($field, $order);
}
diff --git a/app/Models/BoardConfigModel.php b/app/Models/BoardConfigModel.php
index ed071c7..8128542 100644
--- a/app/Models/BoardConfigModel.php
+++ b/app/Models/BoardConfigModel.php
@@ -11,34 +11,61 @@ class BoardConfigModel extends BaseModel
parent::__construct();
$this->table = 'tw_board_config';
$this->useAutoIncrement = false;
- $this->allowedFields = [...$this->allowedFields, 'uid', 'name', 'isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'head', 'tail', 'status'];
+ $this->allowedFields = [
+ ...$this->allowedFields,
+ 'uid', 'name', 'isaccess', 'isread', 'iswrite',
+ 'isreply', 'isupload', 'isdownload',
+ 'status', 'head', 'tail'
+ ];
$this->validationRules = [
...$this->validationRules,
- 'uid' => 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
- 'name' => 'required|string',
- 'isaccess' => 'required',
- 'isread' => 'required',
- 'iswrite' => 'required',
- 'isreply' => 'required',
- 'isupload' => 'required',
- 'isdownload' => 'required',
- 'head' => 'if_exist|string',
- 'tail' => 'if_exist|string',
- 'status' => 'if_exist|string',
+ ...$this->getFieldRules($this->getFields()),
];
}
-
- public function getEntity($uid): BoardConfigEntity
+ public function getFields(array $fields = array(), array $skips = array()): array
{
- $entity = $this->asObject(BoardConfigEntity::class)->where([$this->primaryKey => $uid])->first();
- return $entity ?: throw new \Exception("{$uid}의 해당 데이터가 없습니다.\n ");
+ $fields = [...$this->allowedFields, ...$fields];
+ return parent::getFields($fields, ['uid', ...$skips]);
+ }
+ public function getFieldFilters(array $fields = array(), array $skips = array()): array
+ {
+ $skips = ['name', 'head', 'tail', ...$skips];
+ return parent::getFieldFilters($fields, $skips);
+ }
+ protected function getFieldRule(string $field, array $rules): array
+ {
+ switch ($field) {
+ case 'uid':
+ $rules[$field] = 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]';
+ break;
+ case 'name':
+ $rules[$field] = 'required|trim|string';
+ break;
+ case 'isaccess':
+ case 'isread':
+ case 'iswrite':
+ case 'isreply':
+ case 'isupload':
+ case 'isdownload':
+ $rules[$field] = 'required';
+ break;
+ default:
+ $rules = parent::getFieldRule($field, $rules);
+ break;
+ }
+ return $rules;
+ }
+ public function getEntity($where): BoardConfigEntity
+ {
+ $entity = $this->asObject(BoardConfigEntity::class)->where($where)->first();
+ return $entity ?: throw new \Exception("{$where}의 해당 데이터가 없습니다.\n ");
}
public function getEntitys($where): array
{
return $this->asObject(BoardConfigEntity::class)->where($where)->findAll();
}
- protected function changeFormData($field, array $formDatas, $entity)
+ protected function changeFormData(string $field, array $formDatas, $entity)
{
switch ($field) {
case 'isaccess':
@@ -78,6 +105,12 @@ class BoardConfigModel extends BaseModel
{
parent::setIndexWordFilter($word);
$this->orLike('name', $word, 'both'); //befor , after , both
+ $this->orLike('isaccess', $word, 'both'); //befor , after , both
+ $this->orLike('isread', $word, 'both'); //befor , after , both
+ $this->orLike('iswrite', $word, 'both'); //befor , after , both
+ $this->orLike('isreply', $word, 'both'); //befor , after , both
+ $this->orLike('isupload', $word, 'both'); //befor , after , both
+ $this->orLike('isdownload', $word, 'both'); //befor , after , both
}
public function setIndexOrderBy($field, $order = 'ASC')
{
diff --git a/app/Models/BoardModel.php b/app/Models/BoardModel.php
index ee2178f..3c7395d 100644
--- a/app/Models/BoardModel.php
+++ b/app/Models/BoardModel.php
@@ -10,23 +10,53 @@ class BoardModel extends BaseHierarchyModel
{
parent::__construct();
$this->table = 'tw_board';
- $this->allowedFields = [...$this->allowedFields, 'board_config_uid', 'user_uid', 'title', 'content', 'passwd', 'view_cnt', 'status'];
+ $this->allowedFields = [
+ ...$this->allowedFields,
+ 'board_config_uid', 'user_uid', 'title', 'passwd',
+ 'upload_file', 'status', 'view_cnt', 'content',
+ ];
$this->validationRules = [
...$this->validationRules,
- 'board_config_uid' => 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
- 'user_uid' => 'if_exist|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
- 'title' => 'required|string',
- 'content' => 'required|string',
- 'passwd' => 'if_exist|trim|string',
- 'view_cnt' => 'if_exist|numeric',
- 'status' => 'if_exist|string',
+ ...$this->getFieldRules($this->getFields()),
];
}
-
- public function getEntity($uid): BoardEntity
+ public function getFields(array $fields = array(), array $skips = array()): array
{
- $entity = $this->asObject(BoardEntity::class)->where([$this->primaryKey => $uid])->first();
- return $entity ?: throw new \Exception("{$uid}의 해당 데이터가 없습니다.\n ");
+ $fields = [...$this->allowedFields, ...$fields];
+ return parent::getFields($fields, $skips);
+ }
+ public function getFieldFilters(array $fields = array(), array $skips = array()): array
+ {
+ $skips = ['title', 'passwd', 'upload_file', 'view_cnt', 'content', ...$skips];
+ return parent::getFieldFilters($fields, $skips);
+ }
+ protected function getFieldRule(string $field, array $rules): array
+ {
+ switch ($field) {
+ case 'board_config_uid':
+ $rules[$field] = 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]';
+ break;
+ case 'title':
+ case 'content':
+ $rules[$field] = 'required|string';
+ break;
+ case 'upload_file':
+ $rules[$field] = '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]';
+ break;
+ case 'view_cnt':
+ $rules[$field] = 'if_exist|numeric';
+ break;
+ default:
+ $rules = parent::getFieldRule($field, $rules);
+ break;
+ }
+ return $rules;
+ }
+
+ public function getEntity($where): BoardEntity
+ {
+ $entity = $this->asObject(BoardEntity::class)->where($where)->first();
+ return $entity ?: throw new \Exception("{$where}의 해당 데이터가 없습니다.\n ");
}
public function getEntitys($where): array
{
diff --git a/app/Models/LoggerModel.php b/app/Models/LoggerModel.php
index 39e9673..1e1d142 100644
--- a/app/Models/LoggerModel.php
+++ b/app/Models/LoggerModel.php
@@ -10,20 +10,44 @@ class LoggerModel extends BaseModel
{
parent::__construct();
$this->table = 'tw_logger';
- $this->allowedFields = [...$this->allowedFields, 'user_uid', 'title', 'content', 'status'];
+ $this->allowedFields = [
+ ...$this->allowedFields,
+ ...$this->getFields(),
+ ];
$this->validationRules = [
...$this->validationRules,
- 'user_uid' => 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
- 'title' => 'required|string',
- 'content' => 'if_exist|string',
- 'status' => 'required|string',
+ ...$this->getFieldRules($this->getFields()),
];
}
-
- public function getEntity($uid): LoggerEntity
+ public function getFields(array $fields = array(), array $skips = array()): array
{
- $entity = $this->asObject(LoggerEntity::class)->where([$this->primaryKey => $uid])->first();
- return $entity ?: throw new \Exception("{$uid}의 해당 데이터가 없습니다.\n ");
+ $fields = ['user_uid', 'title', 'content', 'status', ...$fields];
+ return parent::getFields($fields, $skips);
+ }
+ public function getFieldFilters(array $fields = array(), array $skips = array()): array
+ {
+ $fields = ['user_uid', 'status', ...$fields];
+ return parent::getFieldFilters($fields, $skips);
+ }
+ protected function getFieldRule(string $field, array $rules): array
+ {
+ switch ($field) {
+ case 'title':
+ case 'content':
+ case 'status':
+ $rules[$field] = 'required|string';
+ break;
+ default:
+ $rules = parent::getFieldRule($field, $rules);
+ break;
+ }
+ return $rules;
+ }
+
+ public function getEntity($where): LoggerEntity
+ {
+ $entity = $this->asObject(LoggerEntity::class)->where($where)->first();
+ return $entity ?: throw new \Exception("{$where}의 해당 데이터가 없습니다.\n ");
}
public function getEntitys($where): array
{
diff --git a/app/Models/UserModel.php b/app/Models/UserModel.php
index acad26e..5bdc8cf 100644
--- a/app/Models/UserModel.php
+++ b/app/Models/UserModel.php
@@ -11,23 +11,58 @@ class UserModel extends BaseModel
parent::__construct();
$this->table = 'tw_user';
$this->useAutoIncrement = false;
- $this->allowedFields = [...$this->allowedFields, 'uid', 'id', 'email', 'passwd', 'name', 'role', 'status'];
+ $this->allowedFields = [
+ ...$this->allowedFields,
+ 'uid',
+ ...$this->getFields(),
+ ];
$this->validationRules = [
...$this->validationRules,
- 'uid' => 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
- 'id' => 'required|min_length[4]|max_length[20]',
- 'passwd' => 'required|trim|min_length[4]|max_length[150]',
- 'name' => 'required|min_length[2]|max_length[20]',
- 'email' => 'required|valid_email',
- 'role' => 'required|string',
- 'status' => 'if_exist|string',
+ ...$this->getFieldRules($this->getFields()),
];
}
-
- public function getEntity($uid): UserEntity
+ public function getFields(array $fields = array(), array $skips = array()): array
{
- $entity = $this->asObject(UserEntity::class)->where([$this->primaryKey => $uid])->first();
- return $entity ?: throw new \Exception("{$uid}의 해당 데이터가 없습니다.\n ");
+ $fields = ['id', 'email', 'passwd', 'name', 'role', 'status', ...$fields];
+ return parent::getFields($fields, $skips);
+ }
+ public function getFieldFilters(array $fields = array(), array $skips = array()): array
+ {
+ $fields = ['user_uid', 'status', ...$fields];
+ return parent::getFieldFilters($fields, $skips);
+ }
+ protected function getFieldRule(string $field, array $rules): array
+ {
+ switch ($field) {
+ case 'uid':
+ $rules[$field] = 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]';
+ break;
+ case 'id':
+ $rules[$field] = 'required|trim|min_length[4]|max_length[20]';
+ break;
+ case 'passwd':
+ $rules[$field] = 'required|string';
+ $rules['confirmpassword'] = 'if_exist|string|matches[passwd]';
+ break;
+ case 'name':
+ $rules[$field] = 'required|trim|string';
+ break;
+ case 'email':
+ $rules[$field] = 'required|valid_email';
+ break;
+ case 'role':
+ $rules[$field] = 'required|string';
+ break;
+ default:
+ $rules = parent::getFieldRule($field, $rules);
+ break;
+ }
+ return $rules;
+ }
+ public function getEntity($where): UserEntity
+ {
+ $entity = $this->asObject(UserEntity::class)->where($where)->first();
+ return $entity ?: throw new \Exception("{$where}의 해당 사용자가 없습니다.\n ");
}
public function getEntitys($where): array
{
diff --git a/app/Models/UserSNSModel.php b/app/Models/UserSNSModel.php
index fa2923b..35d647f 100644
--- a/app/Models/UserSNSModel.php
+++ b/app/Models/UserSNSModel.php
@@ -10,23 +10,51 @@ class UserSNSModel extends BaseModel
{
parent::__construct();
$this->table = 'tw_user_sns';
- $this->allowedFields = [...$this->allowedFields, 'user_uid', 'site', 'id', 'name', 'email', 'detail', 'status'];
+ $this->allowedFields = [
+ ...$this->allowedFields,
+ ...$this->getFields()
+ ];
$this->validationRules = [
...$this->validationRules,
- 'user_uid' => 'if_exist|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
- 'site' => 'required|string',
- 'id' => 'required|string',
- 'name' => 'required|string',
- 'email' => 'required|valid_email',
- 'detail' => 'if_exist|string',
- 'status' => 'required|string',
+ ...$this->getFieldRules($this->getFields()),
];
}
-
- public function getEntity($uid): UserSNSEntity
+ public function getFields(array $fields = array(), array $skips = array()): array
{
- $entity = $this->asObject(UserSNSEntity::class)->where([$this->primaryKey => $uid])->first();
- return $entity ?: throw new \Exception("{$uid}의 해당 데이터가 없습니다.\n ");
+ $fields = ['user_uid', 'site', 'id', 'name', 'email', 'detail', 'status', ...$fields];
+ return parent::getFields($fields, $skips);
+ }
+ public function getFieldFilters(array $fields = array(), array $skips = array()): array
+ {
+ $fields = ['user_uid', 'status', ...$fields];
+ return parent::getFieldFilters($fields, $skips);
+ }
+ protected function getFieldRule(string $field, array $rules): array
+ {
+ switch ($field) {
+ case 'id':
+ case 'name':
+ $rules[$field] = 'required|trim|string';
+ break;
+ case 'email':
+ $rules[$field] = 'required|valid_email';
+ break;
+ case 'detail':
+ $rules[$field] = 'if_exist|string';
+ break;
+ case 'status':
+ $rules[$field] = 'required|string';
+ break;
+ default:
+ $rules = parent::getFieldRule($field, $rules);
+ break;
+ }
+ return $rules;
+ }
+ public function getEntity($where): UserSNSEntity
+ {
+ $entity = $this->asObject(UserSNSEntity::class)->where($where)->first();
+ return $entity ?: throw new \Exception("{$where}의 해당 데이터가 없습니다.\n ");
}
public function getEntitys($where): array
{