From 0916bbcb439f99543eb29e1914b49634ccaa8416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Mon, 31 Jul 2023 15:41:25 +0900 Subject: [PATCH] servermgrv2 init... --- app/Backend/BaseBackend.php | 138 ++++++ app/Backend/BaseHierarchyBackend.php | 28 ++ app/Backend/BoardBackend.php | 40 ++ app/Backend/BoardConfigBackend.php | 15 + app/Backend/HPILOBackend.php | 15 + app/Backend/UserBackend.php | 15 + app/Backend/UserSNSBackend.php | 15 + app/Config/Services.php | 35 ++ app/Config/Services_HPILO.php | 67 +++ app/Controllers/Admin/AdminController.php | 5 +- .../Admin/AdminHierarchyController.php | 64 --- .../Admin/BoardConfigController.php | 9 +- app/Controllers/Admin/BoardController.php | 45 +- app/Controllers/Admin/HPILOController.php | 8 +- app/Controllers/Admin/Home.php | 11 +- app/Controllers/Admin/UserController.php | 9 +- app/Controllers/Admin/UserSNSController.php | 9 +- app/Controllers/AuthController.php | 4 +- app/Controllers/BaseController.php | 434 ++++++++---------- app/Controllers/Front/BoardController.php | 74 --- app/Controllers/Front/FrontController.php | 2 +- .../Front/FrontHierarchyController.php | 63 --- app/Controllers/Front/UserController.php | 37 -- app/Controllers/Home.php | 11 +- app/Models/BaseHierarchyModel.php | 22 +- app/Models/BaseModel.php | 4 +- app/Models/BoardConfigModel.php | 8 +- app/Models/BoardModel.php | 16 +- app/Models/UserModel.php | 12 +- app/Models/UserSNSModel.php | 10 +- app/Views/admin/board/reply.php | 1 - app/Views/layouts/admin/left_menu_hpilo.php | 10 + 32 files changed, 630 insertions(+), 606 deletions(-) create mode 100644 app/Backend/BaseBackend.php create mode 100644 app/Backend/BaseHierarchyBackend.php create mode 100644 app/Backend/BoardBackend.php create mode 100644 app/Backend/BoardConfigBackend.php create mode 100644 app/Backend/HPILOBackend.php create mode 100644 app/Backend/UserBackend.php create mode 100644 app/Backend/UserSNSBackend.php create mode 100644 app/Config/Services_HPILO.php delete mode 100644 app/Controllers/Admin/AdminHierarchyController.php delete mode 100644 app/Controllers/Front/BoardController.php delete mode 100644 app/Controllers/Front/FrontHierarchyController.php delete mode 100644 app/Controllers/Front/UserController.php create mode 100644 app/Views/layouts/admin/left_menu_hpilo.php diff --git a/app/Backend/BaseBackend.php b/app/Backend/BaseBackend.php new file mode 100644 index 0000000..3ae6eb8 --- /dev/null +++ b/app/Backend/BaseBackend.php @@ -0,0 +1,138 @@ +_className = $className; + $this->_session = \Config\Services::session(); + } + + final public function getClassName() + { + return $this->_className; + } + + //User모델 + final protected function getUserModel(): UserModel + { + return is_null($this->_userModel) ? new UserModel() : $this->_userModel; + } + //Entity값 가져오기 + final public function getEntity($uid) + { + return $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); + } + + //초기화 + final public function getFields(string $action) + { + return $this->_model->getFields($action); + } + //TitleField + final public function getTitleField() + { + return $this->_model->getTitleField(); + } + //Field별 Form Rule용 + final public function getFieldRules(array $fields, string $action) + { + return $this->_model->getFieldRules($fields, $action); + } + //Field별 Form Filter용 + final public function getFieldFilters() + { + return $this->_model->getFieldFilters(); + } + //Field별 Form BatchFilter용 + final public function getFieldBatchFilters() + { + return $this->_model->getFieldBatchFilters(); + } + //Field별 Form Option용 + public function getFieldFormOption(string $field): array + { + switch ($field) { + case 'user_uid': + $options = $this->_user_uids = $this->_user_uids ?: $this->getUserModel()->getFieldFormOptions(['status' => 'use']); + break; + default: + $options = lang($this->_className . '.' . strtoupper($field)); + break; + } + if (!is_array($options)) { + throw new \Exception(__FUNCTION__ . "에서 {$this->_className}의 Field:{$field}의 FormOptionData가 array가 아닙니다.\n" . var_export($options, true)); + } + return $options; + } + //Field별 Form Option용 + final public function getFieldFormOptions(array $fields): array + { + $fieldFormOptions = array(); + foreach ($fields as $field) { + if (!is_string($field)) { + throw new \Exception(__FUNCTION__ . "에서 {$this->_className}의 Field:{$field}가 string 아닙니다.\n" . var_export($fields, true)); + } + $fieldFormOptions[$field] = $this->getFieldFormOption($field); + } + return $fieldFormOptions; + } + + //Insert관련 + public function insert(array $fieldDatas): BaseEntity + { + return $this->_model->create($fieldDatas); + } + //Update관련 + public function update($entity, array $fieldDatas) + { + return $this->_model->modify($entity, $fieldDatas); + } + //Delete 관련 + public function delete($entity) + { + if (!$this->_model->delete($entity->getPrimaryKey())) { + log_message("error", __FUNCTION__ . "에서 호출:" . $this->_model->getLastQuery()); + log_message("error", implode("\n", $this->_model->errors())); + throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->_model->errors(), true)); + } + } + //View 관련 + public function view($entity) + { + return $entity; + } + + public function setCondition(array $filterFields, $word, $start, $end, $order_field, $order_value) + { + foreach ($filterFields as $field => $value) { + $this->_model->where($field, $value); + } + if (!is_null($word)) { + $this->_model->setIndexWordFilter($word); + } + if (!is_null($start) && !is_null($end)) { + $this->_model->setIndexDateFilter($start, $end); + } + $this->_model->setIndexOrderBy($order_field, $order_value); + } + final public function getTotalCount() + { + return $this->_model->countAllResults(); + } + final public function getFindEntitys(int $page = 0, int $per_page = 0) + { + return $per_page ? $this->_model->findAll($per_page, $page * $per_page - $per_page) : $this->_model->findAll(); + } +} diff --git a/app/Backend/BaseHierarchyBackend.php b/app/Backend/BaseHierarchyBackend.php new file mode 100644 index 0000000..75a0d32 --- /dev/null +++ b/app/Backend/BaseHierarchyBackend.php @@ -0,0 +1,28 @@ +_model->getContentField(); + } + //Reply관련 + public function reply($entity, array $fieldDatas) + { + return $this->_model->reply($entity, $fieldDatas); + } + //View관련 + public function view($entity) + { + // view_cnt에 추가하기위함 + $this->_model->increaseViewCount($entity->getPrimaryKey()); + return parent::view($entity); + } +} diff --git a/app/Backend/BoardBackend.php b/app/Backend/BoardBackend.php new file mode 100644 index 0000000..0d7d359 --- /dev/null +++ b/app/Backend/BoardBackend.php @@ -0,0 +1,40 @@ +_model = new BoardModel(); + } + //BoardConfig모델 + final public function getBoardConfigModel(): BoardConfigModel + { + return is_null($this->_boardConfigModel) ? new BoardConfigModel() : $this->_boardConfigModel; + } + + //Field별 Form Option용 + public function getFieldFormOption(string $field): array + { + switch ($field) { + case 'board_config_uid': + $options = $this->_board_config_uids = $this->_board_config_uids ?: $this->getBoardConfigModel()->getFieldFormOptions(['status' => 'use']); + break; + default: + return parent::getFieldFormOption($field); + break; + } + if (!is_array($options)) { + throw new \Exception(__FUNCTION__ . "에서 {$this->getClassName()}의 Field:{$field}의 FormOptionData가 array가 아닙니다.\n" . var_export($options, true)); + } + return $options; + } +} diff --git a/app/Backend/BoardConfigBackend.php b/app/Backend/BoardConfigBackend.php new file mode 100644 index 0000000..6453eb0 --- /dev/null +++ b/app/Backend/BoardConfigBackend.php @@ -0,0 +1,15 @@ +_model = new BoardConfigModel(); + } +} diff --git a/app/Backend/HPILOBackend.php b/app/Backend/HPILOBackend.php new file mode 100644 index 0000000..1414518 --- /dev/null +++ b/app/Backend/HPILOBackend.php @@ -0,0 +1,15 @@ +_model = new HPILOModel(); + } +} diff --git a/app/Backend/UserBackend.php b/app/Backend/UserBackend.php new file mode 100644 index 0000000..073e2e8 --- /dev/null +++ b/app/Backend/UserBackend.php @@ -0,0 +1,15 @@ +_model = new UserModel(); + } +} diff --git a/app/Backend/UserSNSBackend.php b/app/Backend/UserSNSBackend.php new file mode 100644 index 0000000..b3e1cc5 --- /dev/null +++ b/app/Backend/UserSNSBackend.php @@ -0,0 +1,15 @@ +_model = new UserSNSModel(); + } +} diff --git a/app/Config/Services.php b/app/Config/Services.php index df7c8ad..dcaf32e 100644 --- a/app/Config/Services.php +++ b/app/Config/Services.php @@ -29,4 +29,39 @@ class Services extends BaseService * return new \CodeIgniter\Example(); * } */ + public static function user($getShared = true) + { + if ($getShared) { + return static::getSharedInstance('user'); + } + return new \App\Backend\UserBackend(); + } + public static function usersns($getShared = true) + { + if ($getShared) { + return static::getSharedInstance('usersns'); + } + return new \App\Backend\UserSNSBackend(); + } + public static function board($getShared = true) + { + if ($getShared) { + return static::getSharedInstance('board'); + } + return new \App\Backend\BoardBackend(); + } + public static function boardconfig($getShared = true) + { + if ($getShared) { + return static::getSharedInstance('boardconfig'); + } + return new \App\Backend\BoardConfigBackend(); + } + public static function hpilo($getShared = true) + { + if ($getShared) { + return static::getSharedInstance('hpilo'); + } + return new \App\Backend\HPILOBackend(); + } } diff --git a/app/Config/Services_HPILO.php b/app/Config/Services_HPILO.php new file mode 100644 index 0000000..dcaf32e --- /dev/null +++ b/app/Config/Services_HPILO.php @@ -0,0 +1,67 @@ +_viewPath .= strtolower('Admin/'); + $this->_viewPath = 'admin/'; $this->_viewDatas['layout'] = LAYOUTS['admin']; - $this->_viewDatas['title'] = "관리자페이지"; } } diff --git a/app/Controllers/Admin/AdminHierarchyController.php b/app/Controllers/Admin/AdminHierarchyController.php deleted file mode 100644 index 78db27c..0000000 --- a/app/Controllers/Admin/AdminHierarchyController.php +++ /dev/null @@ -1,64 +0,0 @@ -update_form_process($entity); - } - final public function reply_form($uid) - { - try { - $entity = $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); - $this->_viewDatas['fields'] = $this->_model->getFields('reply'); - $this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'reply'); - $this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters(); - $this->_viewDatas['entity'] = $this->reply_form_process($entity); - $this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']); - return view($this->_viewPath . '/update', $this->_viewDatas); - } catch (\Exception $e) { - return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']))->with('return_message', $e->getMessage()); - } - } - protected function reply_validate($entity) - { - return $this->update_validate($entity); - } - protected function reply_process($entity) - { - return $this->_model->reply($entity, $this->_viewDatas['fieldDatas']); - } - public function reply($uid) - { - $msg = ""; - try { - $entity = $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); - $this->_viewDatas['fields'] = $this->_model->getFields('reply'); - $this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'reply'); - $this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters(); - $entity = $this->reply_validate($entity); - $entity = $this->reply_process($entity); - $msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 완료하였습니다."; - return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); - } catch (\Exception $e) { - $msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage(); - log_message("error", $e->getMessage()); - log_message("error", var_export($this->_viewDatas['fieldDatas'], true)); - return redirect()->back()->withInput(); - } finally { - $this->_session->setFlashdata("return_message", $msg); - } - } -} diff --git a/app/Controllers/Admin/BoardConfigController.php b/app/Controllers/Admin/BoardConfigController.php index 7eace82..7b9e718 100644 --- a/app/Controllers/Admin/BoardConfigController.php +++ b/app/Controllers/Admin/BoardConfigController.php @@ -2,7 +2,6 @@ namespace App\Controllers\Admin; -use App\Models\BoardConfigModel; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; @@ -11,12 +10,8 @@ class BoardConfigController extends AdminController { public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { + $this->_backend = service('boardconfig'); parent::initController($request, $response, $logger); - $this->_className .= 'BoardConfig'; - $this->_model = new BoardConfigModel(); - helper($this->_className); - $this->_viewPath .= strtolower($this->_className); - $this->_viewDatas['title'] = lang($this->_className . '.title'); - $this->_viewDatas['className'] = $this->_className; + $this->_viewPath .= strtolower($this->_backend->getClassName()); } } diff --git a/app/Controllers/Admin/BoardController.php b/app/Controllers/Admin/BoardController.php index 739945e..e4b8cc4 100644 --- a/app/Controllers/Admin/BoardController.php +++ b/app/Controllers/Admin/BoardController.php @@ -2,48 +2,17 @@ namespace App\Controllers\Admin; -use App\Models\BoardConfigModel; -use App\Models\BoardModel; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; -class BoardController extends AdminHierarchyController +class BoardController extends AdminController { - private $_boardConfigModel = null; - private $_board_config_uids = null; public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { + $this->_backend = service('board'); parent::initController($request, $response, $logger); - $this->_className .= 'Board'; - $this->_model = new BoardModel(); - helper($this->_className); - $this->_viewPath .= strtolower($this->_className); - $this->_viewDatas['title'] = lang($this->_className . '.title'); - $this->_viewDatas['className'] = $this->_className; - } - - //BoardConfig모델 - final protected function getBoardConfigModel(): BoardConfigModel - { - return is_null($this->_boardConfigModel) ? new BoardConfigModel() : $this->_boardConfigModel; - } - - //Field별 Form Option용 - protected function getFieldFormOption(string $field): array - { - switch ($field) { - case 'board_config_uid': - $options = $this->_board_config_uids = $this->_board_config_uids ?: $this->getBoardConfigModel()->getFieldFormOptions(['status' => 'use']); - break; - default: - return parent::getFieldFormOption($field); - break; - } - if (!is_array($options)) { - throw new \Exception(__FUNCTION__ . "에서 {$this->_className}의 Field:{$field}의 FormOptionData가 array가 아닙니다.\n" . var_export($options, true)); - } - return $options; + $this->_viewPath .= strtolower($this->_backend->getClassName()); } //Field별 Form Datas 처리용 @@ -63,12 +32,4 @@ class BoardController extends AdminHierarchyController } return $this->_viewDatas['fieldDatas']; } - - //View 관련 - protected function view_process($entity) - { - // view_cnt에 추가하기위함 - $this->_model->increaseViewCount($entity->getPrimaryKey()); - return parent::view_process($entity); - } } diff --git a/app/Controllers/Admin/HPILOController.php b/app/Controllers/Admin/HPILOController.php index 733861f..615952c 100644 --- a/app/Controllers/Admin/HPILOController.php +++ b/app/Controllers/Admin/HPILOController.php @@ -14,13 +14,9 @@ class HPILOController extends \App\Controllers\Admin\AdminController private $_adapter = null; public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { + $this->_backend = service('hpilo'); parent::initController($request, $response, $logger); - $this->_className .= 'HPILO'; - $this->_model = new HPILOModel(); - helper($this->_className); - $this->_viewPath .= strtolower($this->_className); - $this->_viewDatas['title'] = lang($this->_className . '.title'); - $this->_viewDatas['className'] = $this->_className; + $this->_viewPath .= strtolower($this->_backend->getClassName()); } private function getAdapter(HPILOEntity $entity) diff --git a/app/Controllers/Admin/Home.php b/app/Controllers/Admin/Home.php index a17e738..7b38ee2 100644 --- a/app/Controllers/Admin/Home.php +++ b/app/Controllers/Admin/Home.php @@ -2,24 +2,19 @@ namespace App\Controllers\Admin; +use CodeIgniter\Controller; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; -class Home extends AdminController +class Home extends Controller { - protected $_viewDatas = array(); public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { parent::initController($request, $response, $logger); - helper('Common'); - $this->_viewDatas = [ - 'layout' => LAYOUTS['admin'], - 'title' => '관리자페이지', - ]; } public function index() { - return view($this->_viewPath . '/welcome_message', $this->_viewDatas); + return view('admin/welcome_message'); } } diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php index 0a316e2..dfd9e2e 100644 --- a/app/Controllers/Admin/UserController.php +++ b/app/Controllers/Admin/UserController.php @@ -2,7 +2,6 @@ namespace App\Controllers\Admin; -use App\Models\UserModel; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; @@ -11,13 +10,9 @@ class UserController extends AdminController { public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { + $this->_backend = service('user'); parent::initController($request, $response, $logger); - $this->_className .= 'User'; - $this->_model = new UserModel(); - helper($this->_className); - $this->_viewPath .= strtolower($this->_className); - $this->_viewDatas['title'] = lang($this->_className . '.title'); - $this->_viewDatas['className'] = $this->_className; + $this->_viewPath .= strtolower($this->_backend->getClassName()); } //Field별 Form Datas 처리용 diff --git a/app/Controllers/Admin/UserSNSController.php b/app/Controllers/Admin/UserSNSController.php index eaad763..0531e19 100644 --- a/app/Controllers/Admin/UserSNSController.php +++ b/app/Controllers/Admin/UserSNSController.php @@ -2,7 +2,6 @@ namespace App\Controllers\Admin; -use App\Models\UserSNSModel; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; @@ -11,12 +10,8 @@ class UserSNSController extends AdminController { public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { + $this->_backend = service('usersns'); parent::initController($request, $response, $logger); - $this->_className .= 'UserSNS'; - $this->_model = new UserSNSModel(); - helper($this->_className); - $this->_viewPath .= strtolower($this->_className); - $this->_viewDatas['title'] = lang($this->_className . '.title'); - $this->_viewDatas['className'] = $this->_className; + $this->_viewPath .= strtolower($this->_backend->getClassName()); } } diff --git a/app/Controllers/AuthController.php b/app/Controllers/AuthController.php index 469c4e1..dbbf307 100644 --- a/app/Controllers/AuthController.php +++ b/app/Controllers/AuthController.php @@ -6,15 +6,15 @@ use App\Libraries\Adapter\Auth\Adapter; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; -use App\Models\UserModel; class AuthController extends BaseController { private $_adapters = array(); public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { + $this->_backend = service('user'); parent::initController($request, $response, $logger); - helper('Common'); + $this->_viewPath .= strtolower($this->_backend->getClassName()); $this->initAdapters(); } diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php index 8f8c975..9a5cfa0 100644 --- a/app/Controllers/BaseController.php +++ b/app/Controllers/BaseController.php @@ -10,8 +10,6 @@ use CodeIgniter\HTTP\IncomingRequest; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; -use App\Models\UserModel; -use App\Entities\BaseEntity; /** * Class BaseController @@ -50,62 +48,21 @@ abstract class BaseController extends Controller /** * Constructor. */ - private $_userModel = null; - private $_user_uids = array(); - protected $_model = null; - protected $_className = '/'; - protected $_viewPath = '/'; - protected $_viewDatas = array(); + protected $_backend = null; protected $_session = null; + protected $_viewPath = ''; + protected $_viewDatas = array(); public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { // Do Not Edit This Line parent::initController($request, $response, $logger); - // Preload any models, libraries, etc, here. - // E.g.: $this->session = \Config\Services::session(); $this->_session = \Config\Services::session(); - $this->_viewDatas = [ - 'layout' => LAYOUTS['empty'], - 'title' => '', - 'session' => $this->_session - ]; - } - - //User모델 - final protected function getUserModel(): UserModel - { - return is_null($this->_userModel) ? new UserModel() : $this->_userModel; - } - - //Field별 Form Option용 - protected function getFieldFormOption(string $field): array - { - switch ($field) { - case 'user_uid': - $options = $this->_user_uids = $this->_user_uids ?: $this->getUserModel()->getFieldFormOptions(['status' => 'use']); - break; - default: - $options = lang($this->_className . '.' . strtoupper($field)); - break; - } - if (!is_array($options)) { - throw new \Exception(__FUNCTION__ . "에서 {$this->_className}의 Field:{$field}의 FormOptionData가 array가 아닙니다.\n" . var_export($options, true)); - } - return $options; - } - //Field별 Form Option용 - final protected function getFieldFormOptions(array $fields): array - { - $fieldFormOptions = array(); - foreach ($fields as $field) { - if (!is_string($field)) { - throw new \Exception(__FUNCTION__ . "에서 {$this->_className}의 Field:{$field}가 string 아닙니다.\n" . var_export($fields, true)); - } - $fieldFormOptions[$field] = $this->getFieldFormOption($field); - } - return $fieldFormOptions; + $this->_viewDatas['layout'] = LAYOUTS['empty']; + $this->_viewDatas['title'] = lang($this->_backend->getClassName() . '.title'); + $this->_viewDatas['session'] = $this->_session; + helper($this->_backend->getClassName()); } //Field별 Form Datas 처리용 @@ -153,14 +110,31 @@ abstract class BaseController extends Controller return $fileNames; } + //초기화 + final public function init(string $action, $fields = null) + { + switch ($action) { + case 'insert_form': + $action = 'insert'; + break; + case 'update_form': + $action = 'update'; + break; + } + $this->_viewDatas['fields'] = $fields ?: $this->_backend->getFields($action); + $this->_viewDatas['fieldRules'] = $this->_backend->getFieldRules($this->_viewDatas['fields'], $action); + $this->_viewDatas['fieldFilters'] = $this->_backend->getFieldFilters(); + $this->_viewDatas['batchjobFilters'] = $this->_backend->getFieldBatchFilters(); + $this->_viewDatas['fieldFormOptions'] = $this->_backend->getFieldFormOptions($this->_viewDatas['fieldFilters']); + return $this->_viewDatas; + } + + //Insert관련 final public function insert_form() { try { - $this->_viewDatas['fields'] = $this->_model->getFields('insert'); - $this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'insert'); - $this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters(); - $this->_viewDatas['fieldFormOptions'] = $this->getFieldFormOptions($this->_viewDatas['fieldFilters']); + $this->_viewDatas = $this->init(__FUNCTION__); $this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []]; helper(['form']); $this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']); @@ -169,44 +143,30 @@ abstract class BaseController extends Controller return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']))->with('return_message', $e->getMessage()); } } - - protected function insert_validate() + protected function insert_process() { - $this->_viewDatas['fieldDatas'] = array(); - //변경할 값 확인 + //fieldData Rule 검사 if (!$this->validate($this->_viewDatas['fieldRules'])) { throw new \Exception("{$this->_viewDatas['title']}의 검증 오류발생\n" . implode("\n", $this->validator->getErrors())); } - //변경된 값 적용 + //fieldData 적용 + $this->_viewDatas['fieldDatas'] = array(); foreach ($this->_viewDatas['fields'] as $field) { $this->_viewDatas['fieldDatas'] = $this->getFieldFormData($field); } - // echo var_export($this->_viewDatas['fields'], true); - // echo "
"; - // echo var_export($this->_viewDatas['fieldDatas'], true); - // echo "
"; - // echo var_export($this->_viewDatas['fieldRules'], true); - // exit; - } - protected function insert_process(): BaseEntity - { - return $this->_model->create($this->_viewDatas['fieldDatas']); } public function insert() { $msg = ""; try { - $this->_viewDatas['fields'] = $this->_model->getFields('insert'); - $this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'insert'); - $this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters(); - $this->insert_validate(); - $entity = $this->insert_process(); + $this->_viewDatas = $this->init(__FUNCTION__); + $this->insert_process(); + $entity = $this->_backend->insert($this->_viewDatas['fieldDatas']); $msg = "{$this->_viewDatas['title']}에서 {$entity->getTitle()}의 " . __FUNCTION__ . " 완료하였습니다."; return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); } catch (\Exception $e) { $msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage(); log_message("error", $e->getMessage()); - log_message("error", var_export($this->_viewDatas['fieldDatas'], true)); return redirect()->back()->withInput(); } finally { $this->_session->setFlashdata("return_message", $msg); @@ -214,118 +174,132 @@ abstract class BaseController extends Controller } //Update관련 - protected function update_form_process($entity) - { - $this->_viewDatas['fieldFormOptions'] = $this->getFieldFormOptions($this->_viewDatas['fieldFilters']); - $this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []]; - helper(['form']); - return $entity; - } final public function update_form($uid) { try { - $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); - $this->_viewDatas['fields'] = $this->_model->getFields('update'); - $this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'update'); - $this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters(); - $this->_viewDatas['entity'] = $this->update_form_process($entity); + $this->_viewDatas = $this->init(__FUNCTION__); + $this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []]; + helper(['form']); $this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']); - return view($this->_viewPath . '/update', $this->_viewDatas); + $this->_viewDatas['entity'] = $this->_backend->getEntity($uid); + return view($this->_viewPath . '/update', $this->_viewDatas); } catch (\Exception $e) { return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']))->with('return_message', $e->getMessage()); } } - protected function update_validate($entity) + protected function update_process() { - //변경된 값 적용 - $this->_viewDatas['fieldDatas'] = array(); - //변경할 값 확인 + //fieldData Rule 검사 if (!$this->validate($this->_viewDatas['fieldRules'])) { throw new \Exception("{$this->_viewDatas['title']}의 검증 오류발생\n" . implode("\n", $this->validator->getErrors())); } + //fieldData 적용 + $this->_viewDatas['fieldDatas'] = array(); foreach ($this->_viewDatas['fields'] as $field) { - $this->_viewDatas['fieldDatas'] = $this->getFieldFormData($field, $entity); + $this->_viewDatas['fieldDatas'] = $this->getFieldFormData($field, $this->_viewDatas['entity']); log_message( "info", - "{$field} : {$entity->$field} => " . var_export($this->_viewDatas['fieldDatas'][$field]) + "{$field} : {$this->_viewDatas['entity']->$field} => " . var_export($this->_viewDatas['fieldDatas'][$field]) ); } - return $entity; - } - protected function update_process($entity) - { - return $this->_model->modify($entity, $this->_viewDatas['fieldDatas']); } public function update($uid) { $msg = ""; try { - $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); - $this->_viewDatas['fields'] = $this->_model->getFields('update'); - $this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'update'); - $this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters(); - $entity = $this->update_validate($entity); - $entity = $this->update_process($entity); - $msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 완료하였습니다."; + $this->_viewDatas = $this->init(__FUNCTION__); + $entity = $this->_viewDatas['entity'] = $this->_backend->getEntity($uid); + $this->update_process(); + $entity = $this->_backend->update($entity, $this->_viewDatas['fieldDatas']); + $msg = "{$this->_viewDatas['title']}에서 {$entity->getTitle()}의 " . __FUNCTION__ . " 완료하였습니다."; return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); } catch (\Exception $e) { $msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage(); log_message("error", $e->getMessage()); - log_message("error", var_export($this->_viewDatas['fieldDatas'], true)); return redirect()->back()->withInput(); } finally { $this->_session->setFlashdata("return_message", $msg); } } + //Reply관련 + final public function reply_form($uid) + { + try { + $this->_viewDatas = $this->init(__FUNCTION__); + $this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []]; + helper(['form']); + $this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']); + $entity = $this->_backend->getEntity($uid); + $titleField = $this->_backend->getTitleField(); + $entity->$titleField = "RE: " . $entity->$titleField; + $contentField = $this->_backend->getContentField(); + $entity->$contentField .= "\n----------------------------------------------\n"; + $this->_viewDatas['entity'] = $entity; + return view($this->_viewPath . '/reply', $this->_viewDatas); + } catch (\Exception $e) { + return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']))->with('return_message', $e->getMessage()); + } + } + protected function reply_process() + { + $this->update_process(); + } + public function reply($uid) + { + $msg = ""; + try { + $this->_viewDatas = $this->init(__FUNCTION__); + $entity = $this->_viewDatas['entity'] = $this->_backend->getEntity($uid); + $this->reply_process(); + $entity = $this->_backend->reply($entity, $this->_viewDatas['fieldDatas']); + $msg = "{$this->_viewDatas['title']}에서 {$entity->getTitle()}의 " . __FUNCTION__ . " 완료하였습니다."; + return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); + } catch (\Exception $e) { + $msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage(); + log_message("error", $e->getMessage()); + return redirect()->back()->withInput(); + } finally { + $this->_session->setFlashdata("return_message", $msg); + } + } //Toggle 관련 - protected function toggle_validate($entity) + protected function toggle_process() { - return $this->update_validate($entity); - } - protected function toggle_process($entity) - { - return $this->update_process($entity); + $this->update_process(); } public function toggle($uid, string $field) { $msg = ""; try { - $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); - $this->_viewDatas['fields'] = [$field]; - $this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'toggle'); - $this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters(); - $entity = $this->toggle_validate($entity); - $entity = $this->toggle_process($entity); - $msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 완료하였습니다."; + $this->_viewDatas = $this->init(__FUNCTION__, [$field]); + $entity = $this->_viewDatas['entity'] = $this->_backend->getEntity($uid); + $this->toggle_process(); + $entity = $this->_backend->update($entity, $this->_viewDatas['fieldDatas']); + $msg = "{$this->_viewDatas['title']}에서 {$entity->getTitle()}의 " . __FUNCTION__ . " 완료하였습니다."; } catch (\Exception $e) { $msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage(); log_message("error", $e->getMessage()); - log_message("error", var_export($this->_viewDatas['fieldDatas'], true)); } finally { $this->_session->setFlashdata("return_message", $msg); return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); } } //Batchjob 관련 - protected function batchjob_validate($entity) + protected function batchjob_process() { - return $this->update_validate($entity); - } - protected function batchjob_process($entity) - { - return $this->update_process($entity); + $this->update_process(); } public function batchjob() { $msg = ""; + $entitys = array(); $batchjobs = array(); try { - $uids = $this->request->getVar('batchjob_uids') ?: throw new \Exception($this->_viewDatas['title'] . '에서 변경할 항목(uid)이 선택되지 않았습니다.'); //fields 해당하는 field중 선택된 값이 있는경우만 fields로 정의 $fields = array(); - foreach ($this->_model->getFieldBatchFilters() as $field) { + foreach ($this->_backend->getFieldBatchFilters() as $field) { if ($this->request->getVar($field)) { array_push($fields, $field); } @@ -333,41 +307,43 @@ abstract class BaseController extends Controller if (!is_array($fields) || count($fields) === 0) { throw new \Exception($this->_viewDatas['title'] . '에서 변경할 항목(field)이 선택되지 않았습니다.'); } - //Transaction manully 시작 - $this->_model->transBegin(); - //Fields,FielRules재정의 - $this->_viewDatas['fields'] = $fields; - $this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'batchjob'); - $this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters(); + $this->_viewDatas = $this->init(__FUNCTION__, $fields); + $uids = $this->request->getVar('batchjob_uids') ?: throw new \Exception($this->_viewDatas['title'] . '에서 변경할 항목(uid)이 선택되지 않았습니다.'); + $cnt = 1; - $entitys = array(); + //Transaction manully 시작 + $this->_backend->transBegin(); foreach ($uids as $uid) { try { - $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); - $entity = $this->batchjob_validate($entity); - array_push($entitys, $this->batchjob_process($entity)); - array_push($batchjobs, "{$cnt}. {$entity->getTitle()}는 완료."); + $entity = $this->_viewDatas['entity'] = $this->_backend->getEntity($uid); + $this->batchjob_process(); + array_push($entitys, $this->_backend->update($entity, $this->_viewDatas['fieldDatas'])); + array_push($batchjobs, "{$cnt}. {$uid}->{$entity->getTitle()}는 완료."); } catch (\Exception $e) { - array_push($batchjobs, "{$cnt}. {$entity->getTitle()}는 실패\n" . $e->getMessage()); + array_push($batchjobs, "{$cnt}. {$uid}는 실패."); } $cnt++; } //Transaction manully Commit - $this->_model->transCommit(); + $this->_backend->transCommit(); $msg = sprintf( - "%s에서 총:%s중 %s개성공 , %s실패 %s 완료하였습니다.", + "%s에서 총:%s개의 %s 완료하였습니다.", $this->_viewDatas['title'], - count($batchjobs), count($entitys), - count($batchjobs) - count($entitys), __FUNCTION__ ); } catch (\Exception $e) { //Transaction manully Rollback - $this->_model->transRollback(); - $msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage(); + $this->_backend->transRollback(); + log_message('error', sprintf("---------batchjob 작업결과--------\n%s\n", implode("\n", $batchjobs))); + return sprintf( + "총:%s개의 작업중 %s개는 성공하였지만 , %s개가 실패하여 %s 취소되었습니다.\n%s", + count($uids), + count($entitys), + count($uids) - count($entitys), + __FUNCTION__, + ); log_message("error", $e->getMessage()); - log_message("error", var_export($this->_viewDatas['fieldDatas'], true)); } finally { $this->_session->setFlashdata("return_message", $msg); return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); @@ -375,26 +351,15 @@ abstract class BaseController extends Controller } //Delete 관련 - protected function delete_process($entity) - { - if (!$this->_model->delete($entity->getPrimaryKey())) { - log_message("error", __FUNCTION__ . "에서 호출:" . $this->_model->getLastQuery()); - log_message("error", implode("\n", $this->_model->errors())); - throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->_model->errors(), true)); - } - return $entity; - } public function delete($uid) { $msg = ""; try { - $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); - $this->delete_process($entity); - $msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 완료하였습니다."; + $entity = $this->_backend->delete($this->_backend->getEntity($uid)); + $msg = "{$this->_viewDatas['title']}에서 {$entity->getTitle()}의 " . __FUNCTION__ . " 완료하였습니다."; } catch (\Exception $e) { $msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage(); log_message("error", $e->getMessage()); - log_message("error", var_export($this->_viewDatas['fieldDatas'], true)); } finally { $this->_session->setFlashdata("return_message", $msg); return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); @@ -409,16 +374,11 @@ abstract class BaseController extends Controller public function view($uid) { try { - // echo "TEST" . $this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']); - // exit; - $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); - $this->_viewDatas['fields'] = $this->_model->getFields('view'); - $this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'view'); - $this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters(); + $this->_viewDatas = $this->init(__FUNCTION__); helper(['form']); - $this->_viewDatas['fieldFormOptions'] = $this->getFieldFormOptions($this->_viewDatas['fieldFilters']); $this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []]; - $this->_viewDatas['entity'] = $this->view_process($entity); + $entity = $this->_viewDatas['entity'] = $this->_backend->getEntity($uid); + $this->_viewDatas['entity'] = $this->_backend->view($entity); $this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']); return view($this->_viewPath . '/view', $this->_viewDatas); } catch (\Exception $e) { @@ -427,46 +387,13 @@ abstract class BaseController extends Controller } //Index 관련 - //index 모델 전처리 - protected function index_setCondition() - { - foreach ($this->_viewDatas['fieldFilters'] as $field) { - $value = $this->request->getVar($field) ?: false; - if ($value) { - $this->_model->where($field, $value); - } - } - $word = $this->request->getVar('word') ?: ''; - if (isset($word) && $word !== '') { - $this->_model->setIndexWordFilter($word); - } - $start = $this->request->getVar('start') ?: ''; - $end = $this->request->getVar('end') ?: ''; - if (isset($start) && $start !== '' && isset($end) && $end !== '') { - $this->_model->setIndexDateFilter($start, $end); - } - } - protected function index_getEntitys(int $page = 0, int $per_page = 0): array - { - //Totalcount 처리 - $this->index_setCondition(); - $this->_viewDatas['total_count'] = $this->_model->countAllResults(); - //Rows 처리 - $this->index_setCondition(); - //OrderBy - $this->_model->setIndexOrderBy($this->request->getVar('order_field'), $this->request->getVar('order_value')); - //Limit - $entitys = $per_page ? $this->_model->findAll($per_page, $page * $per_page - $per_page) : $this->_model->findAll(); - // log_message("debug", __METHOD__ . "에서 호출[{$per_page}:{$page}=>{$page}*{$per_page}-{$per_page}]\n" . $this->_model->getLastQuery()); - return $entitys; - } private function index_getPagination($pager_group = 'default', int $segment = 0, $template = 'bootstrap_full'): string { // 1.Views/Pagers/에 bootstrap_full.php,bootstrap_simple.php 생성 // 2.app/Config/Pager.php/$templates에 'bootstrap_full => 'Pagers\bootstrap_full', // 'bootstrap_simple' => 'Pagers\bootstrap_simple', 추가 $pager = \Config\Services::pager(); - // $this->_model->paginate($this->_viewDatas['per_page'], $pager_group, $this->_viewDatas['page'], $segment); + // $this->_backend->paginate($this->_viewDatas['per_page'], $pager_group, $this->_viewDatas['page'], $segment); $pager->makeLinks( $this->_viewDatas['page'], $this->_viewDatas['per_page'], @@ -479,27 +406,32 @@ abstract class BaseController extends Controller $this->_viewDatas['total_page'] = $pager->getPageCount($pager_group); return $pager->links($pager_group, $template); } - protected function index_process() + private function index_setCondition() { - //모델 처리 - $this->_viewDatas['entitys'] = $this->index_getEntitys((int)$this->_viewDatas['page'], (int)$this->_viewDatas['per_page']); - //줄수 처리용 - $this->_viewDatas['pageOptions'] = array("" => "줄수선택"); - for ($i = 10; $i <= $this->_viewDatas['total_count'] + $this->_viewDatas['per_page']; $i += 10) { - $this->_viewDatas['pageOptions'][$i] = $i; + //조건절 처리 + $filterFields = array(); + foreach ($this->_viewDatas['fieldFilters'] as $field) { + if (!is_null($this->request->getVar($field))) { + $filterFields[$field] = $this->request->getVar($field); + } } - //pagenation 처리 - $this->_viewDatas['pagination'] = $this->index_getPagination(); + $word = $this->request->getVar('word'); + $start = $this->request->getVar('start'); + $end = $this->request->getVar('end'); + $order_field = $this->request->getVar('order_field'); + $order_value = $this->request->getVar('order_value'); + $this->_backend->setCondition($filterFields, $word, $start, $end, $order_field, $order_value); + } + private function index_getEntitys(int $page = 0, int $per_page = 0) + { + $this->index_setCondition(); + return $this->_backend->getFindEntitys($page, $per_page); } public function index() { try { - $this->_viewDatas['fields'] = $this->_model->getFields('index'); - $this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'index'); - $this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters(); - $this->_viewDatas['batchjobFilters'] = $this->_model->getFieldBatchFilters(); + $this->_viewDatas = $this->init(__FUNCTION__); helper(['form']); - $this->_viewDatas['fieldFormOptions'] = $this->getFieldFormOptions($this->_viewDatas['fieldFilters']); $this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []]; foreach ($this->_viewDatas['fieldFilters'] as $field) { $this->_viewDatas[$field] = $this->request->getVar($field) ?: DEFAULTS['EMPTY']; @@ -512,13 +444,21 @@ abstract class BaseController extends Controller $this->_viewDatas['page'] = $this->request->getVar('page') ?: 1; $this->_viewDatas['per_page'] = $this->request->getVar('per_page') ?: DEFAULTS['PERPAGE']; $this->_viewDatas['uri'] = $this->request->getUri(); - $this->index_process(); + //Totalcount 처리 + $this->index_setCondition(); + $this->_viewDatas['total_count'] = $this->_backend->getTotalCount(); + //줄수 처리용 + $this->_viewDatas['pageOptions'] = array("" => "줄수선택"); + for ($i = 10; $i <= $this->_viewDatas['total_count'] + $this->_viewDatas['per_page']; $i += 10) { + $this->_viewDatas['pageOptions'][$i] = $i; + } + //pagenation 처리 + $this->_viewDatas['pagination'] = $this->index_getPagination(); + //모델 처리 + $this->_viewDatas['entitys'] = $this->index_getEntitys((int)$this->_viewDatas['page'], (int)$this->_viewDatas['per_page']); + // log_message("debug", __METHOD__ . "에서 호출:" . $this->_backend->getLastQuery()); //setting return_url to session flashdata $this->_session->setFlashdata(SESSION_NAMES['RETURN_URL'], current_url() . '?' . $this->request->getUri()->getQuery() ?: ""); - // echo "TEST" . var_export($this->_session->get()); - // echo "
"; - // echo $this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']); - // exit; return view($this->_viewPath . '/index', $this->_viewDatas); } catch (\Exception $e) { return redirect()->back()->with('return_message', $e->getMessage()); @@ -526,22 +466,22 @@ abstract class BaseController extends Controller } //Excel 관련 - protected function excel_spreadSheet() + private function excel_spreadSheet(array $viewDatas) { //Excepl 초기화 $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); //Header용 $column = 'A'; - foreach ($this->_viewDatas['fields'] as $field) { - $sheet->setCellValue($column++ . '1', lang($this->_className . '.label.' . $field)); + foreach ($viewDatas['fields'] as $field) { + $sheet->setCellValue($column++ . '1', lang($this->_backend->getClassName() . '.label.' . $field)); } //본문용 $line = 2; foreach ($this->index_getEntitys() as $entity) { $column = 'A'; - foreach ($this->_viewDatas['fields'] as $field) { - $value = in_array($field, $this->_viewDatas['fieldFilters']) ? $this->_viewDatas['fieldFormOptions'][$field][$entity->$field] : $entity->$field; + foreach ($viewDatas['fields'] as $field) { + $value = in_array($field, $viewDatas['fieldFilters']) ? $viewDatas['fieldFormOptions'][$field][$entity->$field] : $entity->$field; $sheet->setCellValue($column . $line, $value); $column++; } @@ -549,32 +489,24 @@ abstract class BaseController extends Controller } return $spreadsheet; } - protected function excel_process() - { - $fileName = date('Y-m-d_Hm') . '.xlsx'; - $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($this->excel_spreadSheet(), 'Xlsx'); - //결과파일저장 - $writer->save(PATHS['EXCEL'] . '/' . $fileName); - //Download시 - header("Content-Type: application/vnd.ms-excel"); - header(sprintf("Content-Disposition: attachment; filename=%s", urlencode($fileName))); - header("Expires: 0"); - header("Cache-Control: must-revalidate"); - header("Pragma: public"); - header("Content-Length:" . filesize(PATHS['EXCEL'] . '/' . $fileName)); - // flush(); - // return readfile(PATHS['EXCEL'] . '/' . $fileName); - return $writer->save('php://output'); - } public function excel() { try { - $this->_viewDatas['fields'] = $this->_model->getFields('excel'); - $this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'excel'); - $this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters(); - $this->_viewDatas['batchjobFilters'] = $this->_model->getFieldBatchFilters(); - $this->_viewDatas['fieldFormOptions'] = $this->getFieldFormOptions($this->_viewDatas['fieldFilters']); - return $this->excel_process(); + $this->_viewDatas = $this->init(__FUNCTION__); + $fileName = date('Y-m-d_Hm') . '.xlsx'; + $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($this->excel_spreadSheet($this->_viewDatas), 'Xlsx'); + //결과파일저장 + $writer->save(PATHS['EXCEL'] . '/' . $fileName); + //Download시 + header("Content-Type: application/vnd.ms-excel"); + header(sprintf("Content-Disposition: attachment; filename=%s", urlencode($fileName))); + header("Expires: 0"); + header("Cache-Control: must-revalidate"); + header("Pragma: public"); + header("Content-Length:" . filesize(PATHS['EXCEL'] . '/' . $fileName)); + // flush(); + // return readfile(PATHS['EXCEL'] . '/' . $fileName); + return $writer->save('php://output'); } catch (\Exception $e) { return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']))->with('return_message', $e->getMessage()); } @@ -583,7 +515,7 @@ abstract class BaseController extends Controller final public function download(string $field, $uid) { try { - $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); + $entity = $this->_backend->getEntity([$this->_backend->getPrimaryKey() => $uid]); if (!$entity->$field) { throw new \Exception("첨부파일이 확인되지 않습니다."); } diff --git a/app/Controllers/Front/BoardController.php b/app/Controllers/Front/BoardController.php deleted file mode 100644 index 96b5af9..0000000 --- a/app/Controllers/Front/BoardController.php +++ /dev/null @@ -1,74 +0,0 @@ -_className .= 'Board'; - $this->_model = new BoardModel(); - helper($this->_className); - $this->_viewPath .= strtolower($this->_className); - $this->_viewDatas['title'] = lang($this->_className . '.title'); - $this->_viewDatas['className'] = $this->_className; - } - - //BoardConfig모델 - final protected function getBoardConfigModel(): BoardConfigModel - { - return is_null($this->_boardConfigModel) ? new BoardConfigModel() : $this->_boardConfigModel; - } - - //Field별 Form Option용 - protected function getFieldFormOption(string $field): array - { - switch ($field) { - case 'board_config_uid': - $options = $this->_board_config_uids = $this->_board_config_uids ?: $this->getBoardConfigModel()->getFieldFormOptions(['status' => 'use']); - break; - default: - return parent::getFieldFormOption($field); - break; - } - if (!is_array($options)) { - throw new \Exception(__FUNCTION__ . "에서 {$this->_className}의 Field:{$field}의 FormOptionData가 array가 아닙니다.\n" . var_export($options, true)); - } - return $options; - } - - //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; - case 'board_file': - $this->_viewDatas['fieldDatas'][$field] = $this->single_upload_procedure($field, $entity); - break; - default: - return parent::getFieldFormData($field, $entity); - break; - } - return $this->_viewDatas['fieldDatas']; - } - - //View 관련 - protected function view_process($entity) - { - // view_cnt에 추가하기위함 - $this->_model->increaseViewCount($entity->getPrimaryKey()); - return parent::view_process($entity); - } -} diff --git a/app/Controllers/Front/FrontController.php b/app/Controllers/Front/FrontController.php index af77a1e..9ef0ac8 100644 --- a/app/Controllers/Front/FrontController.php +++ b/app/Controllers/Front/FrontController.php @@ -7,7 +7,7 @@ use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; -class FrontController extends BASEController +class FrontController extends BaseController { public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { diff --git a/app/Controllers/Front/FrontHierarchyController.php b/app/Controllers/Front/FrontHierarchyController.php deleted file mode 100644 index 67950b9..0000000 --- a/app/Controllers/Front/FrontHierarchyController.php +++ /dev/null @@ -1,63 +0,0 @@ -update_form_process($entity); - } - final public function reply_form($uid) - { - try { - $entity = $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); - $this->_viewDatas['fields'] = $this->_model->getFields('reply'); - $this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'reply'); - $this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters(); - $this->_viewDatas['entity'] = $this->reply_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']); - } - public function reply($uid) - { - $message = ""; - try { - $entity = $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); - $this->_viewDatas['fields'] = $this->_model->getFields('reply'); - $this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'reply'); - $this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters(); - $entity = $this->reply_validate($entity); - $entity = $this->reply_process($entity); - $message = "{$entity->getTitle()} " . __FUNCTION__ . " 완료하였습니다."; - log_message("info", "{$this->_viewDatas['title']} {$message}"); - return alert_CommonHelper($message, $this->_session->get(SESSION_NAMES['RETURN_URL'])); - } catch (\Exception $e) { - $message = __FUNCTION__ . " 실패하였습니다."; - log_message("warning", $e->getMessage()); - log_message("warning", var_export($this->_viewDatas['fieldDatas'], true)); - log_message("info", "{$this->_viewDatas['title']} {$message}",); - return redirect()->back()->withInput()->with("error", $message . "
\n{$e->getMessage()}"); - } - } -} diff --git a/app/Controllers/Front/UserController.php b/app/Controllers/Front/UserController.php deleted file mode 100644 index dfe72be..0000000 --- a/app/Controllers/Front/UserController.php +++ /dev/null @@ -1,37 +0,0 @@ -_className .= 'User'; - $this->_model = new UserModel(); - 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']; - } -} diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php index 7f867e9..ca4238a 100644 --- a/app/Controllers/Home.php +++ b/app/Controllers/Home.php @@ -2,8 +2,17 @@ namespace App\Controllers; -class Home extends BaseController +use CodeIgniter\Controller; +use CodeIgniter\HTTP\RequestInterface; +use CodeIgniter\HTTP\ResponseInterface; +use Psr\Log\LoggerInterface; + +class Home extends Controller { + public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) + { + parent::initController($request, $response, $logger); + } public function index() { return view('welcome_message'); diff --git a/app/Models/BaseHierarchyModel.php b/app/Models/BaseHierarchyModel.php index 1e6ab74..e3a6da5 100644 --- a/app/Models/BaseHierarchyModel.php +++ b/app/Models/BaseHierarchyModel.php @@ -11,8 +11,10 @@ abstract class BaseHierarchyModel extends BaseModel { parent::__construct(); $this->allowedFields = [...$this->allowedFields, "grpno", "grporder", "grpdepth"]; + $this->validationRules = [...$this->validationRules,]; } - abstract function reply($parent_entity, array $formDatas): BaseEntity; + abstract public function getContentField(); + abstract public function reply($parent_entity, array $formDatas): BaseEntity; protected function getFieldRule(string $field, array $rules, string $action = ""): array { switch ($field) { @@ -30,24 +32,24 @@ abstract class BaseHierarchyModel extends BaseModel final protected function create_process($entity, array $formDatas) { - $entity = parent::create_process($entity, $formDatas); - //생성시는 grpno가 primarykey와 같고 숫자여야함 - $this->builder()->set("grpno", $entity->getPrimaryKey()); - $this->builder()->where($this->primaryKey, $entity->getPrimaryKey()); - $this->builder()->update(); - return $entity; + //생성시는 grpno의 max값을 구해서 넣는다. + $entity->grpno = $this->selectMax("grpno")->get()->getResult()[0]->grpno + 1; + if (!$entity->grpno) { + throw new \Exception("grpno는 {$entity->grpno}의 값을 가질수 없습니다."); + } + return parent::create_process($entity, $formDatas); } final protected function reply_process($parent_entity, $entity, array $formDatas) { //부모의 그룹과 grpno가 같고, 부모의 grporder보다 1 큰것을 grporder+1을 해서 update //escape -> false옵션 반드시 있어야함 - $this->builder()->set("grporder", "grporder+1", false); - $this->builder()->where([ + $this->set("grporder", "grporder+1", false); + $this->where([ "grpno" => $parent_entity->grpno, "grporder >" => $parent_entity->grporder ]); - $this->builder()->update(); + $this->update(); //reply용 설정 $entity->grpno = $parent_entity->grpno; $entity->grporder = $parent_entity->grporder + 1; diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index 3f72b8f..4c90b1b 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -55,7 +55,7 @@ abstract class BaseModel extends Model { return $this->primaryKey; } - abstract public function getTitle(): string; + abstract public function getTitleField(): string; abstract public function getEntity($uid): BaseEntity; abstract public function getFieldFilters(): array; abstract public function getFields(string $action): array; @@ -183,6 +183,8 @@ abstract class BaseModel extends Model private function save_process($entity) { + // echo var_export($entity, true); + // exit; if ($entity->hasChanged()) { if (!$this->save($entity)) { log_message("error", __FUNCTION__ . "에서 호출:" . $this->getLastQuery()); diff --git a/app/Models/BoardConfigModel.php b/app/Models/BoardConfigModel.php index d216b94..35f824a 100644 --- a/app/Models/BoardConfigModel.php +++ b/app/Models/BoardConfigModel.php @@ -15,21 +15,21 @@ class BoardConfigModel extends BaseModel $this->allowedFields = [...$this->allowedFields, ...$this->getFields()]; $this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),]; } - public function getTitle(): string + public function getTitleField(): string { return 'name'; } public function getFields(string $action = ""): array { $fields = [ - $this->getTitle(), "isaccess", "isread", "iswrite", "isreply", "isupload", "isdownload", + $this->getTitleField(), "isaccess", "isread", "iswrite", "isreply", "isupload", "isdownload", "status", "head", "tail", ]; switch ($action) { case "index": case "excel": return [ - $this->getTitle(), "isaccess", "isread", "iswrite", "isreply", "isupload", "isdownload", + $this->getTitleField(), "isaccess", "isread", "iswrite", "isreply", "isupload", "isdownload", "status", "created_at" ]; break; @@ -56,7 +56,7 @@ class BoardConfigModel extends BaseModel $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}/]"; $rules[$field] .= $action == "insert" ? "|is_unique[{$this->table}.{$field}]" : ""; break; - case $this->getTitle(): + case $this->getTitleField(): $rules[$field] = "required|trim|string"; $rules[$field] .= $action == "insert" ? "|is_unique[{$this->table}.{$field}]" : ""; break; diff --git a/app/Models/BoardModel.php b/app/Models/BoardModel.php index 2f4c8ac..e4ec8d6 100644 --- a/app/Models/BoardModel.php +++ b/app/Models/BoardModel.php @@ -15,20 +15,24 @@ class BoardModel extends BaseHierarchyModel $this->allowedFields = [...$this->allowedFields, ...$this->getFields(), "user_uid"]; $this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),]; } - public function getTitle(): string + public function getTitleField(): string { return 'title'; } + public function getContentField(): string + { + return 'content'; + } public function getFields(string $action = ""): array { - $fields = ["board_config_uid", $this->getTitle(), "board_file", "passwd", "status", "content"]; + $fields = ["board_config_uid", $this->getTitleField(), "board_file", "passwd", "status", "content"]; switch ($action) { case "index": case "excel": - return ["board_config_uid", "user_uid", $this->getTitle(), "board_file", "view_cnt", "status", "created_at"]; + return ["board_config_uid", "user_uid", $this->getTitleField(), "board_file", "view_cnt", "status", "created_at"]; break; case "view": - return ["board_config_uid", "user_uid", $this->getTitle(), "board_file", "view_cnt", "status", "created_at", "content"]; + return ["board_config_uid", "user_uid", $this->getTitleField(), "board_file", "view_cnt", "status", "created_at", "content"]; break; default: return $fields; @@ -49,7 +53,7 @@ class BoardModel extends BaseHierarchyModel 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 $this->getTitle(): + case $this->getTitleField(): case "content": $rules[$field] = "required|string"; break; @@ -88,7 +92,7 @@ class BoardModel extends BaseHierarchyModel public function setIndexWordFilter(string $word) { parent::setIndexWordFilter($word); - $this->orLike($this->getTitle(), $word, "both"); + $this->orLike($this->getTitleField(), $word, "both"); $this->orLike("content", $word, "both"); //befor , after , both } } diff --git a/app/Models/UserModel.php b/app/Models/UserModel.php index 65f7a95..3771568 100644 --- a/app/Models/UserModel.php +++ b/app/Models/UserModel.php @@ -16,20 +16,20 @@ class UserModel extends BaseModel $this->allowedFields = ["uid", ...$this->allowedFields, ...$this->getFields()]; $this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),]; } - public function getTitle(): string + public function getTitleField(): string { return 'name'; } public function getFields(string $action = ""): array { - $fields = ["id", "passwd", $this->getTitle(), "email", "role", "status"]; + $fields = ["id", "passwd", $this->getTitleField(), "email", "role", "status"]; switch ($action) { case "index": case "excel": - return ["id", $this->getTitle(), "email", "role", "status", 'created_at']; + return ["id", $this->getTitleField(), "email", "role", "status", 'created_at']; break; case "view": - return ["id", $this->getTitle(), "email", "role", "status", 'updated_at', 'created_at']; + return ["id", $this->getTitleField(), "email", "role", "status", 'updated_at', 'created_at']; break; default: return $fields; @@ -57,7 +57,7 @@ class UserModel extends BaseModel $rules["confirmpassword"] = "required|trim|string|matches[passwd]"; } break; - case $this->getTitle(): + case $this->getTitleField(): $rules[$field] = "required|trim|string"; break; case "email": @@ -105,6 +105,6 @@ class UserModel extends BaseModel { parent::setIndexWordFilter($word); $this->orLike("id", $word, "both"); - $this->orLike($this->getTitle(), $word, "both"); //befor , after , both + $this->orLike($this->getTitleField(), $word, "both"); //befor , after , both } } diff --git a/app/Models/UserSNSModel.php b/app/Models/UserSNSModel.php index 4e5f3ed..c48c0f9 100644 --- a/app/Models/UserSNSModel.php +++ b/app/Models/UserSNSModel.php @@ -14,17 +14,17 @@ class UserSNSModel extends BaseModel $this->allowedFields = [...$this->allowedFields, ...$this->getFields(), "user_uid"]; $this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),]; } - public function getTitle(): string + public function getTitleField(): string { return 'name'; } public function getFields(string $action = ""): array { - $fields = ["site", "id", $this->getTitle(), "email", "detail", "status"]; + $fields = ["site", "id", $this->getTitleField(), "email", "detail", "status"]; switch ($action) { case "index": case "excel": - return ["user_uid", "site", "id", $this->getTitle(), "email", "status", "created_at"]; + return ["user_uid", "site", "id", $this->getTitleField(), "email", "status", "created_at"]; break; case "view": return [...$fields, "updated_at", "created_at"]; @@ -49,7 +49,7 @@ class UserSNSModel extends BaseModel $rules[$field] = "required|trim|string"; $rules[$field] .= $action == "insert" ? "|is_unique[{$this->table}.{$field}]" : ""; break; - case $this->getTitle(): + case $this->getTitleField(): $rules[$field] = "required|trim|string"; break; case "email": @@ -85,7 +85,7 @@ class UserSNSModel extends BaseModel public function setIndexWordFilter(string $word) { parent::setIndexWordFilter($word); - $this->orLike($this->getTitle(), $word, "both"); + $this->orLike($this->getTitleField(), $word, "both"); $this->orLike("email", $word, "both"); //befor , after , both } } diff --git a/app/Views/admin/board/reply.php b/app/Views/admin/board/reply.php index 9fca401..9791057 100644 --- a/app/Views/admin/board/reply.php +++ b/app/Views/admin/board/reply.php @@ -4,7 +4,6 @@ -
diff --git a/app/Views/layouts/admin/left_menu_hpilo.php b/app/Views/layouts/admin/left_menu_hpilo.php new file mode 100644 index 0000000..8b2d095 --- /dev/null +++ b/app/Views/layouts/admin/left_menu_hpilo.php @@ -0,0 +1,10 @@ + + + +
+
+ include($layout['path'] . '/left_menu/base'); ?> + include($layout['path'] . '/left_menu/board'); ?> + include($layout['path'] . '/left_menu/hpilo'); ?> +
+
\ No newline at end of file