servermgrv2 init...
This commit is contained in:
parent
b225b22628
commit
fe170ead70
@ -46,4 +46,40 @@ class CategoryController extends AdminController
|
||||
{
|
||||
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;
|
||||
// }
|
||||
}
|
||||
|
||||
@ -3,15 +3,13 @@
|
||||
namespace App\Controllers\Front;
|
||||
|
||||
use App\Models\BoardModel;
|
||||
use App\Models\CategoryModel;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class BoardController extends FrontController
|
||||
{
|
||||
private $_category = null;
|
||||
private $_categoryModel = null;
|
||||
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
$this->_model = new BoardModel($this->getFields());
|
||||
@ -19,11 +17,6 @@ class BoardController extends FrontController
|
||||
$this->_viewPath .= strtolower($this->_model->getClassName());
|
||||
}
|
||||
|
||||
private function getCategoryModel(): CategoryModel
|
||||
{
|
||||
return $this->_categoryModel = $this->_categoryModel ?: new CategoryModel();
|
||||
}
|
||||
|
||||
public function getFields(string $action = ""): array
|
||||
{
|
||||
$fields = ['title', "board_file", "passwd", "content"];
|
||||
@ -69,31 +62,15 @@ class BoardController extends FrontController
|
||||
//Insert관련
|
||||
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]);
|
||||
//사용자가 Category에서 해당 게시판의 WRITE권한이 있는지 확인
|
||||
if (!isRole_CommonHelper(
|
||||
$this->_viewDatas['currentRoles'],
|
||||
$this->_viewDatas['category'],
|
||||
CATEGORY_ROLE_FIELDS['WRITE']
|
||||
)) {
|
||||
throw new \Exception("고객님은 쓰기권한이 없습니다.");
|
||||
}
|
||||
return parent::insert_form();
|
||||
//권한체크
|
||||
$this->isRole('insert');
|
||||
return parent::insert_form_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]);
|
||||
//사용자가 Category에서 해당 게시판의 WRITE권한이 있는지 확인
|
||||
if (!isRole_CommonHelper(
|
||||
$this->_viewDatas['currentRoles'],
|
||||
$this->_viewDatas['category'],
|
||||
CATEGORY_ROLE_FIELDS['WRITE']
|
||||
)) {
|
||||
throw new \Exception("고객님은 쓰기권한이 없습니다.");
|
||||
}
|
||||
return parent::insert();
|
||||
//권한체크
|
||||
$this->isRole('insert');
|
||||
return parent::insert_process();
|
||||
}
|
||||
|
||||
//Update관련
|
||||
@ -116,38 +93,14 @@ class BoardController extends FrontController
|
||||
//Reply관련
|
||||
protected function reply_form_process($entity)
|
||||
{
|
||||
$this->_viewDatas['category'] = $this->getCategoryModel()->getEntity(
|
||||
[$this->getCategoryModel()->getPrimaryKey() => $entity->getCategory_Uid()]
|
||||
);
|
||||
// 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("고객님은 답변권한이 없습니다.");
|
||||
}
|
||||
//권한체크
|
||||
$this->isRole('reply');
|
||||
return parent::reply_form_process($entity);
|
||||
}
|
||||
protected function reply_process($entity)
|
||||
{
|
||||
$this->_viewDatas['category'] = $this->getCategoryModel()->getEntity(
|
||||
[$this->getCategoryModel()->getPrimaryKey() => $entity->getCategory_Uid()]
|
||||
);
|
||||
//사용자가 Category에서 해당 게시판의 REPLY권한이 있는지 확인
|
||||
if (!isRole_CommonHelper(
|
||||
$this->_viewDatas['currentRoles'],
|
||||
$this->_viewDatas['category'],
|
||||
CATEGORY_ROLE_FIELDS['REPLY']
|
||||
)) {
|
||||
throw new \Exception("고객님은 답변권한이 없습니다.");
|
||||
}
|
||||
//권한체크
|
||||
$this->isRole('reply');
|
||||
return parent::reply_process($entity);
|
||||
}
|
||||
//Delete 관련
|
||||
@ -162,17 +115,8 @@ class BoardController extends FrontController
|
||||
//View관련
|
||||
protected function view_process($entity)
|
||||
{
|
||||
$this->_viewDatas['category'] = $this->getCategoryModel()->getEntity(
|
||||
[$this->getCategoryModel()->getPrimaryKey() => $entity->getCategory_Uid()]
|
||||
);
|
||||
//사용자가 Category에서 해당 게시판의 READ권한이 있는지 확인
|
||||
if (!isRole_CommonHelper(
|
||||
$this->_viewDatas['currentRoles'],
|
||||
$this->_viewDatas['category'],
|
||||
CATEGORY_ROLE_FIELDS['READ']
|
||||
)) {
|
||||
throw new \Exception("고객님은 읽기권한이 없습니다.");
|
||||
}
|
||||
//권한체크
|
||||
$this->isRole('view');
|
||||
//조회수 올리기
|
||||
$this->_model->addViewCount($entity);
|
||||
return parent::view_process($entity);
|
||||
@ -180,16 +124,8 @@ class BoardController extends FrontController
|
||||
//Index관련
|
||||
protected function index_process()
|
||||
{
|
||||
$this->_category = $this->request->getVar('category') ?: throw new \Exception("범주를 지정하지 않으셨습니다.");
|
||||
$this->_viewDatas['category'] = $this->getCategoryModel()->getEntity([$this->getCategoryModel()->getPrimaryKey() => $this->_category]);
|
||||
//사용자가 Category에서 해당 게시판의 ACCESS권한이 있는지 확인
|
||||
if (!isRole_CommonHelper(
|
||||
$this->_viewDatas['currentRoles'],
|
||||
$this->_viewDatas['category'],
|
||||
CATEGORY_ROLE_FIELDS['ACCESS']
|
||||
)) {
|
||||
throw new \Exception("고객님은 접속권한이 없습니다.");
|
||||
}
|
||||
//권한체크
|
||||
$this->isRole('index');
|
||||
return parent::index_process();
|
||||
}
|
||||
//Category 및 Status 조건추가
|
||||
|
||||
@ -6,13 +6,50 @@ use App\Controllers\BaseController;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use App\Models\CategoryModel;
|
||||
|
||||
abstract class FrontController extends BaseController
|
||||
{
|
||||
protected $_category = null;
|
||||
private $_categoryModel = null;
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
$this->_viewPath .= '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) . "이 없습니다.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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));
|
||||
}
|
||||
final public function getEntitys(array $conditions = array()): array
|
||||
public function getEntitys(array $conditions = array()): array
|
||||
{
|
||||
return $this->where($conditions)->findAll();
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ class CategoryModel extends BaseHierarchyModel
|
||||
{
|
||||
//대분류 부분은 선택이 되지 않게 하기위해 따로 만듬 (form_dropdown의 optgroup 기능)
|
||||
$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) {
|
||||
$options[$entity->getTitle()] = [];
|
||||
$old_title = $entity->getTitle();
|
||||
@ -96,6 +96,10 @@ class CategoryModel extends BaseHierarchyModel
|
||||
{
|
||||
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
|
||||
{
|
||||
return $this->create_process(new CategoryEntity(), $formDatas);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user