servermgrv2 init...

This commit is contained in:
최준흠git config git config --helpgit config --global user.name 최준흠 2023-08-05 12:47:14 +09:00
parent b225b22628
commit fe170ead70
5 changed files with 94 additions and 81 deletions

View File

@ -46,4 +46,40 @@ class CategoryController extends AdminController
{ {
return parent::getFieldBatchFilters(); return parent::getFieldBatchFilters();
} }
// private function build_leftmenu()
// {
// $categorys = $this->_model->getEntitys(['status' => DEFAULTS['STATUS']]);
// $leftmenu = view($this->_viewPath . '/leftmenu', ['categorys' => $categorys]);
// file_put_contents(APPPATH . 'Views' . '/layouts/front/left_menu/leftmenu.php', $leftmenu);
// }
// //Insert관련
// protected function insert_process()
// {
// $entity = parent::insert_process();
// $this->build_leftmenu();
// return $entity;
// }
// //Update관련
// protected function update_process($entity)
// {
// $entity = parent::update_process($entity);
// $this->build_leftmenu();
// return $entity;
// }
// //Reply관련
// protected function reply_process($entity)
// {
// $entity = parent::reply_process($entity);
// $this->build_leftmenu();
// return $entity;
// }
// //Delete 관련
// protected function delete_process($entity)
// {
// $entity = parent::delete_process($entity);
// $this->build_leftmenu();
// return $entity;
// }
} }

View File

