107 lines
3.8 KiB
PHP
107 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Front;
|
|
|
|
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->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",];
|
|
switch ($action) {
|
|
case "index":
|
|
case "excel":
|
|
return ["category_uid", "user_uid", 'name', "photo", "cost", "price", "sale", "stock", "view_cnt", "status", "created_at"];
|
|
break;
|
|
case "view":
|
|
return [...$fields, "created_at"];
|
|
break;
|
|
default:
|
|
return $fields;
|
|
break;
|
|
}
|
|
}
|
|
public function getFieldFilters(): array
|
|
{
|
|
return ["category_uid", "user_uid", "status"];
|
|
}
|
|
public function getFieldBatchFilters(): array
|
|
{
|
|
return parent::getFieldBatchFilters();
|
|
}
|
|
//Field별 Form Datas 처리용
|
|
protected function getFieldFormData(string $field, $entity = null): array
|
|
{
|
|
switch ($field) {
|
|
case 'photo':
|
|
$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)
|
|
{
|
|
$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();
|
|
}
|
|
}
|