diff --git a/app/Config/Constants.php b/app/Config/Constants.php index 2da7cf5..2fc5314 100644 --- a/app/Config/Constants.php +++ b/app/Config/Constants.php @@ -149,6 +149,7 @@ define('SESSION_NAMES', [ 'RETURN_URL' => "return_url", 'ISLOGIN' => "islogined", 'AUTH' => 'auth', + 'CART' => 'cart' ]); define('AUTH_FIELDS', ['ID' => 'id', 'TITLE' => 'title', 'ROLE' => 'role']); diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 0a684af..bb655f0 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -39,6 +39,10 @@ $routes->get('/login', 'AuthController::login'); $routes->post('/signup', 'AuthController::signup/local'); $routes->get('/signup/(:alpha)', 'AuthController::signup/$1'); $routes->get('/logout', 'AuthController::logout'); +$routes->group('cart', ['namespace' => 'App\Controllers'], static function ($routes) { + $routes->post('addCart', 'CartController::addCart'); + $routes->get('cancelCart/(:uuid)', 'CartController::cancelCart/$1'); +});; $routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) { }); // authGuard는 App\Config\Filters.php의 $aliases에 선언한 이름이어야 함 @@ -91,10 +95,23 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au $routes->post('batchjob', 'BoardController::batchjob'); $routes->get('download/(:any)/(:num)', 'BoardController::download/$1/$2'); }); + $routes->group('hpilo', static function ($routes) { + $routes->get('', 'HPILOController::index'); + $routes->get('excel', 'HPILOController::excel'); + $routes->get('insert', 'HPILOController::insert_form'); + $routes->post('insert', 'HPILOController::insert'); + $routes->get('update/(:num)', 'HPILOController::update_form/$1'); + $routes->post('update/(:num)', 'HPILOController::update/$1'); + $routes->get('view/(:num)', 'HPILOController::view/$1'); + $routes->get('delete/(:num)', 'HPILOController::delete/$1', ['filter' => 'authFilter:master']); + $routes->get('toggle/(:num)/(:hash)', 'HPILOController::toggle/$1/$2'); + $routes->post('batchjob', 'HPILOController::batchjob'); + $routes->get('console/(:num)', 'HPILOController::console/$1'); + $routes->get('reset/(:num)/(:alpha)', 'HPILOController::reset/$1/$2'); + $routes->get('reload/(:num)', 'HPILOController::reload/$1'); + }); }); -$routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($routes) { - $routes->get('/', 'Home::index'); -}); + /* * -------------------------------------------------------------------- * Additional Routing diff --git a/app/Config/Routes_HPILO.php b/app/Config/Routes_HPILO.php index 0eb6a56..bb655f0 100644 --- a/app/Config/Routes_HPILO.php +++ b/app/Config/Routes_HPILO.php @@ -36,14 +36,15 @@ $routes->addPlaceholder('uuid', '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4} $routes->get('/', 'Home::index'); $routes->get('/login', 'AuthController::login'); -$routes->post('/signin', 'AuthController::signin/local'); -$routes->get('/signin/(:alpha)', 'AuthController::signin/$1'); +$routes->post('/signup', 'AuthController::signup/local'); +$routes->get('/signup/(:alpha)', 'AuthController::signup/$1'); $routes->get('/logout', 'AuthController::logout'); +$routes->group('cart', ['namespace' => 'App\Controllers'], static function ($routes) { + $routes->post('addCart', 'CartController::addCart'); + $routes->get('cancelCart/(:uuid)', 'CartController::cancelCart/$1'); +});; $routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) { }); -$routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($routes) { - $routes->get('/', 'FrontController::index'); -}); // authGuard는 App\Config\Filters.php의 $aliases에 선언한 이름이어야 함 $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'authFilter:master,director,cloudflare,manager'], static function ($routes) { $routes->get('/', 'Home::index'); @@ -65,6 +66,7 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au $routes->get('view/(:num)', 'UserSNSController::view/$1'); $routes->get('delete/(:num)', 'UserSNSController::delete/$1'); $routes->get('toggle/(:num)/(:hash)', 'UserSNSController::toggle/$1/$2'); + $routes->post('batchjob', 'UserSNSController::batchjob'); }); $routes->group('boardconfig', static function ($routes) { $routes->get('', 'BoardConfigController::index'); @@ -91,7 +93,7 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au $routes->get('delete/(:num)', 'BoardController::delete/$1', ['filter' => 'authFilter:master']); $routes->get('toggle/(:num)/(:hash)', 'BoardController::toggle/$1/$2'); $routes->post('batchjob', 'BoardController::batchjob'); - $routes->get('download/(:num)', 'BoardController::download/$1'); + $routes->get('download/(:any)/(:num)', 'BoardController::download/$1/$2'); }); $routes->group('hpilo', static function ($routes) { $routes->get('', 'HPILOController::index'); @@ -109,6 +111,7 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au $routes->get('reload/(:num)', 'HPILOController::reload/$1'); }); }); + /* * -------------------------------------------------------------------- * Additional Routing diff --git a/app/Config/Services.php b/app/Config/Services.php index 9c71556..df7c8ad 100644 --- a/app/Config/Services.php +++ b/app/Config/Services.php @@ -29,32 +29,4 @@ 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(); - } } diff --git a/app/Controllers/Admin/BoardConfigController.php b/app/Controllers/Admin/BoardConfigController.php index 7b9e718..c675803 100644 --- a/app/Controllers/Admin/BoardConfigController.php +++ b/app/Controllers/Admin/BoardConfigController.php @@ -2,6 +2,7 @@ namespace App\Controllers\Admin; +use App\Models\BoardConfigModel; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; @@ -10,8 +11,41 @@ class BoardConfigController extends AdminController { public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { - $this->_backend = service('boardconfig'); + $this->_model = new BoardConfigModel(); parent::initController($request, $response, $logger); - $this->_viewPath .= strtolower($this->_backend->getClassName()); + $this->_viewDatas['title'] = lang($this->_model->getClassName() . '.title'); + $this->_viewPath .= strtolower($this->_model->getClassName()); + helper($this->_model->getClassName()); + } + + public function getFields(string $action = ""): array + { + $fields = [ + 'name', "isaccess", "isread", "iswrite", "isreply", "isupload", "isdownload", + "status", "head", "tail", + ]; + switch ($action) { + case "index": + case "excel": + return [ + 'name', "isaccess", "isread", "iswrite", "isreply", "isupload", "isdownload", + "status", "created_at" + ]; + break; + case "view": + return [...$fields, "updated_at", "created_at"]; + break; + default: + return $fields; + break; + } + } + public function getFieldFilters(): array + { + return ["isaccess", "isread", "iswrite", "isreply", "isupload", "isdownload", "status"]; + } + public function getFieldBatchFilters(): array + { + return parent::getFieldBatchFilters(); } } diff --git a/app/Controllers/Admin/BoardController.php b/app/Controllers/Admin/BoardController.php index e4b8cc4..adf8c30 100644 --- a/app/Controllers/Admin/BoardController.php +++ b/app/Controllers/Admin/BoardController.php @@ -2,6 +2,8 @@ namespace App\Controllers\Admin; +use App\Models\BoardConfigModel; +use App\Models\BoardModel; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; @@ -10,11 +12,37 @@ class BoardController extends AdminController { public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { - $this->_backend = service('board'); + $this->_model = new BoardModel(); parent::initController($request, $response, $logger); - $this->_viewPath .= strtolower($this->_backend->getClassName()); + $this->_viewDatas['title'] = lang($this->_model->getClassName() . '.title'); + $this->_viewPath .= strtolower($this->_model->getClassName()); + helper($this->_model->getClassName()); } + public function getFields(string $action = ""): array + { + $fields = ["board_config_uid", 'title', "board_file", "passwd", "status", "content"]; + switch ($action) { + case "index": + case "excel": + return ["board_config_uid", "user_uid", 'title', "board_file", "view_cnt", "status", "created_at"]; + break; + case "view": + return ["board_config_uid", "user_uid", 'title', "board_file", "view_cnt", "status", "created_at", "content"]; + break; + default: + return $fields; + break; + } + } + public function getFieldFilters(): array + { + return ["board_config_uid", "user_uid", "status"]; + } + public function getFieldBatchFilters(): array + { + return parent::getFieldBatchFilters(); + } //Field별 Form Datas 처리용 protected function getFieldFormData(string $field, $entity = null): array { diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php index dfd9e2e..8b5a6fe 100644 --- a/app/Controllers/Admin/UserController.php +++ b/app/Controllers/Admin/UserController.php @@ -2,6 +2,7 @@ namespace App\Controllers\Admin; +use App\Models\UserModel; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; @@ -10,9 +11,11 @@ class UserController extends AdminController { public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { - $this->_backend = service('user'); + $this->_model = new UserModel(); parent::initController($request, $response, $logger); - $this->_viewPath .= strtolower($this->_backend->getClassName()); + $this->_viewDatas['title'] = lang($this->_model->getClassName() . '.title'); + $this->_viewPath .= strtolower($this->_model->getClassName()); + helper($this->_model->getClassName()); } //Field별 Form Datas 처리용 @@ -29,4 +32,29 @@ class UserController extends AdminController } return $this->_viewDatas['fieldDatas']; } + + public function getFields(string $action = ""): array + { + $fields = ["id", "passwd", 'name', "email", "role", "status"]; + switch ($action) { + case "index": + case "excel": + return ["id", 'name', "email", "role", "status", 'created_at']; + break; + case "view": + return ["id", 'name', "email", "role", "status", 'updated_at', 'created_at']; + break; + default: + return $fields; + break; + } + } + public function getFieldFilters(): array + { + return ["role", "status"]; + } + public function getFieldBatchFilters(): array + { + return parent::getFieldBatchFilters(); + } } diff --git a/app/Controllers/Admin/UserSNSController.php b/app/Controllers/Admin/UserSNSController.php index 0531e19..72fa184 100644 --- a/app/Controllers/Admin/UserSNSController.php +++ b/app/Controllers/Admin/UserSNSController.php @@ -2,6 +2,7 @@ namespace App\Controllers\Admin; +use App\Models\UserSNSModel; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; @@ -10,8 +11,34 @@ class UserSNSController extends AdminController { public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { - $this->_backend = service('usersns'); + $this->_model = new UserSNSModel(); parent::initController($request, $response, $logger); - $this->_viewPath .= strtolower($this->_backend->getClassName()); + $this->_viewDatas['title'] = lang($this->_model->getClassName() . '.title'); + $this->_viewPath .= strtolower($this->_model->getClassName()); + helper($this->_model->getClassName()); + } + public function getFields(string $action = ""): array + { + $fields = ["site", "id", 'name', "email", "detail", "status"]; + switch ($action) { + case "index": + case "excel": + return ["user_uid", "site", "id", 'name', "email", "status", "created_at"]; + break; + case "view": + return [...$fields, "updated_at", "created_at"]; + break; + default: + return $fields; + break; + } + } + public function getFieldFilters(): array + { + return ["user_uid", "status"]; + } + public function getFieldBatchFilters(): array + { + return parent::getFieldBatchFilters(); } } diff --git a/app/Controllers/AuthController.php b/app/Controllers/AuthController.php index dbbf307..7f47607 100644 --- a/app/Controllers/AuthController.php +++ b/app/Controllers/AuthController.php @@ -3,18 +3,51 @@ namespace App\Controllers; use App\Libraries\Adapter\Auth\Adapter; +use CodeIgniter\Controller; +use CodeIgniter\HTTP\CLIRequest; +use CodeIgniter\HTTP\IncomingRequest; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; -class AuthController extends BaseController + +class AuthController extends Controller { + /** + * Instance of the main Request object. + * + * @var CLIRequest|IncomingRequest + */ + protected $request; + + /** + * An array of helpers to be loaded automatically upon + * class instantiation. These helpers will be available + * to all other controllers that extend BaseController. + * + * @var array + */ + protected $helpers = ['Common']; + + /** + * Be sure to declare properties for any property fetch you initialized. + * The creation of dynamic property is deprecated in PHP 8.2. + */ + // protected $session; + + /** + * Constructor. + */ + private $_session = null; + private $_viewDatas = array(); private $_adapters = array(); public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { - $this->_backend = service('user'); parent::initController($request, $response, $logger); - $this->_viewPath .= strtolower($this->_backend->getClassName()); + $this->_session = \Config\Services::session(); + $this->_viewDatas['title'] = 'Auth'; + $this->_viewDatas['layout'] = LAYOUTS['empty']; + $this->_viewDatas['session'] = $this->_session; $this->initAdapters(); } diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php index 7464dda..df390e0 100644 --- a/app/Controllers/BaseController.php +++ b/app/Controllers/BaseController.php @@ -3,6 +3,7 @@ namespace App\Controllers; +use App\Models\UserModel; use CodeIgniter\Controller; use CodeIgniter\HTTP\CLIRequest; use CodeIgniter\HTTP\Files\UploadedFile; @@ -48,7 +49,7 @@ abstract class BaseController extends Controller /** * Constructor. */ - protected $_backend = null; + protected $_model = null; protected $_session = null; protected $_viewPath = ''; protected $_viewDatas = array(); @@ -60,11 +61,15 @@ abstract class BaseController extends Controller // E.g.: $this->session = \Config\Services::session(); $this->_session = \Config\Services::session(); $this->_viewDatas['layout'] = LAYOUTS['empty']; - $this->_viewDatas['title'] = lang($this->_backend->getClassName() . '.title'); $this->_viewDatas['session'] = $this->_session; - helper($this->_backend->getClassName()); } + abstract public function getFields(string $action): array; + abstract public function getFieldFilters(): array; + public function getFieldBatchFilters(): array + { + return $this->getFieldFilters(); + } //Field별 Form Datas 처리용 protected function getFieldFormData(string $field, $entity = null): array { @@ -121,15 +126,14 @@ abstract class BaseController extends Controller $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']); + $this->_viewDatas['fields'] = $fields ?: $this->getFields($action); + $this->_viewDatas['fieldFilters'] = $this->getFieldFilters(); + $this->_viewDatas['batchjobFilters'] = $this->getFieldBatchFilters(); + $this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], $action); + $this->_viewDatas['fieldFormOptions'] = $this->_model->getFieldFormOptions($this->_viewDatas['fieldFilters']); return $this->_viewDatas; } - //Insert관련 final public function insert_form() { @@ -140,10 +144,11 @@ abstract class BaseController extends Controller $this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']); return view($this->_viewPath . '/insert', $this->_viewDatas); } catch (\Exception $e) { + log_message("error", $e->getMessage()); return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']))->with('return_message', $e->getMessage()); } } - protected function insert_process() + protected function insert_validate() { //fieldData Rule 검사 if (!$this->validate($this->_viewDatas['fieldRules'])) { @@ -155,13 +160,17 @@ abstract class BaseController extends Controller $this->_viewDatas['fieldDatas'] = $this->getFieldFormData($field); } } + protected function insert_process() + { + return $this->_model->create($this->_viewDatas['fieldDatas']); + } public function insert() { $msg = ""; try { $this->_viewDatas = $this->init(__FUNCTION__); - $this->insert_process(); - $entity = $this->_backend->insert($this->_viewDatas['fieldDatas']); + $this->insert_validate(); + $entity = $this->insert_process(); $msg = "{$this->_viewDatas['title']}에서 {$entity->getTitle()}의 " . __FUNCTION__ . " 완료하였습니다."; return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); } catch (\Exception $e) { @@ -180,14 +189,15 @@ abstract class BaseController extends Controller $this->_viewDatas = $this->init(__FUNCTION__); $this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []]; helper(['form']); - $this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']); - $this->_viewDatas['entity'] = $this->_backend->getEntity($uid); + $$this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']); + $this->_viewDatas['entity'] = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); return view($this->_viewPath . '/update', $this->_viewDatas); } catch (\Exception $e) { + log_message("error", $e->getMessage()); return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']))->with('return_message', $e->getMessage()); } } - protected function update_process() + protected function update_validate($entity) { //fieldData Rule 검사 if (!$this->validate($this->_viewDatas['fieldRules'])) { @@ -196,21 +206,25 @@ abstract class BaseController extends Controller //fieldData 적용 $this->_viewDatas['fieldDatas'] = array(); foreach ($this->_viewDatas['fields'] as $field) { - $this->_viewDatas['fieldDatas'] = $this->getFieldFormData($field, $this->_viewDatas['entity']); + $this->_viewDatas['fieldDatas'] = $this->getFieldFormData($field, $entity); log_message( "info", - "{$field} : {$this->_viewDatas['entity']->$field} => " . var_export($this->_viewDatas['fieldDatas'][$field]) + "{$field} : {$entity->$field} => " . var_export($this->_viewDatas['fieldDatas'][$field]) ); } } + protected function update_process($entity) + { + return $this->_model->modify($entity, $this->_viewDatas['fieldDatas']); + } public function update($uid) { $msg = ""; try { $this->_viewDatas = $this->init(__FUNCTION__); - $entity = $this->_viewDatas['entity'] = $this->_backend->getEntity($uid); - $this->update_process(); - $entity = $this->_backend->update($entity, $this->_viewDatas['fieldDatas']); + $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); + $this->update_validate($entity); + $entity = $this->update_process($entity); $msg = "{$this->_viewDatas['title']}에서 {$entity->getTitle()}의 " . __FUNCTION__ . " 완료하였습니다."; return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); } catch (\Exception $e) { @@ -230,29 +244,34 @@ abstract class BaseController extends Controller $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 = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); + $titleField = $this->_model->getTitleField(); $entity->$titleField = "RE: " . $entity->$titleField; - $contentField = $this->_backend->getContentField(); + $contentField = $this->_model->getContentField(); $entity->$contentField .= "\n----------------------------------------------\n"; $this->_viewDatas['entity'] = $entity; return view($this->_viewPath . '/reply', $this->_viewDatas); } catch (\Exception $e) { + log_message("error", $e->getMessage()); return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']))->with('return_message', $e->getMessage()); } } - protected function reply_process() + protected function reply_validate($entity) { - $this->update_process(); + $this->update_validate($entity); + } + protected function reply_process($entity) + { + return $this->_model->reply($entity, $this->_viewDatas['fieldDatas']); } 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']); + $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); + $this->reply_validate($entity); + $entity = $this->reply_process($entity); $msg = "{$this->_viewDatas['title']}에서 {$entity->getTitle()}의 " . __FUNCTION__ . " 완료하였습니다."; return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); } catch (\Exception $e) { @@ -265,31 +284,40 @@ abstract class BaseController extends Controller } //Toggle 관련 - protected function toggle_process() + protected function toggle_validate($entity) { - $this->update_process(); + $this->update_validate($entity); + } + protected function toggle_process($entity) + { + return $this->update_process($entity); } public function toggle($uid, string $field) { $msg = ""; try { $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']); + $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); + $this->toggle_validate($entity); + $entity = $this->toggle_process($entity); $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()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); } finally { $this->_session->setFlashdata("return_message", $msg); - return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); } } //Batchjob 관련 - protected function batchjob_process() + protected function batchjob_validate($entity) { - $this->update_process(); + $this->update_validate($entity); + } + protected function batchjob_process($entity) + { + return $this->update_process($entity); } public function batchjob() { @@ -299,7 +327,7 @@ abstract class BaseController extends Controller try { //fields 해당하는 field중 선택된 값이 있는경우만 fields로 정의 $fields = array(); - foreach ($this->_backend->getFieldBatchFilters() as $field) { + foreach ($this->_model->getFieldBatchFilters() as $field) { if ($this->request->getVar($field)) { array_push($fields, $field); } @@ -309,15 +337,15 @@ abstract class BaseController extends Controller } $this->_viewDatas = $this->init(__FUNCTION__, $fields); $uids = $this->request->getVar('batchjob_uids') ?: throw new \Exception($this->_viewDatas['title'] . '에서 변경할 항목(uid)이 선택되지 않았습니다.'); - $cnt = 1; //Transaction 시작 - $this->_backend->transStart(); + $this->_model->transStart(); foreach ($uids as $uid) { try { - $entity = $this->_viewDatas['entity'] = $this->_backend->getEntity($uid); - $this->batchjob_process(); - array_push($entitys, $this->_backend->update($entity, $this->_viewDatas['fieldDatas'])); + $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); + $this->batchjob_validate($entity); + $entity = $this->batchjob_process($entity); + array_push($entitys, $this->_model->modify($entity, $this->_viewDatas['fieldDatas'])); array_push($batchjobs, "{$cnt}. {$uid}->{$entity->getTitle()}는 완료."); } catch (\Exception $e) { array_push($batchjobs, "{$cnt}. {$uid}는 실패."); @@ -325,16 +353,17 @@ abstract class BaseController extends Controller $cnt++; } //Transaction Commit - $this->_backend->transCommit(); + $this->_model->transComplete(); $msg = sprintf( "%s에서 총:%s개의 %s 완료하였습니다.", $this->_viewDatas['title'], count($entitys), __FUNCTION__ ); + return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); } catch (\Exception $e) { //Transaction Rollback - $this->_backend->transRollback(); + $this->_model->transRollback(); log_message('error', sprintf("---------batchjob 작업결과--------\n%s\n", implode("\n", $batchjobs))); return sprintf( "총:%s개의 작업중 %s개는 성공하였지만 , %s개가 실패하여 %s 취소되었습니다.\n%s", @@ -344,25 +373,36 @@ abstract class BaseController extends Controller __FUNCTION__, ); log_message("error", $e->getMessage()); + return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); } finally { $this->_session->setFlashdata("return_message", $msg); - return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); } } //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->_backend->delete($this->_backend->getEntity($uid)); + $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); + $this->delete_process($entity); $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()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); } finally { $this->_session->setFlashdata("return_message", $msg); - return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); } } @@ -377,8 +417,7 @@ abstract class BaseController extends Controller $this->_viewDatas = $this->init(__FUNCTION__); helper(['form']); $this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []]; - $entity = $this->_viewDatas['entity'] = $this->_backend->getEntity($uid); - $this->_viewDatas['entity'] = $this->_backend->view($entity); + $this->_viewDatas['entity'] = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); $this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']); return view($this->_viewPath . '/view', $this->_viewDatas); } catch (\Exception $e) { @@ -387,26 +426,7 @@ abstract class BaseController extends Controller } //Index 관련 - 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->_backend->paginate($this->_viewDatas['per_page'], $pager_group, $this->_viewDatas['page'], $segment); - $pager->makeLinks( - $this->_viewDatas['page'], - $this->_viewDatas['per_page'], - $this->_viewDatas['total_count'], - $template, - $segment, - $pager_group - ); - $this->_viewDatas['page'] = $pager->getCurrentPage($pager_group); - $this->_viewDatas['total_page'] = $pager->getPageCount($pager_group); - return $pager->links($pager_group, $template); - } - private function index_setCondition() + protected function index_setCondition() { //조건절 처리 $filterFields = array(); @@ -420,12 +440,34 @@ abstract class BaseController extends Controller $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); + $this->_model->setCondition($filterFields, $word, $start, $end, $order_field, $order_value); } - private function index_getEntitys(int $page = 0, int $per_page = 0) + 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); + $pager->makeLinks( + $this->_viewDatas['page'], + $this->_viewDatas['per_page'], + $this->_viewDatas['total_count'], + $template, + $segment, + $pager_group + ); + $this->_viewDatas['page'] = $pager->getCurrentPage($pager_group); + $this->_viewDatas['total_page'] = $pager->getPageCount($pager_group); + return $pager->links($pager_group, $template); + } + private function index_getEntitys(): array { $this->index_setCondition(); - return $this->_backend->getFindEntitys($page, $per_page); + return $this->_viewDatas['page'] ? $this->_model->findAll( + $this->_viewDatas['per_page'], + $this->_viewDatas['page'] * $this->_viewDatas['per_page'] - $this->_viewDatas['per_page'] + ) : $this->_model->findAll(); } public function index() { @@ -441,12 +483,13 @@ abstract class BaseController extends Controller $this->_viewDatas['end'] = $this->request->getVar('end') ?: ''; $this->_viewDatas['order_field'] = $this->request->getVar('order_field') ?: 'uid'; $this->_viewDatas['order_value'] = $this->request->getVar('order_value') ?: 'DESC'; - $this->_viewDatas['page'] = $this->request->getVar('page') ?: 1; - $this->_viewDatas['per_page'] = $this->request->getVar('per_page') ?: DEFAULTS['PERPAGE']; + $this->_viewDatas['page'] = (int)$this->request->getVar('page') ?: 1; + $this->_viewDatas['per_page'] = (int)$this->request->getVar('per_page') ?: DEFAULTS['PERPAGE']; $this->_viewDatas['uri'] = $this->request->getUri(); //Totalcount 처리 $this->index_setCondition(); - $this->_viewDatas['total_count'] = $this->_backend->getTotalCount(); + $this->_viewDatas['total_count'] = $this->_model->countAllResults(); + // log_message("debug", __METHOD__ . "에서 TotalCount 호출:" . $this->_model->getLastQuery()); //줄수 처리용 $this->_viewDatas['pageOptions'] = array("" => "줄수선택"); for ($i = 10; $i <= $this->_viewDatas['total_count'] + $this->_viewDatas['per_page']; $i += 10) { @@ -455,8 +498,9 @@ abstract class BaseController extends Controller //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()); + $this->_viewDatas['entitys'] = $this->index_getEntitys(); + // echo $this->_model->getLastQuery(); + // log_message("debug", __METHOD__ . "에서 findAll 호출:" . $this->_model->getLastQuery()); //setting return_url to session flashdata $this->_session->setFlashdata(SESSION_NAMES['RETURN_URL'], current_url() . '?' . $this->request->getUri()->getQuery() ?: ""); return view($this->_viewPath . '/index', $this->_viewDatas); @@ -474,7 +518,7 @@ abstract class BaseController extends Controller //Header용 $column = 'A'; foreach ($viewDatas['fields'] as $field) { - $sheet->setCellValue($column++ . '1', lang($this->_backend->getClassName() . '.label.' . $field)); + $sheet->setCellValue($column++ . '1', lang($this->_model->getClassName() . '.label.' . $field)); } //본문용 $line = 2; @@ -515,7 +559,7 @@ abstract class BaseController extends Controller final public function download(string $field, $uid) { try { - $entity = $this->_backend->getEntity($uid); + $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); if (!$entity->$field) { throw new \Exception("첨부파일이 확인되지 않습니다."); } diff --git a/app/Controllers/Front/FrontController.php b/app/Controllers/Front/FrontController.php index 9ef0ac8..dbdf323 100644 --- a/app/Controllers/Front/FrontController.php +++ b/app/Controllers/Front/FrontController.php @@ -7,13 +7,12 @@ use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; -class FrontController extends BaseController +abstract class FrontController extends BaseController { public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { parent::initController($request, $response, $logger); - $this->_viewPath .= strtolower('Front/'); + $this->_viewPath .= 'front/'; $this->_viewDatas['layout'] = LAYOUTS['front']; - $this->_viewDatas['title'] = "사용자페이지"; } } diff --git a/app/Entities/BaseEntity.php b/app/Entities/BaseEntity.php index 6354677..deab2a9 100644 --- a/app/Entities/BaseEntity.php +++ b/app/Entities/BaseEntity.php @@ -7,6 +7,6 @@ use CodeIgniter\Entity\Entity; abstract class BaseEntity extends Entity { abstract public function getPrimaryKey(); - abstract public function getTitle(); - abstract public function getStatus(); + abstract public function getTitle(): string; + abstract public function getStatus(): string; } diff --git a/app/Entities/BoardConfigEntity.php b/app/Entities/BoardConfigEntity.php index 3459fe1..318a3ef 100644 --- a/app/Entities/BoardConfigEntity.php +++ b/app/Entities/BoardConfigEntity.php @@ -13,11 +13,11 @@ class BoardConfigEntity extends BaseEntity { return $this->attributes['uid']; } - public function getTitle() + public function getTitle(): string { return $this->attributes['name']; } - public function getStatus() + public function getStatus(): string { return $this->attributes['status']; } diff --git a/app/Entities/BoardEntity.php b/app/Entities/BoardEntity.php index 7dfcbd5..3580fb3 100644 --- a/app/Entities/BoardEntity.php +++ b/app/Entities/BoardEntity.php @@ -13,11 +13,11 @@ class BoardEntity extends BaseHierarchyEntity { return $this->attributes['uid']; } - public function getTitle() + public function getTitle(): string { return $this->attributes['title']; } - public function getStatus() + public function getStatus(): string { return $this->attributes['status']; } @@ -31,4 +31,8 @@ class BoardEntity extends BaseHierarchyEntity { return $this->attributes['view_cnt']; } + public function getUser_Uid() + { + return $this->attributes['user_uid']; + } } diff --git a/app/Entities/UserEntity.php b/app/Entities/UserEntity.php index 0705302..9344533 100644 --- a/app/Entities/UserEntity.php +++ b/app/Entities/UserEntity.php @@ -13,11 +13,11 @@ class UserEntity extends BaseEntity { return $this->attributes['uid']; } - public function getTitle() + public function getTitle(): string { return $this->attributes['name']; } - public function getStatus() + public function getStatus(): string { return $this->attributes['status']; } diff --git a/app/Entities/UserSNSEntity.php b/app/Entities/UserSNSEntity.php index 2c5298c..d1e02ec 100644 --- a/app/Entities/UserSNSEntity.php +++ b/app/Entities/UserSNSEntity.php @@ -13,11 +13,11 @@ class UserSNSEntity extends BaseEntity { return $this->attributes['uid']; } - public function getTitle() + public function getTitle(): string { return $this->attributes['name']; } - public function getStatus() + public function getStatus(): string { return $this->attributes['status']; } diff --git a/app/Helpers/BoardConfig_helper.php b/app/Helpers/BoardConfig_helper.php index 3c55c59..38f7c02 100644 --- a/app/Helpers/BoardConfig_helper.php +++ b/app/Helpers/BoardConfig_helper.php @@ -81,7 +81,7 @@ function getFieldView_BoardConfigHelper($field, $entity, array $fieldFilters, ar return html_entity_decode($value); break; default: - return in_array($field, $fieldFilters) ? $fieldFormOptions[$field][$value] : $value; + return in_array($field, $fieldFilters) && $value ? $fieldFormOptions[$field][$value] : $value; break; } } // @@ -108,11 +108,20 @@ function getFieldIndex_Row_BoardConfigHelper($field, $entity, array $fieldFilter { switch ($field) { default: - if (in_array($field, $fieldFilters)) { - $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field); - return getFieldFilter_BoardConfigHelper($field, $entity->$field, $fieldFormOptions, [...$attributes, 'style' => 'width:100%']); - } return getFieldView_BoardConfigHelper($field, $entity, $fieldFormOptions, $attributes); break; } +} // + +function getFieldIndex_Row_BoardConfigHelper_Admin($field, $entity, array $fieldFilters, $fieldFormOptions, $attributes = array()): string +{ + switch ($field) { + default: + if (in_array($field, $fieldFilters)) { + $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field); + return getFieldFilter_BoardConfigHelper($field, $entity->$field, $fieldFormOptions, $attributes); + } + return getFieldIndex_Row_BoardConfigHelper($field, $entity, $fieldFormOptions, $attributes); + break; + } } // \ No newline at end of file diff --git a/app/Helpers/Board_helper.php b/app/Helpers/Board_helper.php index 0a3f72e..a8fe607 100644 --- a/app/Helpers/Board_helper.php +++ b/app/Helpers/Board_helper.php @@ -98,7 +98,7 @@ function getFieldView_BoardHelper($field, $entity, array $fieldFilters, array $f return $value ? str_split($value, 10)[0] : ""; break; default: - return in_array($field, $fieldFilters) ? $fieldFormOptions[$field][$value] : $value; + return in_array($field, $fieldFilters) && $value ? $fieldFormOptions[$field][$value] : $value; break; } } // @@ -125,11 +125,20 @@ function getFieldIndex_Row_BoardHelper($field, $entity, array $fieldFilters, $fi { switch ($field) { default: - if (in_array($field, $fieldFilters)) { - $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field); - return getFieldFilter_BoardHelper($field, $entity->$field, $fieldFormOptions, [...$attributes, 'style' => 'width:100%']); - } return getFieldView_BoardHelper($field, $entity, $fieldFormOptions, $attributes); break; } +} // + +function getFieldIndex_Row_BoardHelper_Admin($field, $entity, array $fieldFilters, $fieldFormOptions, $attributes = array()): string +{ + switch ($field) { + default: + if (in_array($field, $fieldFilters)) { + $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field); + return getFieldFilter_BoardHelper($field, $entity->$field, $fieldFormOptions, $attributes); + } + return getFieldIndex_Row_BoardHelper($field, $entity, $fieldFormOptions, $attributes); + break; + } } // \ No newline at end of file diff --git a/app/Helpers/UserSNS_helper.php b/app/Helpers/UserSNS_helper.php index 47c0418..801e8aa 100644 --- a/app/Helpers/UserSNS_helper.php +++ b/app/Helpers/UserSNS_helper.php @@ -71,7 +71,7 @@ function getFieldView_UserSNSHelper($field, $entity, array $fieldFilters, array return isset($value) ? str_split($value, 10)[0] : ""; break; default: - return in_array($field, $fieldFilters) ? $fieldFormOptions[$field][$value] : $value; + return in_array($field, $fieldFilters) && $value ? $fieldFormOptions[$field][$value] : $value; break; } } // @@ -98,11 +98,20 @@ function getFieldIndex_Row_UserSNSHelper($field, $entity, array $fieldFilters, $ { switch ($field) { default: - if (in_array($field, $fieldFilters)) { - $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field); - return getFieldFilter_UserSNSHelper($field, $entity->$field, $fieldFormOptions, [...$attributes, 'style' => 'width:100%']); - } return getFieldView_UserSNSHelper($field, $entity, $fieldFormOptions, $attributes); break; } +} // + +function getFieldIndex_Row_UserSNSHelper_Admin($field, $entity, array $fieldFilters, $fieldFormOptions, $attributes = array()): string +{ + switch ($field) { + default: + if (in_array($field, $fieldFilters)) { + $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field); + return getFieldFilter_UserSNSHelper($field, $entity->$field, $fieldFormOptions, $attributes); + } + return getFieldIndex_Row_UserSNSHelper($field, $entity, $fieldFormOptions, $attributes); + break; + } } // \ No newline at end of file diff --git a/app/Helpers/User_helper.php b/app/Helpers/User_helper.php index ed81ffa..17ff344 100644 --- a/app/Helpers/User_helper.php +++ b/app/Helpers/User_helper.php @@ -77,7 +77,7 @@ function getFieldView_UserHelper($field, $entity, array $fieldFilters, array $fi return html_entity_decode($value); break; default: - return in_array($field, $fieldFilters) ? $fieldFormOptions[$field][$value] : $value; + return in_array($field, $fieldFilters) && $value ? $fieldFormOptions[$field][$value] : $value; break; } } // @@ -104,11 +104,20 @@ function getFieldIndex_Row_UserHelper($field, $entity, array $fieldFilters, $fie { switch ($field) { default: - if (in_array($field, $fieldFilters)) { - $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field); - return getFieldFilter_UserHelper($field, $entity->$field, $fieldFormOptions, [...$attributes, 'style' => 'width:100%']); - } return getFieldView_UserHelper($field, $entity, $fieldFormOptions, $attributes); break; } +} // + +function getFieldIndex_Row_UserHelper_Admin($field, $entity, array $fieldFilters, $fieldFormOptions, $attributes = array()): string +{ + switch ($field) { + default: + if (in_array($field, $fieldFilters)) { + $attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field); + return getFieldFilter_UserHelper($field, $entity->$field, $fieldFormOptions, $attributes); + } + return getFieldIndex_Row_UserHelper($field, $entity, $fieldFormOptions, $attributes); + break; + } } // \ No newline at end of file diff --git a/app/Libraries/Adapter/Auth/Adapter.php b/app/Libraries/Adapter/Auth/Adapter.php index 83ed02a..1e18cd4 100644 --- a/app/Libraries/Adapter/Auth/Adapter.php +++ b/app/Libraries/Adapter/Auth/Adapter.php @@ -2,9 +2,9 @@ namespace App\Libraries\Adapter\Auth; +use App\Entities\UserEntity; use App\Models\UserModel; use App\Models\UserSNSModel; -use App\Entities\UserEntity; // 참고:https://github.com/SyntaxPhoenix/iloclient abstract class Adapter @@ -50,7 +50,7 @@ abstract class Adapter { $this->_session->set(SESSION_NAMES['ISLOGIN'], true); $auths = []; - foreach (AUTH_FIELDS as $key => $field) { + foreach (array_values(AUTH_FIELDS) as $field) { switch ($field) { case 'id': $auths[$field] = $entity->getPrimaryKey(); diff --git a/app/Models/BaseHierarchyModel.php b/app/Models/BaseHierarchyModel.php index e3a6da5..d56cdce 100644 --- a/app/Models/BaseHierarchyModel.php +++ b/app/Models/BaseHierarchyModel.php @@ -7,9 +7,9 @@ use App\Entities\BaseEntity; //계층형구조구현용 모델(게시판,카테고리 등등) abstract class BaseHierarchyModel extends BaseModel { - protected function __construct() + protected function __construct(string $className) { - parent::__construct(); + parent::__construct($className); $this->allowedFields = [...$this->allowedFields, "grpno", "grporder", "grpdepth"]; $this->validationRules = [...$this->validationRules,]; } diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index 2ad10bc..f57d605 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -40,28 +40,36 @@ abstract class BaseModel extends Model protected $beforeDelete = []; protected $afterDelete = []; + private $_user_options = null; + private $_className = null; protected $_session = null; - protected function __construct() + protected function __construct(string $className) { + $this->_className = $className; parent::__construct(); - $this->allowedFields = ["updated_at", "created_at"]; + $this->allowedFields = ["uid", "updated_at", "created_at"]; if (!$this->useAutoIncrement) { array_push($this->allowedFields, $this->primaryKey); } $this->validationRules = []; $this->_session = \Config\Services::session(); } + final public function getClassName() + { + return $this->_className; + } final public function getPrimaryKey(): string { return $this->primaryKey; } abstract public function getTitleField(): string; - abstract public function getEntity($uid): BaseEntity; - abstract public function getFieldFilters(): array; - abstract public function getFields(string $action): array; - final public function getEntitys($conditions = false): array + public function getEntity($conditions): BaseEntity { - return $conditions ? $this->where($conditions)->findAll() : $this->findAll(); + return $this->where($conditions)->first() ?: throw new \Exception(__FUNCTION__ . "에서 {$this->getClassName()}의 해당 데이터가 없습니다.\n" . var_export($conditions, true)); + } + final public function getEntitys(array $conditions = array()): array + { + return $this->where($conditions)->findAll(); } protected function getFieldRule(string $field, array $rules, string $action = ""): array { @@ -106,18 +114,45 @@ abstract class BaseModel extends Model } return $rules; } - public function getFieldBatchFilters(): array - { - return $this->getFieldFilters(); - } - - public function getFieldFormOptions($conditions, $options = array()): array + //Field별 Form Option용 + public function getOptions(array $conditions = array(), $options = array()): array { foreach ($this->getEntitys($conditions) as $entity) { $options[$entity->getPrimaryKey()] = $entity->getTitle(); } return $options; } + public function getFieldFormOption(string $field): array + { + switch ($field) { + case 'user_uid': + if (is_null($this->_user_options)) { + $userModel = new UserModel([$this->getPrimaryKey(), $this->getTitleField()]); + $this->_user_options = $userModel->getOptions(); + } + $options = $this->_user_options; + break; + default: + $options = lang($this->getClassName() . '.' . strtoupper($field)); + break; + } + if (!is_array($options)) { + throw new \Exception(__FUNCTION__ . "에서 {$this->getClassName()}의 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->getClassName()}의 Field:{$field}가 string 아닙니다.\n" . var_export($fields, true)); + } + $fieldFormOptions[$field] = $this->getFieldFormOption($field); + } + return $fieldFormOptions; + } final public function getUUID() { @@ -132,15 +167,6 @@ 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(string $action, string $field, array $formDatas, $entity) { @@ -152,10 +178,12 @@ abstract class BaseModel extends Model $entity->$pk = $this->getUUID(); } break; - case "user_uid": //입력데이터로 있을시 추가, 없을시는 입력의 경우에만 자동으로 추가 + case "user_uid": //입력데이터로 있을시 관리툴에서 (사용자,등)추가, 없을시는 입력의 경우에만 자동(장바구니,등)으로 추가 if (array_key_exists($field, $formDatas) && !is_null($formDatas[$field])) { + //관리툴 USERSNS에서 사용자 연동 시 추가기능등에 사용 $entity->$field = $formDatas[$field]; } elseif ($action == 'create' && $this->_session->get(SESSION_NAMES["ISLOGIN"])) { + //Front에서 장바구니,게시판등에 추가시 로그온한경우 자동 추가기능등에 사용 $auth = $this->_session->get(SESSION_NAMES["AUTH"]); $entity->$field = $auth[AUTH_FIELDS["ID"]]; } @@ -227,15 +255,30 @@ abstract class BaseModel extends Model public function setIndexWordFilter(string $word) { } - public function setIndexDateFilterTrit($start, $end) + public function setIndexDateFilter($start, $end) { $this->where("created_at >=", $start); $this->where("created_at <=", $end); } public function setIndexOrderBy(?string $field, ?string $order) { - if (!is_null($field) && !is_null($order)) { + if ($this->useAutoIncrement) { $this->orderBy($field ?: $this->primaryKey, $order ?: "DESC"); + } else { + $this->orderBy($field ?: "created_at", $order ?: "DESC"); } } + final public function setCondition(array $filterFields, $word, $start, $end, $order_field, $order_value) + { + foreach ($filterFields as $field => $value) { + $this->where($field, $value); + } + if (!is_null($word)) { + $this->setIndexWordFilter($word); + } + if (!is_null($start) && !is_null($end)) { + $this->setIndexDateFilter($start, $end); + } + $this->setIndexOrderBy($order_field, $order_value); + } } diff --git a/app/Models/BoardConfigModel.php b/app/Models/BoardConfigModel.php index 8793943..56cfc7b 100644 --- a/app/Models/BoardConfigModel.php +++ b/app/Models/BoardConfigModel.php @@ -11,44 +11,18 @@ class BoardConfigModel extends BaseModel protected $returnType = BoardConfigEntity::class; public function __construct() { - parent::__construct(); - $this->allowedFields = [...$this->allowedFields, ...$this->getFields()]; + parent::__construct('BoardConfig'); + $this->allowedFields = [ + ...$this->allowedFields, + 'name', "isaccess", "isread", "iswrite", "isreply", "isupload", "isdownload", + "head", "tail", "status" + ]; $this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),]; } public function getTitleField(): string { return 'name'; } - public function getFields(string $action = ""): array - { - $fields = [ - $this->getTitleField(), "isaccess", "isread", "iswrite", "isreply", "isupload", "isdownload", - "status", "head", "tail", - ]; - switch ($action) { - case "index": - case "excel": - return [ - $this->getTitleField(), "isaccess", "isread", "iswrite", "isreply", "isupload", "isdownload", - "status", "created_at" - ]; - break; - case "view": - return [...$fields, "updated_at", "created_at"]; - break; - default: - return $fields; - break; - } - } - public function getFieldFilters(): array - { - return ["isaccess", "isread", "iswrite", "isreply", "isupload", "isdownload", "status"]; - } - public function getFieldBatchFilters(): array - { - return parent::getFieldBatchFilters(); - } protected function getFieldRule(string $field, array $rules, string $action = ""): array { switch ($field) { @@ -76,7 +50,7 @@ class BoardConfigModel extends BaseModel } public function getEntity($conditions): BoardConfigEntity { - return $this->where($conditions)->first() ?: throw new \Exception("해당 데이터가 없습니다.\n" . var_export($conditions, true)); + return parent::getEntity($conditions); } protected function changeFormData(string $action, string $field, array $formDatas, $entity) diff --git a/app/Models/BoardModel.php b/app/Models/BoardModel.php index e4ec8d6..de21620 100644 --- a/app/Models/BoardModel.php +++ b/app/Models/BoardModel.php @@ -6,13 +6,18 @@ use App\Entities\BoardEntity; class BoardModel extends BaseHierarchyModel { - //BaseHierarchyModel를 확장하면 grpno가 숫자이고, primarykey를 대분류 생성시 copy하여 grpno에 넣고 sorting하므로 + private $_boardconfig_options = null; protected $table = "tw_board"; protected $returnType = BoardEntity::class; public function __construct() { - parent::__construct(); - $this->allowedFields = [...$this->allowedFields, ...$this->getFields(), "user_uid"]; + parent::__construct('Board'); + $this->allowedFields = [ + ...$this->allowedFields, + "board_config_uid", + "user_uid", 'title', "content", + "passwd", "board_file", "view_cnt", "status" + ]; $this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),]; } public function getTitleField(): string @@ -23,30 +28,6 @@ class BoardModel extends BaseHierarchyModel { return 'content'; } - public function getFields(string $action = ""): array - { - $fields = ["board_config_uid", $this->getTitleField(), "board_file", "passwd", "status", "content"]; - switch ($action) { - case "index": - case "excel": - 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->getTitleField(), "board_file", "view_cnt", "status", "created_at", "content"]; - break; - default: - return $fields; - break; - } - } - public function getFieldFilters(): array - { - return ["board_config_uid", "user_uid", "status"]; - } - public function getFieldBatchFilters(): array - { - return parent::getFieldBatchFilters(); - } protected function getFieldRule(string $field, array $rules, string $action = ""): array { switch ($field) { @@ -69,7 +50,26 @@ class BoardModel extends BaseHierarchyModel } return $rules; } - + //Field별 Form Option용 + public function getFieldFormOption(string $field): array + { + switch ($field) { + case 'board_config_uid': + if (is_null($this->_boardconfig_options)) { + $boardConfigModel = new BoardConfigModel([$this->getPrimaryKey(), $this->getTitleField()]); + $this->_boardconfig_options = $boardConfigModel->getOptions(); + } + $options = $this->_boardconfig_options; + 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; + } public function getEntity($conditions): BoardEntity { return $this->where($conditions)->first() ?: throw new \Exception("해당 데이터가 없습니다.\n" . var_export($conditions, true)); diff --git a/app/Models/UserModel.php b/app/Models/UserModel.php index 3f4b76e..b9cfc12 100644 --- a/app/Models/UserModel.php +++ b/app/Models/UserModel.php @@ -9,41 +9,20 @@ class UserModel extends BaseModel protected $table = "tw_user"; protected $useAutoIncrement = false; protected $returnType = UserEntity::class; - protected $useSoftDeletes = false; + protected $useSoftDeletes = true; public function __construct() { - parent::__construct(); - $this->allowedFields = ["uid", ...$this->allowedFields, ...$this->getFields()]; + parent::__construct('User'); + $this->allowedFields = [ + ...$this->allowedFields, + "id", "passwd", 'name', "email", "role", "status" + ]; $this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),]; } public function getTitleField(): string { return 'name'; } - public function getFields(string $action = ""): array - { - $fields = ["id", "passwd", $this->getTitleField(), "email", "role", "status"]; - switch ($action) { - case "index": - case "excel": - return ["id", $this->getTitleField(), "email", "role", "status", 'created_at']; - break; - case "view": - return ["id", $this->getTitleField(), "email", "role", "status", 'updated_at', 'created_at']; - break; - default: - return $fields; - break; - } - } - public function getFieldFilters(): array - { - return ["role", "status"]; - } - public function getFieldBatchFilters(): array - { - return parent::getFieldBatchFilters(); - } protected function getFieldRule(string $field, array $rules, string $action = ""): array { switch ($field) { @@ -74,7 +53,7 @@ class UserModel extends BaseModel } public function getEntity($conditions): UserEntity { - return $this->where($conditions)->first() ?: throw new \Exception("해당 데이터가 없습니다.\n" . var_export($conditions, true)); + return parent::getEntity($conditions); } protected function changeFormData(string $action, string $field, array $formDatas, $entity) diff --git a/app/Models/UserSNSModel.php b/app/Models/UserSNSModel.php index c48c0f9..df81626 100644 --- a/app/Models/UserSNSModel.php +++ b/app/Models/UserSNSModel.php @@ -10,38 +10,18 @@ class UserSNSModel extends BaseModel protected $returnType = UserSNSEntity::class; public function __construct() { - parent::__construct(); - $this->allowedFields = [...$this->allowedFields, ...$this->getFields(), "user_uid"]; + parent::__construct('UserSNS'); + $this->allowedFields = [ + ...$this->allowedFields, + "site", "id", 'name', "email", "detail", "status" + ]; $this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),]; } public function getTitleField(): string { return 'name'; } - public function getFields(string $action = ""): array - { - $fields = ["site", "id", $this->getTitleField(), "email", "detail", "status"]; - switch ($action) { - case "index": - case "excel": - return ["user_uid", "site", "id", $this->getTitleField(), "email", "status", "created_at"]; - break; - case "view": - return [...$fields, "updated_at", "created_at"]; - break; - default: - return $fields; - break; - } - } - public function getFieldFilters(): array - { - return ["user_uid", "status"]; - } - public function getFieldBatchFilters(): array - { - return parent::getFieldBatchFilters(); - } + protected function getFieldRule(string $field, array $rules, string $action = ""): array { switch ($field) { @@ -69,7 +49,7 @@ class UserSNSModel extends BaseModel } public function getEntity($conditions): UserSNSEntity { - return $this->where($conditions)->first() ?: throw new \Exception("해당 데이터가 없습니다.\n" . var_export($conditions, true)); + return parent::getEntity($conditions); } public function create(array $formDatas): UserSNSEntity diff --git a/app/Views/admin/board/index.php b/app/Views/admin/board/index.php index ddb8991..0e4ec9b 100644 --- a/app/Views/admin/board/index.php +++ b/app/Views/admin/board/index.php @@ -24,7 +24,7 @@ = anchor(current_url() . '/update/' . $entity->getPrimaryKey(), $total_count - (($page - 1) * $per_page + $i), ["target" => "_self"]) ?> -
| + = $this->include($layout['path'] . '/left_menu'); ?> + | ++ = $this->include('templates/front/header'); ?> + = $this->renderSection('content') ?> + = $this->include('templates/front/footer'); ?> + = $this->include($layout['path'] . '/copyright'); ?> + | ++ = $this->include($layout['path'] . '/right_menu'); ?> + | +