@ -3,15 +3,13 @@
namespace App\Controllers\Front; namespace App\Controllers\Front;
use App\Models\BoardModel; use App\Models\BoardModel;
use App\Models\CategoryModel;
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 FrontController class BoardController extends FrontController
{ {
private $_category = null;
private $_categoryModel = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
$this->_model = new BoardModel($this->getFields()); $this->_model = new BoardModel($this->getFields());
@ -19,11 +17,6 @@ class BoardController extends FrontController
$this->_viewPath .= strtolower($this->_model->getClassName()); $this->_viewPath .= strtolower($this->_model->getClassName());
} }
private function getCategoryModel(): CategoryModel
{
return $this->_categoryModel = $this->_categoryModel ?: new CategoryModel();
}
public function getFields(string $action = ""): array public function getFields(string $action = ""): array
{ {
$fields = ['title', "board_file", "passwd", "content"]; $fields = ['title', "board_file", "passwd", "content"];
@ -69,31 +62,15 @@ class BoardController extends FrontController
//Insert관련 //Insert관련
protected function insert_form_process() protected function insert_form_process()
{ {
$this->_category = $this->request->getVar('category') ?: throw new \Exception("범주를 지정하지 않으셨습니다."); //권한체크
$this->_viewDatas['category'] = $this->getCategoryModel()->getEntity([$this->getCategoryModel()->getPrimaryKey() => $this->_category]); $this->isRole('insert');
//사용자가 Category에서 해당 게시판의 WRITE권한이 있는지 확인 return parent::insert_form_process();
if (!isRole_CommonHelper(
$this->_viewDatas['currentRoles'],
$this->_viewDatas['category'],
CATEGORY_ROLE_FIELDS['WRITE']
)) {
throw new \Exception("고객님은 쓰기권한이 없습니다.");
}
return parent::insert_form();
} }
protected function insert_process() protected function insert_process()
{ {
$this->_category = $this->request->getVar('category') ?: throw new \Exception("범주를 지정하지 않으셨습니다."); //권한체크
$this->_viewDatas['category'] = $this->getCategoryModel()->getEntity([$this->getCategoryModel()->getPrimaryKey() => $this->_category]); $this->isRole('insert');
//사용자가 Category에서 해당 게시판의 WRITE권한이 있는지 확인 return parent::insert_process();
if (!isRole_CommonHelper(
$this->_viewDatas['currentRoles'],
$this->_viewDatas['category'],
CATEGORY_ROLE_FIELDS['WRITE']
)) {
throw new \Exception("고객님은 쓰기권한이 없습니다.");
}
return parent::insert();
} }
//Update관련 //Update관련
@ -116,38 +93,14 @@ class BoardController extends FrontController
//Reply관련 //Reply관련
protected function reply_form_process($entity) protected function reply_form_process($entity)
{ {
$this->_viewDatas['category'] = $this->getCategoryModel()->getEntity( //권한체크
[$this->getCategoryModel()->getPrimaryKey() => $entity->getCategory_Uid()] $this->isRole('reply');
);
// echo var_export(isRole_CommonHelper(
// $this->_viewDatas['currentRoles'],
// $this->_viewDatas['category'],
// CATEGORY_ROLE_FIELDS['REPLY']
// ), true);
// exit;
//사용자가 Category에서 해당 게시판의 REPLY권한이 있는지 확인
if (!isRole_CommonHelper(
$this->_viewDatas['currentRoles'],
$this->_viewDatas['category'],
CATEGORY_ROLE_FIELDS['REPLY']
)) {
throw new \Exception("고객님은 답변권한이 없습니다.");
}
return parent::reply_form_process($entity); return parent::reply_form_process($entity);
} }
protected function reply_process($entity) protected function reply_process($entity)
{ {
$this->_viewDatas['category'] = $this->getCategoryModel()->getEntity( //권한체크
[$this->getCategoryModel()->getPrimaryKey() => $entity->getCategory_Uid()] $this->isRole('reply');
);
//사용자가 Category에서 해당 게시판의 REPLY권한이 있는지 확인
if (!isRole_CommonHelper(
$this->_viewDatas['currentRoles'],
$this->_viewDatas['category'],
CATEGORY_ROLE_FIELDS['REPLY']
)) {
throw new \Exception("고객님은 답변권한이 없습니다.");
}
return parent::reply_process($entity); return parent::reply_process($entity);
} }
//Delete 관련 //Delete 관련
@ -162,17 +115,8 @@ class BoardController extends FrontController
//View관련 //View관련
protected function view_process($entity) protected function view_process($entity)
{ {
$this->_viewDatas['category'] = $this->getCategoryModel()->getEntity( //권한체크
[$this->getCategoryModel()->getPrimaryKey() => $entity->getCategory_Uid()] $this->isRole('view');
);
//사용자가 Category에서 해당 게시판의 READ권한이 있는지 확인
if (!isRole_CommonHelper(
$this->_viewDatas['currentRoles'],
$this->_viewDatas['category'],
CATEGORY_ROLE_FIELDS['READ']
)) {
throw new \Exception("고객님은 읽기권한이 없습니다.");
}
//조회수 올리기 //조회수 올리기
$this->_model->addViewCount($entity); $this->_model->addViewCount($entity);
return parent::view_process($entity); return parent::view_process($entity);
@ -180,16 +124,8 @@ class BoardController extends FrontController
//Index관련 //Index관련
protected function index_process() protected function index_process()
{ {
$this->_category = $this->request->getVar('category') ?: throw new \Exception("범주를 지정하지 않으셨습니다."); //권한체크
$this->_viewDatas['category'] = $this->getCategoryModel()->getEntity([$this->getCategoryModel()->getPrimaryKey() => $this->_category]); $this->isRole('index');
//사용자가 Category에서 해당 게시판의 ACCESS권한이 있는지 확인
if (!isRole_CommonHelper(
$this->_viewDatas['currentRoles'],
$this->_viewDatas['category'],
CATEGORY_ROLE_FIELDS['ACCESS']
)) {
throw new \Exception("고객님은 접속권한이 없습니다.");
}
return parent::index_process(); return parent::index_process();
} }
//Category 및 Status 조건추가 //Category 및 Status 조건추가

View File

@ -6,13 +6,50 @@ use App\Controllers\BaseController;
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\CategoryModel;
abstract class FrontController extends BaseController abstract class FrontController extends BaseController
{ {
protected $_category = null;
private $_categoryModel = null;
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 .= 'front/'; $this->_viewPath .= 'front/';
$this->_viewDatas['layout'] = LAYOUTS['front']; $this->_viewDatas['layout'] = LAYOUTS['front'];
} }
final protected function getCategoryModel(): CategoryModel
{
return $this->_categoryModel = $this->_categoryModel ?: new CategoryModel();
}
//권한체크
final protected function isRole($action)
{
$this->_category = $this->request->getVar('category') ?: throw new \Exception("범주를 지정하지 않으셨습니다.");
$this->_viewDatas['category'] = $this->getCategoryModel()->getEntity([$this->getCategoryModel()->getPrimaryKey() => $this->_category]);
switch ($action) {
case 'insert':
$category_field = CATEGORY_ROLE_FIELDS['WRITE'];
break;
case 'reply':
$category_field = CATEGORY_ROLE_FIELDS['REPLY'];
break;
case 'view':
$category_field = CATEGORY_ROLE_FIELDS['READ'];
break;
default:
$category_field = CATEGORY_ROLE_FIELDS['ACCESS'];
break;
}
//사용자가 Category에서 해당 게시판의 해당권한이 있는지 확인
if (!isRole_CommonHelper(
$this->_viewDatas['currentRoles'],
$this->_viewDatas['category'],
$category_field,
)) {
throw new \Exception("고객님은 " . lang('Category' . $category_field) . "이 없습니다.");
}
}
} }

View File

@ -69,7 +69,7 @@ abstract class BaseModel extends Model
{ {
return $this->where($conditions)->first() ?: throw new \Exception(__FUNCTION__ . "에서 {$this->getClassName()}의 해당 데이터가 없습니다.\n" . var_export($conditions, true)); return $this->where($conditions)->first() ?: throw new \Exception(__FUNCTION__ . "에서 {$this->getClassName()}의 해당 데이터가 없습니다.\n" . var_export($conditions, true));
} }
final public function getEntitys(array $conditions = array()): array public function getEntitys(array $conditions = array()): array
{ {
return $this->where($conditions)->findAll(); return $this->where($conditions)->findAll();
} }

View File

@ -55,7 +55,7 @@ class CategoryModel extends BaseHierarchyModel
{ {
//대분류 부분은 선택이 되지 않게 하기위해 따로 만듬 (form_dropdown의 optgroup 기능) //대분류 부분은 선택이 되지 않게 하기위해 따로 만듬 (form_dropdown의 optgroup 기능)
$old_title = ""; $old_title = "";
foreach ($this->where($conditions)->orderby("grpno DESC, grporder ASC")->findAll() as $entity) { foreach ($this->getEntitys($conditions) as $entity) {
if ($entity->getHierarchy_Depth() == 1) { if ($entity->getHierarchy_Depth() == 1) {
$options[$entity->getTitle()] = []; $options[$entity->getTitle()] = [];
$old_title = $entity->getTitle(); $old_title = $entity->getTitle();
@ -96,6 +96,10 @@ class CategoryModel extends BaseHierarchyModel
{ {
return parent::getEntity($conditions); return parent::getEntity($conditions);
} }
public function getEntitys(array $conditions = array()): array
{
return $this->where($conditions)->orderby("grpno DESC, grporder ASC")->findAll();
}
public function create(array $formDatas): CategoryEntity public function create(array $formDatas): CategoryEntity
{ {
return $this->create_process(new CategoryEntity(), $formDatas); return $this->create_process(new CategoryEntity(), $formDatas);