cfmgrv4/app/Controllers/Admin/MapurlController.php
2025-03-12 16:13:07 +09:00

187 lines
7.4 KiB
PHP

<?php
namespace App\Controllers\Admin;
use App\Helpers\MapurlHelper;
use App\Services\MapurlService;
use CodeIgniter\HTTP\DownloadResponse;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use App\Services\MyLogService;
class MapurlController extends AdminController
{
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->title = lang("{$this->getService()->getClassPath()}.title");
$this->helper = new MapurlHelper();
}
protected function getService(): MapurlService
{
if ($this->service === null) {
$this->service = new MapurlService();
$this->class_name = $this->service->getClassName();
$this->class_path = $this->service->getClassPath();
}
return $this->service;
}
private function remaping_process(): void
{
//모든 필요한 FormOption등 조기화작업 필요
$this->getService()->getModel()->where('status', DEFAULTS['STATUS']);
$this->getService()->getModel()->orderBy('oldurl', 'ASC');
$this->entitys = $this->getService()->getModel()->getEntitys();
$remap_page = view($this->view_path . DIRECTORY_SEPARATOR . strtolower($this->getService()->getClassPath()) . DIRECTORY_SEPARATOR . 'remap_template', ["viewDatas" => $this->getViewDatas()]);
$remap_path = FCPATH . DIRECTORY_SEPARATOR . "mapurl";
//디렉토리 생성 여부 확인
if (!is_dir($remap_path)) {
mkdir($remap_path, 0755, true);
}
//htmlBuild용
if (!file_put_contents($remap_path . '/index.html', $remap_page)) {
throw new \Exception(__FUNCTION__ . "에서 " . $remap_path . "/index.html Write 실패");
}
}
//생성
public function create_form(): RedirectResponse|string
{
$this->init('create', [$this->getService()->getModel()::TITLE, 'newurl', 'status']);
return $this->create_form_procedure();
}
protected function create_process_failed($message): RedirectResponse|string
{
MyLogService::add("error", $message);
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, MESSAGES["FAILED"], $this->myauth->getUIDByAuthInfo());
return parent::create_process_failed($message);
}
protected function create_process(): void
{
parent::create_process();
$this->remaping_process();
}
public function create(): RedirectResponse|string
{
$this->init(__FUNCTION__, [$this->getService()->getModel()::TITLE, 'newurl', 'status']);
return $this->create_procedure();
}
//수정
public function modify_form(int $uid): RedirectResponse|string
{
$this->init('modify', [$this->getService()->getModel()::TITLE, 'newurl', 'status']);
return $this->modify_form_procedure($uid);
}
//(modify,toggle,batchjob사용)
//수정관련
protected function modify_process_result($message): RedirectResponse|string
{
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, $message, $this->myauth->getUIDByAuthInfo());
return parent::modify_process_result($message);
}
protected function modify_process_failed($message): RedirectResponse|string
{
MyLogService::add("error", $message);
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, MESSAGES["FAILED"], $this->myauth->getUIDByAuthInfo());
return parent::modify_process_failed($message);
}
protected function modify_process(mixed $uid): void
{
parent::modify_process($uid);
$this->remaping_process();
}
public function modify(int $uid): RedirectResponse|string
{
$this->init(__FUNCTION__, [$this->getService()->getModel()::TITLE, 'newurl', 'status']);
return $this->modify_procedure($uid);
}
//단일필드작업
protected function toggle_process_result($message): RedirectResponse|string
{
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, $message, $this->myauth->getUIDByAuthInfo());
return parent::toggle_process_result($message);
}
protected function toggle_process_failed($message): RedirectResponse|string
{
MyLogService::add("error", $message);
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, MESSAGES["FAILED"], $this->myauth->getUIDByAuthInfo());
return parent::toggle_process_failed($message);
}
public function toggle(mixed $uid, string $field): RedirectResponse
{
return $this->toggle_procedure($uid, $field);
}
//일괄처리작업
protected function batchjob_process_result($message): RedirectResponse|string
{
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, $message, $this->myauth->getUIDByAuthInfo());
return parent::batchjob_process_result($message);
}
protected function batchjob_process_failed($message): RedirectResponse|string
{
MyLogService::add("error", $message);
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, MESSAGES["FAILED"], $this->myauth->getUIDByAuthInfo());
return parent::batchjob_process_failed($message);
}
public function batchjob(): RedirectResponse
{
$this->init(__FUNCTION__);
return $this->batchjob_procedure();
}
//View
public function view(int $uid): RedirectResponse|string
{
$this->init(__FUNCTION__);
return $this->view_procedure($uid);
}
//삭제
protected function delete_process_result($message): RedirectResponse|string
{
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, $message, $this->myauth->getUIDByAuthInfo());
return parent::delete_process_result($message);
}
protected function delete_process_failed($message): RedirectResponse|string
{
MyLogService::add("error", $message);
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, MESSAGES["FAILED"], $this->myauth->getUIDByAuthInfo());
return parent::delete_process_failed($message);
}
protected function delete_process(mixed $uid): void
{
parent::delete_process($uid);
$this->remaping_process();
}
//일괄삭제
protected function batchdelete_process_result($message): RedirectResponse|string
{
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, $message, $this->myauth->getUIDByAuthInfo());
return parent::batchjob_delete_process_result($message);
}
protected function batchdelete_process_failed($message): RedirectResponse|string
{
MyLogService::add("error", $message);
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, MESSAGES["FAILED"], $this->myauth->getUIDByAuthInfo());
return parent::batchjob_delete_process_failed($message);
}
// 리스트
public function index(): string
{
$this->init(__FUNCTION__);
return $this->list_procedure();
}
// Download
public function download(string $output_type, mixed $uid = false): DownloadResponse|string
{
$this->init(__FUNCTION__);
return $this->download_procedure($output_type, $uid);
}
}