82 lines
3.1 KiB
PHP
82 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Front;
|
|
|
|
use App\Controllers\BaseController;
|
|
use App\Entities\CategoryEntity;
|
|
use App\Models\CategoryModel;
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
abstract class FrontController extends BaseController
|
|
{
|
|
private $_categoryModel = null;
|
|
private $_currentCategory = null;
|
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
|
{
|
|
parent::initController($request, $response, $logger);
|
|
$this->_viewPath = 'front/';
|
|
$this->_viewDatas['control'] = 'front';
|
|
$this->_viewDatas['layout'] = LAYOUTS['front'];
|
|
$this->_viewDatas['title'] = '사용자화면';
|
|
$this->_viewDatas['class_icon'] = '';
|
|
$this->_viewDatas['menus'] = $this->getCategoryModel()->getMenus();
|
|
$this->_viewDatas['category'] = false;
|
|
}
|
|
|
|
final protected function getCategoryModel(): CategoryModel
|
|
{
|
|
return $this->_categoryModel = $this->_categoryModel ?: new CategoryModel();
|
|
}
|
|
final protected function getCurrentCategory(): CategoryEntity
|
|
{
|
|
if ($this->_currentCategory === null) {
|
|
$this->_viewDatas['category'] = $this->request->getVar('category');
|
|
$this->_viewDatas['category'] ?: throw new \Exception("분류를 지정하지 않으셨습니다.");
|
|
$this->_currentCategory = $this->_viewDatas['currentCategory'] = $this->getCategoryModel()->getEntity([$this->getCategoryModel()->getPrimaryKey() => $this->_viewDatas['category']]);
|
|
//$this->_viewDatas['parent_category'] = $this->getCategoryModel()->getEntity([$this->getCategoryModel()->getPrimaryKey() => $this->_viewDatas['category']->getHierarchy_ParentUID()]);
|
|
}
|
|
return $this->_currentCategory;
|
|
}
|
|
|
|
//권한체크
|
|
protected function isRole($action)
|
|
{
|
|
switch ($action) {
|
|
case 'insert':
|
|
$category_field = 'iswrite';
|
|
break;
|
|
case 'reply':
|
|
$category_field = 'isreply';
|
|
break;
|
|
case 'view':
|
|
$category_field = 'isread';
|
|
break;
|
|
case 'upload':
|
|
$category_field = 'isupload';
|
|
break;
|
|
case 'download':
|
|
$category_field = 'isdownload';
|
|
break;
|
|
default:
|
|
$category_field = 'isdaccess';
|
|
break;
|
|
}
|
|
//사용자가 Category에서 해당 게시판의 해당권한이 있는지 확인
|
|
if (!isRole_CommonHelper(
|
|
$this->_viewDatas['currentRoles'],
|
|
$this->getCurrentCategory(),
|
|
$category_field,
|
|
)) {
|
|
// echo var_export($this->_viewDatas['currentRoles'], true);
|
|
// echo "<HR>";
|
|
// echo var_export($this->_viewDatas['category'], true);
|
|
// echo "<HR>";
|
|
// echo "field->", $action . ":" . $category_field;
|
|
// exit;
|
|
throw new \Exception("고객님은 " . lang("Category.label." . $category_field) . "이 없습니다.");
|
|
}
|
|
}
|
|
}
|