servermgrv2 init...

This commit is contained in:
최준흠 2023-07-31 15:41:25 +09:00
parent 524c25fdd9
commit 0916bbcb43
32 changed files with 630 additions and 606 deletions

138
app/Backend/BaseBackend.php Normal file
View File

@ -0,0 +1,138 @@
<?php
namespace App\Backend;
use App\Models\UserModel;
use App\Entities\BaseEntity;
use CodeIgniter\HTTP\Files\UploadedFile;
abstract class BaseBackend
{
private $_userModel = null;
private $_className = null;
private $_user_uids = array();
protected $_model = null;
protected $_session = null;
protected function __construct(string $className)
{
$this->_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();
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace App\Backend;
abstract class BaseHierarchyBackend extends BaseBackend
{
public function __construct(string $className)
{
parent::__construct($className);
}
//ContentField
final public function getContentField()
{
return $this->_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);
}
}

View File

@ -0,0 +1,40 @@
<?php
namespace App\Backend;
use App\Models\BoardModel;
use App\Entities\BoardEntity;
use App\Models\BoardConfigModel;
class BoardBackend extends BaseHierarchyBackend
{
private $_board_config_uids = null;
private $_boardConfigModel = null;
public function __construct()
{
parent::__construct('Board');
$this->_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;
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace App\Backend;
use App\Models\BoardConfigModel;
use App\Entities\BoardConfigEntity;
class BoardConfigBackend extends BaseBackend
{
public function __construct()
{
parent::__construct('BoardConfig');
$this->_model = new BoardConfigModel();
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace App\Backend;
use App\Models\HPILOModel;
use App\Entities\HPILOEntity;
class HPILOBackend extends BaseBackend
{
public function __construct()
{
parent::__construct('HPILO');
$this->_model = new HPILOModel();
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace App\Backend;
use App\Models\UserModel;
use App\Entities\UserEntity;
class UserBackend extends BaseBackend
{
public function __construct()
{
parent::__construct('User');
$this->_model = new UserModel();
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace App\Backend;
use App\Models\UserSNSModel;
use App\Entities\UserSNSEntity;
class UserSNSBackend extends BaseBackend
{
public function __construct()
{
parent::__construct('UserSNS');
$this->_model = new UserSNSModel();
}
}

View File

@ -29,4 +29,39 @@ class Services extends BaseService
* return new \CodeIgniter\Example(); * 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();
}
} }

View File

@ -0,0 +1,67 @@
<?php
namespace Config;
use CodeIgniter\Config\BaseService;
/**
* Services Configuration file.
*
* Services are simply other classes/libraries that the system uses
* to do its job. This is used by CodeIgniter to allow the core of the
* framework to be swapped out easily without affecting the usage within
* the rest of your application.
*
* This file holds any application-specific services, or service overrides
* that you might need. An example has been included with the general
* method format you should use for your service methods. For more examples,
* see the core Services file at system/Config/Services.php.
*/
class Services extends BaseService
{
/*
* public static function example($getShared = true)
* {
* if ($getShared) {
* return static::getSharedInstance('example');
* }
*
* 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();
}
}

View File

@ -7,13 +7,12 @@ use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
abstract class AdminController extends BASEController abstract class AdminController extends BaseController
{ {
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->_viewPath .= strtolower('Admin/'); $this->_viewPath = 'admin/';
$this->_viewDatas['layout'] = LAYOUTS['admin']; $this->_viewDatas['layout'] = LAYOUTS['admin'];
$this->_viewDatas['title'] = "관리자페이지";
} }
} }

View File

@ -1,64 +0,0 @@
<?php
namespace App\Controllers\Admin;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
abstract class AdminHierarchyController extends AdminController
{
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
}
//Reply관련
protected function reply_form_process($entity)
{
return $this->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);
}
}
}

View File

@ -2,7 +2,6 @@
namespace App\Controllers\Admin; namespace App\Controllers\Admin;
use App\Models\BoardConfigModel;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@ -11,12 +10,8 @@ class BoardConfigController extends AdminController
{ {
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
$this->_backend = service('boardconfig');
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->_className .= 'BoardConfig'; $this->_viewPath .= strtolower($this->_backend->getClassName());
$this->_model = new BoardConfigModel();
helper($this->_className);
$this->_viewPath .= strtolower($this->_className);
$this->_viewDatas['title'] = lang($this->_className . '.title');
$this->_viewDatas['className'] = $this->_className;
} }
} }

View File

@ -2,48 +2,17 @@
namespace App\Controllers\Admin; namespace App\Controllers\Admin;
use App\Models\BoardConfigModel;
use App\Models\BoardModel;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface; 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) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
$this->_backend = service('board');
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->_className .= 'Board'; $this->_viewPath .= strtolower($this->_backend->getClassName());
$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 처리용 //Field별 Form Datas 처리용
@ -63,12 +32,4 @@ class BoardController extends AdminHierarchyController
} }
return $this->_viewDatas['fieldDatas']; return $this->_viewDatas['fieldDatas'];
} }
//View 관련
protected function view_process($entity)
{
// view_cnt에 추가하기위함
$this->_model->increaseViewCount($entity->getPrimaryKey());
return parent::view_process($entity);
}
} }

View File

@ -14,13 +14,9 @@ class HPILOController extends \App\Controllers\Admin\AdminController
private $_adapter = null; private $_adapter = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
$this->_backend = service('hpilo');
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->_className .= 'HPILO'; $this->_viewPath .= strtolower($this->_backend->getClassName());
$this->_model = new HPILOModel();
helper($this->_className);
$this->_viewPath .= strtolower($this->_className);
$this->_viewDatas['title'] = lang($this->_className . '.title');
$this->_viewDatas['className'] = $this->_className;
} }
private function getAdapter(HPILOEntity $entity) private function getAdapter(HPILOEntity $entity)

View File

@ -2,24 +2,19 @@
namespace App\Controllers\Admin; namespace App\Controllers\Admin;
use CodeIgniter\Controller;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
class Home extends AdminController class Home extends Controller
{ {
protected $_viewDatas = array();
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
helper('Common');
$this->_viewDatas = [
'layout' => LAYOUTS['admin'],
'title' => '관리자페이지',
];
} }
public function index() public function index()
{ {
return view($this->_viewPath . '/welcome_message', $this->_viewDatas); return view('admin/welcome_message');
} }
} }

View File

@ -2,7 +2,6 @@
namespace App\Controllers\Admin; namespace App\Controllers\Admin;
use App\Models\UserModel;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@ -11,13 +10,9 @@ class UserController extends AdminController
{ {
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
$this->_backend = service('user');
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->_className .= 'User'; $this->_viewPath .= strtolower($this->_backend->getClassName());
$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 처리용 //Field별 Form Datas 처리용

View File

@ -2,7 +2,6 @@
namespace App\Controllers\Admin; namespace App\Controllers\Admin;
use App\Models\UserSNSModel;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@ -11,12 +10,8 @@ class UserSNSController extends AdminController
{ {
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
$this->_backend = service('usersns');
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->_className .= 'UserSNS'; $this->_viewPath .= strtolower($this->_backend->getClassName());
$this->_model = new UserSNSModel();
helper($this->_className);
$this->_viewPath .= strtolower($this->_className);
$this->_viewDatas['title'] = lang($this->_className . '.title');
$this->_viewDatas['className'] = $this->_className;
} }
} }

View File

@ -6,15 +6,15 @@ use App\Libraries\Adapter\Auth\Adapter;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use App\Models\UserModel;
class AuthController extends BaseController class AuthController extends BaseController
{ {
private $_adapters = array(); private $_adapters = array();
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
$this->_backend = service('user');
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
helper('Common'); $this->_viewPath .= strtolower($this->_backend->getClassName());
$this->initAdapters(); $this->initAdapters();
} }

View File

@ -10,8 +10,6 @@ use CodeIgniter\HTTP\IncomingRequest;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use App\Models\UserModel;
use App\Entities\BaseEntity;
/** /**
* Class BaseController * Class BaseController
@ -50,62 +48,21 @@ abstract class BaseController extends Controller
/** /**
* Constructor. * Constructor.
*/ */
private $_userModel = null; protected $_backend = null;
private $_user_uids = array();
protected $_model = null;
protected $_className = '/';
protected $_viewPath = '/';
protected $_viewDatas = array();
protected $_session = null; protected $_session = null;
protected $_viewPath = '';
protected $_viewDatas = array();
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
// Do Not Edit This Line // Do Not Edit This Line
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
// Preload any models, libraries, etc, here. // Preload any models, libraries, etc, here.
// E.g.: $this->session = \Config\Services::session(); // E.g.: $this->session = \Config\Services::session();
$this->_session = \Config\Services::session(); $this->_session = \Config\Services::session();
$this->_viewDatas = [ $this->_viewDatas['layout'] = LAYOUTS['empty'];
'layout' => LAYOUTS['empty'], $this->_viewDatas['title'] = lang($this->_backend->getClassName() . '.title');
'title' => '', $this->_viewDatas['session'] = $this->_session;
'session' => $this->_session helper($this->_backend->getClassName());
];
}
//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;
} }
//Field별 Form Datas 처리용 //Field별 Form Datas 처리용
@ -153,14 +110,31 @@ abstract class BaseController extends Controller
return $fileNames; 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관련 //Insert관련
final public function insert_form() final public function insert_form()
{ {
try { try {
$this->_viewDatas['fields'] = $this->_model->getFields('insert'); $this->_viewDatas = $this->init(__FUNCTION__);
$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['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []]; $this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []];
helper(['form']); helper(['form']);
$this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']); $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()); return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']))->with('return_message', $e->getMessage());
} }
} }
protected function insert_process()
protected function insert_validate()
{ {
$this->_viewDatas['fieldDatas'] = array(); //fieldData Rule 검사
//변경할 값 확인
if (!$this->validate($this->_viewDatas['fieldRules'])) { if (!$this->validate($this->_viewDatas['fieldRules'])) {
throw new \Exception("{$this->_viewDatas['title']}의 검증 오류발생\n" . implode("\n", $this->validator->getErrors())); throw new \Exception("{$this->_viewDatas['title']}의 검증 오류발생\n" . implode("\n", $this->validator->getErrors()));
} }
//변경된 값 적용 //fieldData 적용
$this->_viewDatas['fieldDatas'] = array();
foreach ($this->_viewDatas['fields'] as $field) { foreach ($this->_viewDatas['fields'] as $field) {
$this->_viewDatas['fieldDatas'] = $this->getFieldFormData($field); $this->_viewDatas['fieldDatas'] = $this->getFieldFormData($field);
} }
// echo var_export($this->_viewDatas['fields'], true);
// echo "<HR>";
// echo var_export($this->_viewDatas['fieldDatas'], true);
// echo "<HR>";
// echo var_export($this->_viewDatas['fieldRules'], true);
// exit;
}
protected function insert_process(): BaseEntity
{
return $this->_model->create($this->_viewDatas['fieldDatas']);
} }
public function insert() public function insert()
{ {
$msg = ""; $msg = "";
try { try {
$this->_viewDatas['fields'] = $this->_model->getFields('insert'); $this->_viewDatas = $this->init(__FUNCTION__);
$this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'insert'); $this->insert_process();
$this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters(); $entity = $this->_backend->insert($this->_viewDatas['fieldDatas']);
$this->insert_validate();
$entity = $this->insert_process();
$msg = "{$this->_viewDatas['title']}에서 {$entity->getTitle()}" . __FUNCTION__ . " 완료하였습니다."; $msg = "{$this->_viewDatas['title']}에서 {$entity->getTitle()}" . __FUNCTION__ . " 완료하였습니다.";
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']));
} catch (\Exception $e) { } catch (\Exception $e) {
$msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage(); $msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage();
log_message("error", $e->getMessage()); log_message("error", $e->getMessage());
log_message("error", var_export($this->_viewDatas['fieldDatas'], true));
return redirect()->back()->withInput(); return redirect()->back()->withInput();
} finally { } finally {
$this->_session->setFlashdata("return_message", $msg); $this->_session->setFlashdata("return_message", $msg);
@ -214,118 +174,132 @@ abstract class BaseController extends Controller
} }
//Update관련 //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) final public function update_form($uid)
{ {
try { try {
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); $this->_viewDatas = $this->init(__FUNCTION__);
$this->_viewDatas['fields'] = $this->_model->getFields('update'); $this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []];
$this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'update'); helper(['form']);
$this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters();
$this->_viewDatas['entity'] = $this->update_form_process($entity);
$this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']); $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) { } catch (\Exception $e) {
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']))->with('return_message', $e->getMessage()); return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']))->with('return_message', $e->getMessage());
} }
} }
protected function update_validate($entity) protected function update_process()
{ {
//변경된 값 적용 //fieldData Rule 검사
$this->_viewDatas['fieldDatas'] = array();
//변경할 값 확인
if (!$this->validate($this->_viewDatas['fieldRules'])) { if (!$this->validate($this->_viewDatas['fieldRules'])) {
throw new \Exception("{$this->_viewDatas['title']}의 검증 오류발생\n" . implode("\n", $this->validator->getErrors())); throw new \Exception("{$this->_viewDatas['title']}의 검증 오류발생\n" . implode("\n", $this->validator->getErrors()));
} }
//fieldData 적용
$this->_viewDatas['fieldDatas'] = array();
foreach ($this->_viewDatas['fields'] as $field) { foreach ($this->_viewDatas['fields'] as $field) {
$this->_viewDatas['fieldDatas'] = $this->getFieldFormData($field, $entity); $this->_viewDatas['fieldDatas'] = $this->getFieldFormData($field, $this->_viewDatas['entity']);
log_message( log_message(
"info", "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) public function update($uid)
{ {
$msg = ""; $msg = "";
try { try {
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); $this->_viewDatas = $this->init(__FUNCTION__);
$this->_viewDatas['fields'] = $this->_model->getFields('update'); $entity = $this->_viewDatas['entity'] = $this->_backend->getEntity($uid);
$this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'update'); $this->update_process();
$this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters(); $entity = $this->_backend->update($entity, $this->_viewDatas['fieldDatas']);
$entity = $this->update_validate($entity); $msg = "{$this->_viewDatas['title']}에서 {$entity->getTitle()}" . __FUNCTION__ . " 완료하였습니다.";
$entity = $this->update_process($entity);
$msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 완료하였습니다.";
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']));
} catch (\Exception $e) { } catch (\Exception $e) {
$msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage(); $msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage();
log_message("error", $e->getMessage()); log_message("error", $e->getMessage());
log_message("error", var_export($this->_viewDatas['fieldDatas'], true));
return redirect()->back()->withInput(); return redirect()->back()->withInput();
} finally { } finally {
$this->_session->setFlashdata("return_message", $msg); $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 관련 //Toggle 관련
protected function toggle_validate($entity) protected function toggle_process()
{ {
return $this->update_validate($entity); $this->update_process();
}
protected function toggle_process($entity)
{
return $this->update_process($entity);
} }
public function toggle($uid, string $field) public function toggle($uid, string $field)
{ {
$msg = ""; $msg = "";
try { try {
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); $this->_viewDatas = $this->init(__FUNCTION__, [$field]);
$this->_viewDatas['fields'] = [$field]; $entity = $this->_viewDatas['entity'] = $this->_backend->getEntity($uid);
$this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'toggle'); $this->toggle_process();
$this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters(); $entity = $this->_backend->update($entity, $this->_viewDatas['fieldDatas']);
$entity = $this->toggle_validate($entity); $msg = "{$this->_viewDatas['title']}에서 {$entity->getTitle()}" . __FUNCTION__ . " 완료하였습니다.";
$entity = $this->toggle_process($entity);
$msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 완료하였습니다.";
} catch (\Exception $e) { } catch (\Exception $e) {
$msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage(); $msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage();
log_message("error", $e->getMessage()); log_message("error", $e->getMessage());
log_message("error", var_export($this->_viewDatas['fieldDatas'], true));
} finally { } finally {
$this->_session->setFlashdata("return_message", $msg); $this->_session->setFlashdata("return_message", $msg);
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']));
} }
} }
//Batchjob 관련 //Batchjob 관련
protected function batchjob_validate($entity) protected function batchjob_process()
{ {
return $this->update_validate($entity); $this->update_process();
}
protected function batchjob_process($entity)
{
return $this->update_process($entity);
} }
public function batchjob() public function batchjob()
{ {
$msg = ""; $msg = "";
$entitys = array();
$batchjobs = array(); $batchjobs = array();
try { try {
$uids = $this->request->getVar('batchjob_uids') ?: throw new \Exception($this->_viewDatas['title'] . '에서 변경할 항목(uid)이 선택되지 않았습니다.');
//fields 해당하는 field중 선택된 값이 있는경우만 fields로 정의 //fields 해당하는 field중 선택된 값이 있는경우만 fields로 정의
$fields = array(); $fields = array();
foreach ($this->_model->getFieldBatchFilters() as $field) { foreach ($this->_backend->getFieldBatchFilters() as $field) {
if ($this->request->getVar($field)) { if ($this->request->getVar($field)) {
array_push($fields, $field); array_push($fields, $field);
} }
@ -333,41 +307,43 @@ abstract class BaseController extends Controller
if (!is_array($fields) || count($fields) === 0) { if (!is_array($fields) || count($fields) === 0) {
throw new \Exception($this->_viewDatas['title'] . '에서 변경할 항목(field)이 선택되지 않았습니다.'); throw new \Exception($this->_viewDatas['title'] . '에서 변경할 항목(field)이 선택되지 않았습니다.');
} }
//Transaction manully 시작 $this->_viewDatas = $this->init(__FUNCTION__, $fields);
$this->_model->transBegin(); $uids = $this->request->getVar('batchjob_uids') ?: throw new \Exception($this->_viewDatas['title'] . '에서 변경할 항목(uid)이 선택되지 않았습니다.');
//Fields,FielRules재정의
$this->_viewDatas['fields'] = $fields;
$this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'batchjob');
$this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters();
$cnt = 1; $cnt = 1;
$entitys = array(); //Transaction manully 시작
$this->_backend->transBegin();
foreach ($uids as $uid) { foreach ($uids as $uid) {
try { try {
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); $entity = $this->_viewDatas['entity'] = $this->_backend->getEntity($uid);
$entity = $this->batchjob_validate($entity); $this->batchjob_process();
array_push($entitys, $this->batchjob_process($entity)); array_push($entitys, $this->_backend->update($entity, $this->_viewDatas['fieldDatas']));
array_push($batchjobs, "{$cnt}. {$entity->getTitle()}는 완료."); array_push($batchjobs, "{$cnt}. {$uid}->{$entity->getTitle()}는 완료.");
} catch (\Exception $e) { } catch (\Exception $e) {
array_push($batchjobs, "{$cnt}. {$entity->getTitle()}는 실패\n" . $e->getMessage()); array_push($batchjobs, "{$cnt}. {$uid}는 실패.");
} }
$cnt++; $cnt++;
} }
//Transaction manully Commit //Transaction manully Commit
$this->_model->transCommit(); $this->_backend->transCommit();
$msg = sprintf( $msg = sprintf(
"%s에서 총:%s중 %s개성공 , %s실패 %s 완료하였습니다.", "%s에서 총:%s개의 %s 완료하였습니다.",
$this->_viewDatas['title'], $this->_viewDatas['title'],
count($batchjobs),
count($entitys), count($entitys),
count($batchjobs) - count($entitys),
__FUNCTION__ __FUNCTION__
); );
} catch (\Exception $e) { } catch (\Exception $e) {
//Transaction manully Rollback //Transaction manully Rollback
$this->_model->transRollback(); $this->_backend->transRollback();
$msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage(); 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", $e->getMessage());
log_message("error", var_export($this->_viewDatas['fieldDatas'], true));
} finally { } finally {
$this->_session->setFlashdata("return_message", $msg); $this->_session->setFlashdata("return_message", $msg);
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']));
@ -375,26 +351,15 @@ abstract class BaseController extends Controller
} }
//Delete 관련 //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) public function delete($uid)
{ {
$msg = ""; $msg = "";
try { try {
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); $entity = $this->_backend->delete($this->_backend->getEntity($uid));
$this->delete_process($entity); $msg = "{$this->_viewDatas['title']}에서 {$entity->getTitle()}" . __FUNCTION__ . " 완료하였습니다.";
$msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 완료하였습니다.";
} catch (\Exception $e) { } catch (\Exception $e) {
$msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage(); $msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage();
log_message("error", $e->getMessage()); log_message("error", $e->getMessage());
log_message("error", var_export($this->_viewDatas['fieldDatas'], true));
} finally { } finally {
$this->_session->setFlashdata("return_message", $msg); $this->_session->setFlashdata("return_message", $msg);
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL'])); return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']));
@ -409,16 +374,11 @@ abstract class BaseController extends Controller
public function view($uid) public function view($uid)
{ {
try { try {
// echo "TEST" . $this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']); $this->_viewDatas = $this->init(__FUNCTION__);
// 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();
helper(['form']); helper(['form']);
$this->_viewDatas['fieldFormOptions'] = $this->getFieldFormOptions($this->_viewDatas['fieldFilters']);
$this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []]; $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']); $this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']);
return view($this->_viewPath . '/view', $this->_viewDatas); return view($this->_viewPath . '/view', $this->_viewDatas);
} catch (\Exception $e) { } catch (\Exception $e) {
@ -427,46 +387,13 @@ abstract class BaseController extends Controller
} }
//Index 관련 //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 private function index_getPagination($pager_group = 'default', int $segment = 0, $template = 'bootstrap_full'): string
{ {
// 1.Views/Pagers/에 bootstrap_full.php,bootstrap_simple.php 생성 // 1.Views/Pagers/에 bootstrap_full.php,bootstrap_simple.php 생성
// 2.app/Config/Pager.php/$templates에 'bootstrap_full => 'Pagers\bootstrap_full', // 2.app/Config/Pager.php/$templates에 'bootstrap_full => 'Pagers\bootstrap_full',
// 'bootstrap_simple' => 'Pagers\bootstrap_simple', 추가 // 'bootstrap_simple' => 'Pagers\bootstrap_simple', 추가
$pager = \Config\Services::pager(); $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( $pager->makeLinks(
$this->_viewDatas['page'], $this->_viewDatas['page'],
$this->_viewDatas['per_page'], $this->_viewDatas['per_page'],
@ -479,27 +406,32 @@ abstract class BaseController extends Controller
$this->_viewDatas['total_page'] = $pager->getPageCount($pager_group); $this->_viewDatas['total_page'] = $pager->getPageCount($pager_group);
return $pager->links($pager_group, $template); 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']); $filterFields = array();
//줄수 처리용 foreach ($this->_viewDatas['fieldFilters'] as $field) {
$this->_viewDatas['pageOptions'] = array("" => "줄수선택"); if (!is_null($this->request->getVar($field))) {
for ($i = 10; $i <= $this->_viewDatas['total_count'] + $this->_viewDatas['per_page']; $i += 10) { $filterFields[$field] = $this->request->getVar($field);
$this->_viewDatas['pageOptions'][$i] = $i; }
} }
//pagenation 처리 $word = $this->request->getVar('word');
$this->_viewDatas['pagination'] = $this->index_getPagination(); $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() public function index()
{ {
try { try {
$this->_viewDatas['fields'] = $this->_model->getFields('index'); $this->_viewDatas = $this->init(__FUNCTION__);
$this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'index');
$this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters();
$this->_viewDatas['batchjobFilters'] = $this->_model->getFieldBatchFilters();
helper(['form']); helper(['form']);
$this->_viewDatas['fieldFormOptions'] = $this->getFieldFormOptions($this->_viewDatas['fieldFilters']);
$this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []]; $this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []];
foreach ($this->_viewDatas['fieldFilters'] as $field) { foreach ($this->_viewDatas['fieldFilters'] as $field) {
$this->_viewDatas[$field] = $this->request->getVar($field) ?: DEFAULTS['EMPTY']; $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['page'] = $this->request->getVar('page') ?: 1;
$this->_viewDatas['per_page'] = $this->request->getVar('per_page') ?: DEFAULTS['PERPAGE']; $this->_viewDatas['per_page'] = $this->request->getVar('per_page') ?: DEFAULTS['PERPAGE'];
$this->_viewDatas['uri'] = $this->request->getUri(); $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 //setting return_url to session flashdata
$this->_session->setFlashdata(SESSION_NAMES['RETURN_URL'], current_url() . '?' . $this->request->getUri()->getQuery() ?: ""); $this->_session->setFlashdata(SESSION_NAMES['RETURN_URL'], current_url() . '?' . $this->request->getUri()->getQuery() ?: "");
// echo "TEST" . var_export($this->_session->get());
// echo "<HR>";
// echo $this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']);
// exit;
return view($this->_viewPath . '/index', $this->_viewDatas); return view($this->_viewPath . '/index', $this->_viewDatas);
} catch (\Exception $e) { } catch (\Exception $e) {
return redirect()->back()->with('return_message', $e->getMessage()); return redirect()->back()->with('return_message', $e->getMessage());
@ -526,22 +466,22 @@ abstract class BaseController extends Controller
} }
//Excel 관련 //Excel 관련
protected function excel_spreadSheet() private function excel_spreadSheet(array $viewDatas)
{ {
//Excepl 초기화 //Excepl 초기화
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$sheet = $spreadsheet->getActiveSheet(); $sheet = $spreadsheet->getActiveSheet();
//Header용 //Header용
$column = 'A'; $column = 'A';
foreach ($this->_viewDatas['fields'] as $field) { foreach ($viewDatas['fields'] as $field) {
$sheet->setCellValue($column++ . '1', lang($this->_className . '.label.' . $field)); $sheet->setCellValue($column++ . '1', lang($this->_backend->getClassName() . '.label.' . $field));
} }
//본문용 //본문용
$line = 2; $line = 2;
foreach ($this->index_getEntitys() as $entity) { foreach ($this->index_getEntitys() as $entity) {
$column = 'A'; $column = 'A';
foreach ($this->_viewDatas['fields'] as $field) { foreach ($viewDatas['fields'] as $field) {
$value = in_array($field, $this->_viewDatas['fieldFilters']) ? $this->_viewDatas['fieldFormOptions'][$field][$entity->$field] : $entity->$field; $value = in_array($field, $viewDatas['fieldFilters']) ? $viewDatas['fieldFormOptions'][$field][$entity->$field] : $entity->$field;
$sheet->setCellValue($column . $line, $value); $sheet->setCellValue($column . $line, $value);
$column++; $column++;
} }
@ -549,32 +489,24 @@ abstract class BaseController extends Controller
} }
return $spreadsheet; 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() public function excel()
{ {
try { try {
$this->_viewDatas['fields'] = $this->_model->getFields('excel'); $this->_viewDatas = $this->init(__FUNCTION__);
$this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'excel'); $fileName = date('Y-m-d_Hm') . '.xlsx';
$this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters(); $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($this->excel_spreadSheet($this->_viewDatas), 'Xlsx');
$this->_viewDatas['batchjobFilters'] = $this->_model->getFieldBatchFilters(); //결과파일저장
$this->_viewDatas['fieldFormOptions'] = $this->getFieldFormOptions($this->_viewDatas['fieldFilters']); $writer->save(PATHS['EXCEL'] . '/' . $fileName);
return $this->excel_process(); //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) { } catch (\Exception $e) {
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']))->with('return_message', $e->getMessage()); 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) final public function download(string $field, $uid)
{ {
try { try {
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); $entity = $this->_backend->getEntity([$this->_backend->getPrimaryKey() => $uid]);
if (!$entity->$field) { if (!$entity->$field) {
throw new \Exception("첨부파일이 확인되지 않습니다."); throw new \Exception("첨부파일이 확인되지 않습니다.");
} }

View File

@ -1,74 +0,0 @@
<?php
namespace App\Controllers\Front;
use App\Models\BoardConfigModel;
use App\Models\BoardModel;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
class BoardController extends FrontHierarchyController
{
private $_boardConfigModel = null;
private $_board_config_uids = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
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;
}
//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);
}
}

View File

@ -7,7 +7,7 @@ use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
class FrontController extends BASEController class FrontController extends BaseController
{ {
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {

View File

@ -1,63 +0,0 @@
<?php
namespace App\Controllers\Front;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
abstract class FrontHierarchyController extends FrontController
{
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
}
//Reply관련
protected function reply_form_process($entity)
{
return $this->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 . "<br>\n{$e->getMessage()}");
}
}
}

View File

@ -1,37 +0,0 @@
<?php
namespace App\Controllers\Front;
use App\Models\UserModel;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
class UserController extends FrontController
{
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
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;
}
//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'];
}
}

View File

@ -2,8 +2,17 @@
namespace App\Controllers; 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() public function index()
{ {
return view('welcome_message'); return view('welcome_message');

View File

@ -11,8 +11,10 @@ abstract class BaseHierarchyModel extends BaseModel
{ {
parent::__construct(); parent::__construct();
$this->allowedFields = [...$this->allowedFields, "grpno", "grporder", "grpdepth"]; $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 protected function getFieldRule(string $field, array $rules, string $action = ""): array
{ {
switch ($field) { switch ($field) {
@ -30,24 +32,24 @@ abstract class BaseHierarchyModel extends BaseModel
final protected function create_process($entity, array $formDatas) final protected function create_process($entity, array $formDatas)
{ {
$entity = parent::create_process($entity, $formDatas); //생성시는 grpno의 max값을 구해서 넣는다.
//생성시는 grpno가 primarykey와 같고 숫자여야함 $entity->grpno = $this->selectMax("grpno")->get()->getResult()[0]->grpno + 1;
$this->builder()->set("grpno", $entity->getPrimaryKey()); if (!$entity->grpno) {
$this->builder()->where($this->primaryKey, $entity->getPrimaryKey()); throw new \Exception("grpno는 {$entity->grpno}의 값을 가질수 없습니다.");
$this->builder()->update(); }
return $entity; return parent::create_process($entity, $formDatas);
} }
final protected function reply_process($parent_entity, $entity, array $formDatas) final protected function reply_process($parent_entity, $entity, array $formDatas)
{ {
//부모의 그룹과 grpno가 같고, 부모의 grporder보다 1 큰것을 grporder+1을 해서 update //부모의 그룹과 grpno가 같고, 부모의 grporder보다 1 큰것을 grporder+1을 해서 update
//escape -> false옵션 반드시 있어야함 //escape -> false옵션 반드시 있어야함
$this->builder()->set("grporder", "grporder+1", false); $this->set("grporder", "grporder+1", false);
$this->builder()->where([ $this->where([
"grpno" => $parent_entity->grpno, "grpno" => $parent_entity->grpno,
"grporder >" => $parent_entity->grporder "grporder >" => $parent_entity->grporder
]); ]);
$this->builder()->update(); $this->update();
//reply용 설정 //reply용 설정
$entity->grpno = $parent_entity->grpno; $entity->grpno = $parent_entity->grpno;
$entity->grporder = $parent_entity->grporder + 1; $entity->grporder = $parent_entity->grporder + 1;

View File

@ -55,7 +55,7 @@ abstract class BaseModel extends Model
{ {
return $this->primaryKey; return $this->primaryKey;
} }
abstract public function getTitle(): string; abstract public function getTitleField(): string;
abstract public function getEntity($uid): BaseEntity; abstract public function getEntity($uid): BaseEntity;
abstract public function getFieldFilters(): array; abstract public function getFieldFilters(): array;
abstract public function getFields(string $action): array; abstract public function getFields(string $action): array;
@ -183,6 +183,8 @@ abstract class BaseModel extends Model
private function save_process($entity) private function save_process($entity)
{ {
// echo var_export($entity, true);
// exit;
if ($entity->hasChanged()) { if ($entity->hasChanged()) {
if (!$this->save($entity)) { if (!$this->save($entity)) {
log_message("error", __FUNCTION__ . "에서 호출:" . $this->getLastQuery()); log_message("error", __FUNCTION__ . "에서 호출:" . $this->getLastQuery());

View File

@ -15,21 +15,21 @@ class BoardConfigModel extends BaseModel
$this->allowedFields = [...$this->allowedFields, ...$this->getFields()]; $this->allowedFields = [...$this->allowedFields, ...$this->getFields()];
$this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),]; $this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),];
} }
public function getTitle(): string public function getTitleField(): string
{ {
return 'name'; return 'name';
} }
public function getFields(string $action = ""): array public function getFields(string $action = ""): array
{ {
$fields = [ $fields = [
$this->getTitle(), "isaccess", "isread", "iswrite", "isreply", "isupload", "isdownload", $this->getTitleField(), "isaccess", "isread", "iswrite", "isreply", "isupload", "isdownload",
"status", "head", "tail", "status", "head", "tail",
]; ];
switch ($action) { switch ($action) {
case "index": case "index":
case "excel": case "excel":
return [ return [
$this->getTitle(), "isaccess", "isread", "iswrite", "isreply", "isupload", "isdownload", $this->getTitleField(), "isaccess", "isread", "iswrite", "isreply", "isupload", "isdownload",
"status", "created_at" "status", "created_at"
]; ];
break; 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] = "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}]" : ""; $rules[$field] .= $action == "insert" ? "|is_unique[{$this->table}.{$field}]" : "";
break; break;
case $this->getTitle(): case $this->getTitleField():
$rules[$field] = "required|trim|string"; $rules[$field] = "required|trim|string";
$rules[$field] .= $action == "insert" ? "|is_unique[{$this->table}.{$field}]" : ""; $rules[$field] .= $action == "insert" ? "|is_unique[{$this->table}.{$field}]" : "";
break; break;

View File

@ -15,20 +15,24 @@ class BoardModel extends BaseHierarchyModel
$this->allowedFields = [...$this->allowedFields, ...$this->getFields(), "user_uid"]; $this->allowedFields = [...$this->allowedFields, ...$this->getFields(), "user_uid"];
$this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),]; $this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),];
} }
public function getTitle(): string public function getTitleField(): string
{ {
return 'title'; return 'title';
} }
public function getContentField(): string
{
return 'content';
}
public function getFields(string $action = ""): array 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) { switch ($action) {
case "index": case "index":
case "excel": 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; break;
case "view": 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; break;
default: default:
return $fields; return $fields;
@ -49,7 +53,7 @@ class BoardModel extends BaseHierarchyModel
case "board_config_uid": 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}/]"; $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; break;
case $this->getTitle(): case $this->getTitleField():
case "content": case "content":
$rules[$field] = "required|string"; $rules[$field] = "required|string";
break; break;
@ -88,7 +92,7 @@ class BoardModel extends BaseHierarchyModel
public function setIndexWordFilter(string $word) public function setIndexWordFilter(string $word)
{ {
parent::setIndexWordFilter($word); parent::setIndexWordFilter($word);
$this->orLike($this->getTitle(), $word, "both"); $this->orLike($this->getTitleField(), $word, "both");
$this->orLike("content", $word, "both"); //befor , after , both $this->orLike("content", $word, "both"); //befor , after , both
} }
} }

View File

@ -16,20 +16,20 @@ class UserModel extends BaseModel
$this->allowedFields = ["uid", ...$this->allowedFields, ...$this->getFields()]; $this->allowedFields = ["uid", ...$this->allowedFields, ...$this->getFields()];
$this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),]; $this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),];
} }
public function getTitle(): string public function getTitleField(): string
{ {
return 'name'; return 'name';
} }
public function getFields(string $action = ""): array public function getFields(string $action = ""): array
{ {
$fields = ["id", "passwd", $this->getTitle(), "email", "role", "status"]; $fields = ["id", "passwd", $this->getTitleField(), "email", "role", "status"];
switch ($action) { switch ($action) {
case "index": case "index":
case "excel": case "excel":
return ["id", $this->getTitle(), "email", "role", "status", 'created_at']; return ["id", $this->getTitleField(), "email", "role", "status", 'created_at'];
break; break;
case "view": 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; break;
default: default:
return $fields; return $fields;
@ -57,7 +57,7 @@ class UserModel extends BaseModel
$rules["confirmpassword"] = "required|trim|string|matches[passwd]"; $rules["confirmpassword"] = "required|trim|string|matches[passwd]";
} }
break; break;
case $this->getTitle(): case $this->getTitleField():
$rules[$field] = "required|trim|string"; $rules[$field] = "required|trim|string";
break; break;
case "email": case "email":
@ -105,6 +105,6 @@ class UserModel extends BaseModel
{ {
parent::setIndexWordFilter($word); parent::setIndexWordFilter($word);
$this->orLike("id", $word, "both"); $this->orLike("id", $word, "both");
$this->orLike($this->getTitle(), $word, "both"); //befor , after , both $this->orLike($this->getTitleField(), $word, "both"); //befor , after , both
} }
} }

View File

@ -14,17 +14,17 @@ class UserSNSModel extends BaseModel
$this->allowedFields = [...$this->allowedFields, ...$this->getFields(), "user_uid"]; $this->allowedFields = [...$this->allowedFields, ...$this->getFields(), "user_uid"];
$this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),]; $this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),];
} }
public function getTitle(): string public function getTitleField(): string
{ {
return 'name'; return 'name';
} }
public function getFields(string $action = ""): array public function getFields(string $action = ""): array
{ {
$fields = ["site", "id", $this->getTitle(), "email", "detail", "status"]; $fields = ["site", "id", $this->getTitleField(), "email", "detail", "status"];
switch ($action) { switch ($action) {
case "index": case "index":
case "excel": 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; break;
case "view": case "view":
return [...$fields, "updated_at", "created_at"]; return [...$fields, "updated_at", "created_at"];
@ -49,7 +49,7 @@ class UserSNSModel extends BaseModel
$rules[$field] = "required|trim|string"; $rules[$field] = "required|trim|string";
$rules[$field] .= $action == "insert" ? "|is_unique[{$this->table}.{$field}]" : ""; $rules[$field] .= $action == "insert" ? "|is_unique[{$this->table}.{$field}]" : "";
break; break;
case $this->getTitle(): case $this->getTitleField():
$rules[$field] = "required|trim|string"; $rules[$field] = "required|trim|string";
break; break;
case "email": case "email":
@ -85,7 +85,7 @@ class UserSNSModel extends BaseModel
public function setIndexWordFilter(string $word) public function setIndexWordFilter(string $word)
{ {
parent::setIndexWordFilter($word); parent::setIndexWordFilter($word);
$this->orLike($this->getTitle(), $word, "both"); $this->orLike($this->getTitleField(), $word, "both");
$this->orLike("email", $word, "both"); //befor , after , both $this->orLike("email", $word, "both"); //befor , after , both
} }
} }

View File

@ -4,7 +4,6 @@
<?= form_open_multipart(current_url(), $forms['attributes'], $forms['hiddens']) ?> <?= form_open_multipart(current_url(), $forms['attributes'], $forms['hiddens']) ?>
<table class="form table table-bordered table-hover table-striped"> <table class="form table table-bordered table-hover table-striped">
<?php foreach ($fields as $field) : ?> <?php foreach ($fields as $field) : ?>
<?= csrf_field() ?>
<tr> <tr>
<td class="label"><?= getFieldLabel_BoardHelper($field, $fieldRules) ?></td> <td class="label"><?= getFieldLabel_BoardHelper($field, $fieldRules) ?></td>
<td class="column"> <td class="column">

View File

@ -0,0 +1,10 @@
<!-- left menu start -->
<link href="/css/admin/left_menu.css" media="screen" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/js/side_menu.js"></script>
<div id="left_menu" class="shadow-lg rounded">
<div class="accordion accordion-flush">
<?= $this->include($layout['path'] . '/left_menu/base'); ?>
<?= $this->include($layout['path'] . '/left_menu/board'); ?>
<?= $this->include($layout['path'] . '/left_menu/hpilo'); ?>
</div>
</div>