diff --git a/app/Controllers/Front/ProductController.php b/app/Controllers/Front/ProductController.php index 3536898..487bf36 100644 --- a/app/Controllers/Front/ProductController.php +++ b/app/Controllers/Front/ProductController.php @@ -6,16 +6,24 @@ use App\Models\ProductModel; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; +use App\Models\CategoryModel; class ProductController extends FrontController { + private $_category = null; + private $_categoryModel = null; public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { - $this->_model = new ProductModel(); + $this->_model = new ProductModel($this->getFields()); parent::initController($request, $response, $logger); $this->_viewPath .= strtolower($this->_model->getClassName()); } + private function getCategoryModel(): CategoryModel + { + return $this->_categoryModel = $this->_categoryModel ?: new CategoryModel(); + } + public function getFields(string $action = ""): array { $fields = ["category_uid", 'name', "photo", "cost", "price", "sale", "stock", "view_cnt", "status", "content",]; @@ -57,7 +65,42 @@ class ProductController extends FrontController //View관련 protected function view_process($entity) { - $entity = parent::view_process($entity); - return $this->_model->addViewCount($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->_model->addViewCount($entity); + return parent::view_process($entity); + } + + //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("고객님은 접속권한이 없습니다."); + } + return parent::index_process(); + } + //Category 및 Status 조건추가 + protected function index_setCondition() + { + $this->_model->where("category_uid", $this->_viewDatas['category']->getPrimaryKey()); + $this->_model->where("status", DEFAULTS['STATUS']); + parent::index_setCondition(); } } diff --git a/app/Views/front/product/index.php b/app/Views/front/product/index.php index 188f8e9..140a104 100644 --- a/app/Views/front/product/index.php +++ b/app/Views/front/product/index.php @@ -1,6 +1,7 @@ = $this->extend('layouts/front') ?> = $this->section('content') ?>