92 lines
3.5 KiB
PHP
92 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Admin;
|
|
|
|
use App\Models\BoardConfigModel;
|
|
use App\Models\BoardModel;
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
class BoardController extends AdminHierarchyController
|
|
{
|
|
private $_boardConfigModel = null;
|
|
private $_board_config_uids = null;
|
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
|
{
|
|
parent::initController($request, $response, $logger);
|
|
$this->_className .= '/Board';
|
|
$this->_model = new BoardModel();
|
|
helper($this->_className);
|
|
$this->_viewPath = strtolower($this->_className);
|
|
$this->_viewDatas['title'] = lang($this->_className . '.title');
|
|
$this->_viewDatas['className'] = $this->_className;
|
|
}
|
|
|
|
//BoardConfig모델
|
|
final protected function getBoardConfigModel(): BoardConfigModel
|
|
{
|
|
return is_null($this->_boardConfigModel) ? new BoardConfigModel() : $this->_boardConfigModel;
|
|
}
|
|
|
|
//Field별 Form Option용
|
|
protected function getFieldFormOption(string $field): array
|
|
{
|
|
switch ($field) {
|
|
case 'board_config_uid':
|
|
$options = $this->_board_config_uids = $this->_board_config_uids ?: $this->getBoardConfigModel()->getFieldFormOptions(['status' => 'use']);
|
|
break;
|
|
default:
|
|
return parent::getFieldFormOption($field);
|
|
break;
|
|
}
|
|
if (!is_array($options)) {
|
|
throw new \Exception(__FUNCTION__ . "에서 {$this->_className}의 Field:{$field}의 FormOptionData가 array가 아닙니다.\n" . var_export($options, true));
|
|
}
|
|
return $options;
|
|
}
|
|
|
|
//Field별 Form Datas 처리용
|
|
protected function getFieldFormData(string $field, $entity = null): array
|
|
{
|
|
switch ($field) {
|
|
case 'passwd':
|
|
$this->_viewDatas['fieldDatas'][$field] = $this->request->getVar($field);
|
|
$this->_viewDatas['fieldDatas']['confirmpassword'] = $this->request->getVar('confirmpassword');
|
|
break;
|
|
case 'board_file':
|
|
$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)
|
|
{
|
|
// view_cnt에 추가하기위함
|
|
$this->_model->increaseViewCount($entity->getPrimaryKey());
|
|
return parent::view_process($entity);
|
|
}
|
|
//File Download관련
|
|
public function download($uid)
|
|
{
|
|
try {
|
|
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
|
|
if (!$entity->getFile()) {
|
|
throw new \Exception("해당게시물은 첨부파일이 확인되지 않습니다.");
|
|
}
|
|
list($origin_filename, $filename) = explode("||", $entity->getFile());
|
|
if (is_file(WRITEPATH . PATHS['UPLOAD'] . "/" . $origin_filename)) {
|
|
throw new \Exception("파일이 확인되지 않습니다.");
|
|
}
|
|
return $this->response->download(WRITEPATH . PATHS['UPLOAD'] . "/" . $filename, null)->setFileName(date("YmdHms") . '_' . $origin_filename);
|
|
} catch (\Exception $e) {
|
|
return alert_CommonHelper($e->getMessage(), 'back');
|
|
}
|
|
}
|
|
}
|