80 lines
2.4 KiB
PHP
80 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Front;
|
|
|
|
use App\Models\ProductModel;
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
class ProductController extends FrontController
|
|
{
|
|
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());
|
|
}
|
|
public function getFields(string $action = ""): array
|
|
{
|
|
$fields = ["photo", 'user_uid', 'name', "cost", "sale", "price", "stock", "view_cnt", "content",];
|
|
switch ($action) {
|
|
case "index":
|
|
case "excel":
|
|
return ["user_uid", "photo", 'name', "cost", "sale", "price", "stock", "view_cnt"];
|
|
break;
|
|
case "view":
|
|
return [...$fields, "created_at"];
|
|
break;
|
|
default:
|
|
return $fields;
|
|
break;
|
|
}
|
|
}
|
|
public function getFieldFilters(): array
|
|
{
|
|
return ["user_uid"];
|
|
}
|
|
public function getFieldBatchFilters(): array
|
|
{
|
|
return parent::getFieldBatchFilters();
|
|
}
|
|
|
|
//권한체크
|
|
protected function isRole($action)
|
|
{
|
|
$this->_category = $this->request->getVar('category') ?: throw new \Exception("분류를 지정하지 않으셨습니다.");
|
|
parent::isRole($action);
|
|
}
|
|
//View관련
|
|
protected function view_process($entity)
|
|
{
|
|
//권한체크
|
|
$this->isRole('view', $entity);
|
|
//조회수 올리기
|
|
$entity = $this->_model->addViewCount($entity);
|
|
return parent::view_process($entity);
|
|
}
|
|
//Index관련
|
|
protected function index_process()
|
|
{
|
|
//권한체크
|
|
$this->isRole('index');
|
|
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();
|
|
}
|
|
//Download관련
|
|
public function download_process($entity)
|
|
{
|
|
//권한체크
|
|
$this->isRole('download', $entity);
|
|
return parent::download_process($entity);
|
|
}
|
|
}
|